C#

C

C#

We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.

Join

web.config encrypt identity

Hello, I have a web.config they ask me to encrypt the password in the node identity because in IIS they want to configure single sign in so we have Impersonation Enabled Encrypt the node with aspnet_regiis doesn't work I have look on internet and it's say to add the password in the registry but when I do that I get on error Can you help me ? It's already been a day I work on that...
No description

✅ How do i get rid of this blue text

it always pops up except if use dotnet run what can i do to get rid of it
No description

Mapping json objects with known schema but unknown number of properties

hello. in stj, I have to map something, as in discord error structures. Main top level object is a record with message, code and optional "Errors" property, which I have tried to map like so (unsuccessfully): ```cs public sealed record ErrorDetailsModel { [JsonPropertyName("_errors")]...

GitVersion help

I'm trying to use gitversion v6 to auto-version nuget packages I'm building in a github action, but I can not get it to work correctly and not having much luck going through the documentation. I don't really understand the different "modes", and most of the posts/videos are using v5. 1. There are no releases or tags in the repo currently. 2. I want to start off at version 1.0.0 3. Branches are main, release, and any other branch (we'll call them feature branches, but not necessarily named feature) not named those two....

✅ I've spent so much time on this school project someone please help me.

This is a blackjack under 500 lines project for my computer science class and I'm basically done with it, but sometimes the total comes out greater than it should and I cannot figure out why or how to fix it. It might be something with aces, but I nothing's standing out to me.
No description

✅ Understanding how to build controllers.

My controller is supposed to pass ifnormation from the model to the view. My instructor left some code for me to understand. I also wrote out his comments. Can someone help me explain these parts to me? ```cs // Question 1 So the first thing that we do is connect the model to the controller correct? Is that what is happening on this line of code? // Question 2 I am lost on what context is. Based on my googling this is objects that ...

Windows 10/11 modern Way of putting apps in Tray ?

Hi , i am making a C# WPF app for performance boost , one of the features i am working on is closing a selected number of tray apps when a game is opened and opening them again when games closed , but i couldn't figure out how to get what's on the tray , tried multiple ways but all i managed to get is background processes (all of em) , is there anyone here that knows how windows 10/11 put apps in tray (in the overflow arrow) ? how to extract it in C# ?

Memory Leak Issue in .NET/C# Application

Hi @everyone,| I’m running into a problem with memory leaks in my .NET/C# application. Over time, the app’s memory usage keeps increasing, and performance drops until it eventually slows down or crashes. I suspect it might be related to unreleased resources like open database connections, file streams, or event handlers not being unsubscribed properly....

DTOs - I'm so lost its unreal

So I had a good conversation last night about DTOs and thought I understood it. Now I'm more confused than ever. I'm building a game server in C# and its turned into a project nightmare spanning many class libraries and nuget packages. ...

✅ I need help with designing my microservices

I am making some app for distributed systems subject. So, i am making som easy order/product/user and i dont know how to design my api in a way that these are all separeted services and this needs to happen: user tries to buy product if he has enough money it is deducted and then it is added in the order and they all have thier own database you know? it is not connected at all. Help? how to design this in code

✅ Microsoft.PowerShell.SDK missing reference

I don't know what to do, I installed this package from nuget but I can't add it to my proyect any ideas on how to solve this?...
No description

✅ How does dictionary.ContainsKey() work?

i have a class that implements IEquatable and ICompareable (i think only iequatable is needed for this but i could do both so i did), yet when I try and use it as a key it doesn't seem to work. here is a pretty much what I have, tho i can send the actual code if needed ```c# ItemType item1 = ......

Need help with some memory leaks

I got this file of code here. My code just runs fine over time without it, and when its running it starts producing memory leaks. I tried for 2-3 days now to fix and can't find it. It is supposed to check the status of every shard in the database and save it in the database. It always checks a maximum of 5 shards at the same time. I'm coding a discord bot with C# and ASP.NET...
No description

✅ Should i know this?

Hi this is my code:
DateTime Today = DateTime.Now;
Console.WriteLine(Today.ToString("D")
DateTime Today = DateTime.Now;
Console.WriteLine(Today.ToString("D")
i clicked the pop up window (the one where you hover your mouse over something pops up) How am i supposed to read this? and i found this ``` public string ToString([StringSyntax(StringSyntaxAttribute.DateTimeFormat)] string? format) {...

✅ SSL Error on ASP.Net

I Have a simple ASP.net api with a SignalR hub running, when i try to connect to the hub from a windows app (also running locally) im getting an SSL error (image attached). Ive tried resetting the dev certs already but gotten no where. Any thoughts on next steps?
No description

✅ Testing Guidance (Unit/Integration)

Hello! I am having the worst time trying to wrap my head around how/what/when to do unit tests vs integration tests. My company currently has no testing setup and so I am being tasked with adding it to one of our web apis we are currently rewriting. The part I am mainly struggling on is where the db comes into play. We have an IUnitOfWork interface that's currently only exposing Set<T> Query<T> (which is just Set<T> with AsNoTracking enabled) and SaveChanges on the DbContext. That's injected pretty much everywhere we need to make a database query, so most of our services have it injected. This was a pattern set before I joined the company and we've just followed it since. With that said, if I wanted to unit test one of those services that have a dependency on IUnitOfWork, it doesn't seem like I could easily mock this since it's generic and reliant on ef core. What should I do in this scenario? Just integration test it? Inject the concrete DbContext and try and mock the DbSets? Abstract away the "repository" (that seems overkill just to have testing) using the repository pattern on top of ef core?...

✅ How can I filter for only JSON ModelState errors?

Hi, I want to use Model State to return a custom failure response when invalid JSON is provided (for the request body, for example). The issue is, I am not sure what the best way to do this is because the errors messages do not have an associated exception with them. What can I do so that my filter can successfully only return early on JSON errors?...
No description

Recommended way to implement a Channel consumer with async handlers & backpressure?

Hey everyone 👋 I’m working on a microservice (DDD style) where aggregates communicate through an in-memory Channel (System.Threading.Channels). Producers push domain messages/events into it, and a background consumer runs handlers for each message. ...

How do i get another's elements data from a element in a list?

``` class Main { List<Ent> entis; // Contains EntA and EntB } abstract class Ent...