C#

C

C#

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

Join

✅ vs code community don't start my code

does anyone know how to fix visual studio code community that won't open my project? When I click on the run button it tells me everything was successful but in reality nothing opens, i am doing a Windows forms app and i am new with c# and vs code community

Manipulate Json

Anyone know how to add things to a deserialized json?

How do y'all get the ideas for your side projects?

Title. Do you have a random blink in your mind? Do you find them online? Is it something that helps you without your day? hmm...

✅ Fedora 40, dotnet 8 sdk, can’t use debugging tools in vscode.

Hi, has anyone else had a similar issue with dotnet on Fedora 40 or in general?


Could not execute because the specified command or file was not found.
Possible reasons for this include:
• You misspelled a built-in dotnet command.
• You intended to execute a .NET program, but dotnet-/home/username/GodotEngine/Godot_v4.3-stable_mono_linux_x86_64/Godot_v4.3-stable_mono_linux.x86_64 does not exist.
• You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.”
Could not execute because the specified command or file was not found.
Possible reasons for this include:
• You misspelled a built-in dotnet command.
• You intended to execute a .NET program, but dotnet-/home/username/GodotEngine/Godot_v4.3-stable_mono_linux_x86_64/Godot_v4.3-stable_mono_linux.x86_64 does not exist.
• You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.”


Haven’t found much online about this problem. I was only able to find solutions related to dotnet-ef which didn’t resolve my issue. I can’t start debugging my C# code due to this error. Path to executable is correct and when I run dotnet —version command in terminal, it outputs sdk’s version which is 8.0.108.
This happens both in vscode and when just running through the terminal....

✅ Why is this try/catch block preventing lines after it from firing when an exception is caught?

I have this foreach block with a try/catch inside it. Can someone please help me understand why the logger line for initialization completing isn't executing when an exception occurs inside the foreach try/catch? I know it's bad form to control flow with exceptions. This is a call to a dependency service which unfortunately doesn't give me a good way to tell if the ConnectAsync method succeeds or fails, so I don't really have a choice. (Also I'd want to catch exceptions regardless.) ```c#...

✅ Is it possible to ask check for a keypress without pausing the whole console?

Kinda new to c# so i dont rlly know alot, but i started a project and i literally have no clue how to ask for a keypress w out pausing and waiting for one, ive seen examples on stack like
Task.Factory.StartNew(() => Console.ReadKey(true)).Wait(TimeSpan.FromSeconds(0.2)); but i cant assign that to var key to use as controls etc, if anyone wants to check through my code more i can send screenshtos or try open a git...

How to add an image tag to an Aspire's ProjectResource?

so I add my project like this: ```csharp var apiService = builder .AddProject<Projects.Messenger_ApiService>("apiService") .WithEnvironment("ASPNETCORE_URLS", "http://*:8080;https://*:8443");...

Unit Testing ASP.NET async api service

Okay. I am trying to make a unit test for my Customer Service. I tried starting with the Read operation which looks like this in my service: ```csharp public async Task<Customer> Read(int customerId) {...

help with project for school, the program keeps looping and doesn't stop adding "*"

```Console.WriteLine("how many lines do you need?"); int l; l = int.Parse(Console.ReadLine()); Console.WriteLine("how many columns do you need?"); int c;...

✅ Problem connecting entities on efcore

I'm new with blazor and efcore and i'm in trouble to connect 2 relation Error: ---> Npgsql.PostgresException (0x80004005): 23505: Duplicate key value violates unique constraint "PK_Blocks" Method:...

C# programming in Linux Mint

What is the best IDE to programm C# on Linux Mint?

✅ ASP.NET MVC and mapping correct views.

Im working on a project that's split in two: There's an API project built in ASP.NET WEB API - and the Frontend in ASP.NET MVC. Im trying to make it so when you log in and the TwoFactorEnabled in the MS Identity database is set to True then you'd be taken to a View called "Verify2FA", "TwoFactorAuth" There the User would be prompted to enter the 2FA code from their phones and clicking verify; If the Code is correct they get to move on to "Dashboard", "Admin"...

✅ DbContextOptionsBuilder.UseMongoDB is not referenced after use AspNetCore.HealthChecks.MongoDb

As above I recently added AspNetCore.HealthChecks.MongoDb to my project and the code below stop working ```cs builder.Services.AddDbContext<LightningLanesDbContext>((serviceProvider, opt) => { var databaseSettings = serviceProvider.GetRequiredService<IOptionsMonitor<DatabaseSettings>>().CurrentValue;...

Why ins't inlining working here?

Just doing an experiment. The following code are not inlined by the compiler: ```csharp class Program {...

✅ Is there a reason to still be using EventArgs and EventHandler<T> for events?

I see the usage of both aforementioned types in the msdocs for events. Even in new-ish blogs and packages, I see some people still using this approach. However, I fail to see a point to it. Event declarations can be of any delegate, like Action<T> or Func<T, T>. And EventArgs seems utterly pointless. So, I just want to make sure: Is this just an outdated convention? Or are there secret runtime benefits of doing events this way?...

Dealing with HTTPClient metrics

Hi, i currently working on httpclient metrics, goal is fair easy - i just want draw a chart which represents request to external dependency in time - i tried something like this -> sum by(server_address)(http_client_active_requests) But in my opinion data does'nt correspond with real traffic. What i make wrong? I collect metrics with multiple apps using prometheus
No description

Form Data Binding Issue in ASP.NET Core MVC - Dictionary Not Receiving Values

I’m encountering a problem in my ASP.NET Core MVC project when trying to bind form data from dynamically generated checkboxes and text inputs to a dictionary in my view model. Despite selecting checkboxes and entering values, the dictionary in my controller isn't receiving the expected values after form submission. I’m attaching my project files and database script so you can replicate the issue with my actual setup. The goal is to ensure that selected variant items (with checkboxes) and their associated prices are properly inserted into the tbl_product_variants_relation table. Here are the key areas:...

✅ how I can write like this?

idk what it called but I can use same logic writing in other language ```cs int a = 0; int b = 1; ...
No description

✅ could not be translated

Generally what solution do you use when you get the "could not be translated" error from ef core? I generally try to use a [NotMapped] property(it doesn't always work), but I saw that it is possible to create a procedure to translate a specific command