C#

C

C#

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

Join

✅ Windows Audio Capture

Building an XAML application. The eventual goal is to capture an audio source and stream it to another application using webhooks. This is my first time doing: 1) XAML 2) Audio anything...

✅ EFCore 8 MySQL - Table doesn't exist, but it does?

I'm trying to use EFCore to integrate with an existing database, but apparently the table doesn't exist, even though it clearly does. I'm manually writing the class for Products since EFCore didn't automatically generate it. What the heck is going on here?...
No description

Web-based game with ASP.NET

In the game, I want to include NPCs and implement AI so that they can make their own decisions. I want them to autonomously decide on actions such as assigning workers to mines, assigning workers for agriculture, making diplomatic agreements, etc. What would be the best way to achieve this? Would it be sensible to use C# ML, or is it better to write a service?

Console.WriteLine does nothing

So i am away from my PC for a bit, and so i moved to my laptop to code there for a few days. However, for some reason the same project that i was working on works on my laptop, but just Console.WriteLine does nothing anymore. It also is not the IDE that is the problem. In fact, i could even open the project in my cmd and run dotnet run and all the Console.WriteLine() do nothing. ...
No description

Blazor Static SSR - redirect after form submission

I woudl like to redirect user after successful login. However, after NavigationManager.NavigateTo, it throws an exception. I tried to find any useful information, but I found nothing. Here's my HTML form: ``` <EditForm Enhance="true" Model="LoginEmployee" OnSubmit="HandleSubmit" FormName="Login">...

✅ JsonSerializer ignoring encoding options?

This issue has been driving me crazy for the last hour. I have a json object that includes a string with an apostrophe in it, however it keeps getting converted to a unicode code. After some reading I found this was the default behaviour for the serializer and can be overridden with encoder options, however I have been totally unable to override this behaviour for some reason. This is the dotnetfiddle snippet I've been testing with https://dotnetfiddle.net/7VZABE. Am I doing something wrong here?...

Is there a method that throws an exception if a config value is not present in appsettings?

Hello, Getting configuration values from appsettings.json is done via calling builder.Configuration["name"]. This way few of my services might get a null property, without throwing error before build. Is there an existing method that will throw an exception if the config value is null?...

Scaling c# win Forms

so i have a problem when i maximize my screen i get this layout , which isnt ideal cause of the unnecessary space , i wish it be the first when its maximized
No description

Error 500.9 when I expand httpRuntime size

I have a error problem, and how do I solve it..I got error I tried to allowing website to upload more than 10mb..so I put ``` <configuration>...

✅ My RESX file still is supposedly invalid

You might remember I have a RESX file that VS refuses to open. Furthermore, the ResXFileCodeGenerator tool also claims it's invalid. I compared it to a RESX that I know works and don't see anything. Can someone take a look at it. This is what I see in the csproj file. ```XML...
No description

✅ Why Red Underline on Views?

Why are there red lines under the View? I dont seem to have any errors, this happens on every new MVC project and the theme I choose also doesnt matter it's always there. It's annoying cause I feel like I constantly have errors.
No description

How to sustain TcpListener keep-alive?

I'm creating a https SSL listener that works on top of the tcplistener, but I'm having a problem with the TCP keep-alive. The itself server works well, but it seems that every request cannot reuse previous connections. The code below was trimmed to reduce the size of the example. Btw, I open the streams and discard them at the end of TCPListeners egiBeginAcceptTcpClient callback . I couldn't find another example or documentation about it, so idk if I should reuse networkstreams or just accept another tcpclient. ...
No description

Trying to get a method to work

I'm very new to code. On the first image you'll see from line 58 to 62 the method I've declared. On line 94 you'll see where the method is being used. Unfortunately the line appears to be ignored. Why is that? I could just write Monster1.hp -= attroll; but I'm trying to learn methods and be more object oriented....
No description

✅ How do you handle countdowns of objects?

I have a List of Objects, each has an expiry date. I would like to display a countdown (e.g. 1 hour and 1 minute until expiry) in one of my views (WPF). I'm unsure however, how to construct this in regards to timers. I calculate the time left by subtracting the current date from the date of expiration. If I do this in the object class and implement OnPropertyChanged I get a stackoverflow error, which is understandable because the subtraction would be calculated infinitely often. I also don't want to create a timer for every object because there could be quite a lot of those. What is a better approach for this? I thought of creating a second collection that stores all the calculated values and is updated by a single timer, but I'm unsure how to implement this. I'd be grateful for your assistance!...

✅ Add grid dynamically from MainWindow to SecondaryWindow

Hi everyone, My program is base on C# WPF .NET. I want to use a button which is in Main window to add a grid to secondary window. But the grid can't be updated in secondary window. If the button is in secondary window, the grid can be updated successfully. Do somebody know this problems?...

✅ Azure key vault with microservices

Hello, Right now I have 2 microservice, they communicate with RabbitMq, so the credentials are the same. Would it be more reasonable to have 2 key vaults storing the same secrets, one vault per each microservice, or create an extra vault for shared secrets? 2 vault, 1 per each microservice or 3 vault, 1 per each microservice + a shared one?...

✅ A problem with field.

I have an abstract Entity class. This class has "Position" field. I also have a Player class, that inherits from Entity. Position in Player sets to an certain value (let's say 1, 1) every frame. But for some reason, if I'll try to access entity's position it'll only return the position that set through the constructor, no matter what I do. (it's 0, 0) figuratively speaking, how can I make it return 1, 1?...
No description

Main Menu load

So i have a Main Menu that i want to load when i start the game in unity. One idea of me was to have it shown at the beginning and then to turn it off via script. But when i want to restart the Level i get it again because i just reload the Scene from the beginning but if i put in the line to make the Main menu invisible it does not work and stays visible.
No description

✅ How to access specific fields from an [ObservableProperty] ObservableCollection<Object>?

Hoping to pick someone's brain on MVVM and MAUI. So I have a ViewModel that looks like: ```cs public partial class TermsViewModel : ObservableObject { public TermsViewModel()...