C#

C

C#

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

Join

Use of inline arrays to model arrays of structs

For a native type with the following shape: ```cs public struct CHRDATA { public uint hp; public uint mp; // ... hundreds more fields...

✅ cant switch buttons.

I got a task is to randomize a 4x4 board with 15 visible buttons and one hidden. When a button next to the empty space is clicked, it swaps places with the empty spot—updating its text, background, and visibility. The goal is to sort the buttons in ascending order, with the hidden button in the bottom-right corner. but my problam is that when i click oln a button whos next to an invisible one this exception : System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' ...
No description

Getting constant address instead of ephemeral one

So, I am developing a simple WakeOnLan program to turn the computer on and off ( using an agent ). And the thing works, but the problem is when trying to get an answer. Code: https://pastebin.com/WiupUPQZ But when the agent receives any packet, I get an IP with an ephemeral port and when trying to answer I get an exception, however I have port forwarding for these computers in the router. How do I get the constant port in the IPEndPoint?...

@key directive switches two elements around for no apparent reason

Hello, Is there any scenario in which using the @key directive would cause two elements to switch around? From my understanding, when using foreach and @key within, the elements should retain the order they were in the UI before. I'm using Sortable JS to move the elements around and it works just fine. But the only issue arises when moving within a single foreach, if I move the element up by two spaces, it will appear normally, but on the next Blazor re-render, the top two elements will get switched around. This issue does not happen in any other case. So what happens:...

Controller uses Dto file to create a new user, does the Model it self needs to include restrictions?

Hello! I have a model of "User" which include User basic attributes, I also added restrictions like password length (max, min and errors). When the controller creates a new user, it uses a Dto file (which obviously has less attributes than the Model it self) and then mapping it into the model which stores it into the database. Does the Model needs the restrictions or the Dto is enough for restrictions? For example: (picture)...
No description

✅ can anyone help me convert .snl to .dll?

i really know nothing about coding, programing, ect., but im trying to mod a game and ive been struggling converting .sln to .dll for a while TvT

Migration Error

Hello, I created migration by this code ( dotnet ef migrations add firstmigration ) and I had to delete it for some reasons I just deleted Migrations folder from Visual Studio and when I am trying to recreate migration from cmd with same code ( dotnet ef migrations add firstmigration ) it shows this error ( shown in image ) and what could be wrong? Thank you....
No description

✅ Asp.Net 9 OpenAPI Swagger UI not using Newtonsoft JSON Snake Case strategy

Hi, How can I get the Swagger UI for OpenAPI to work with Newtonsoft JSON for Snake Case? I've tried:...
No description

View or ViewModel duty?

I am building a Maui application where the user can switch between using "kg" or "lbs" across the application. So the main dilemma I have a Weight property and how to update if the preferred unit has been changed by the user the two ways to update: Some extra information I store the weight in kg in the database there are many collectionviews, also tabbed view so singleton...

is this not a proper use of elseif

i was pretty sure i was doing it just as the cirriculum did before, but all it activates is the daysUntilExpiration <= 10 message
No description

Using 'var' instead of explicitly stating the type

JetBrains Rider suggests I change CircleData[] circles = CircleRegistry.ToDataArray(); to var circles = CircleRegistry.ToDataArray(); with the warning:
Use 'var' (elsewhere)
I understand this is just coding style, but is it considered standard practice to use var whenever possible in C#? As someone with a bit of C++ experience this feels weird to me...

runtime size of label different from design time size, causing issue

hi guys, i'm doing a c# WinForms project for my a-level and there's an issue that's driving me crazy label14 is the label full of periods, and everything is contained in a flowlayoutpanel in design time the width is 678, and doesn't cause a horizontal scrollbar to appear; i can't change its width in design time anyway due to being contained in a flowlayoutpanel in run time however its width is somehow 702 (and now only spans two lines rather than three), and now causes the horizontal scrollbar to appear due to a small portion of it sticking outside the flowlayoutpanel width, which I do not want...
No description

SEHException (0x80004005) in CultureData.GetLocaleInfoCore

Hi, I'm trying to figure out an issue that someone's encountering when using a desktop (avalonia) app I'm a contributer of. From what I've managed to gather, they get an exception when the constructor of the XmlSerializer type is called. This exception simply crashes the entire program, even though there is a try-catch around the main function. TaskScheduler.UnobservedTaskException does set observed, but I haven't been able to verify if it was called in the first place (don't think async Tasks used like this sohuld even trigger this). ^Edit: I can verify it isn't being called....
No description

✅ Codes runs as expected, but Unit Test keeps failing

This is the unit test that keeps the helper methods from evaluating to green ```csharp [Fact] public void SaveAndLoadGame()...
No description

✅ ASP.Net Core Web API

Hello, I have an ASP.Net Core Web API and I am trying to add razor pages to it. Can I do it in the same project or do I need to make another seperate one? Thank you!...

Application doesnt free up ram properly for some reason

im making a custom archive packager and i have a problem with it running out of ram in debug mode(when it reaches 1.4GB) it uses way too much ram and its even more with every file it has 3 modes: misc, tex, sound in misc it compresses with zstd at max compression level in tex it goes through imageGrabber to give it a custom smaller header and decompresses the pixels and encodes them with zstd at max compression level and in sound, it doesnt compress it as its already compressed good enough...

Unity Help

I am just messing around with unity trying to see what different code does, but i cant figure out why on trigger enter is not working
No description

✅ What's the difference between ++variable and variable++?

I understand the complier sees the compound variable operators differently depending if it's before or after the variable, but I'm not sure how. Can someone explain this to me like I'm five?

🖥️ C# WinForms + DTO (with COM Object) → 🔺 Memory Usage Problem

Hi everyone 👋 I’m running into a memory issue in my WinForms application. I have a StudentDTO 👉 which contains an Address class 👉 that wraps a COM object. The Grid is bound to a collection of these DTOs....

Issue in my football match simulator

I have an issue in my football match simulator with red card events. Whenever red card events pop up, the number of players left outputted is incorrect sometimes, can someone help me figure this out? I even tried copying and resetting classes such as Player, Team and MatchProperties but nothing changes. Ping me and I'll send you the zip file.
Next