C#

C

C#

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

Join
CCore5/13/2024

UUID v4 vs v7

Hi, I had a model which primary key was type of long and it was used as cursor for pagination. This way I could simply do the following LINQ query: query.Where(l => l.Id >= queryParams.Cursor). I switched from long to Guid and I think this is no longer a good solution. ...
TWTony Wang5/13/2024

HttpListenerResponse

I am using a .net HttpClient and HttpListener to communicate between two machines. I have trouble configuring the httpListenerResponse correctly. Whatever I tried so far, the HttpReponseMessage that my HttpClient receives always has an empty ContentEncoding header. I need to somehow communicate the encoding of the response back to the client. I could also use the request encoding as a workaround but I would rather avoid that...
Kknut.wannheden5/13/2024

Best practice reading from `Socket` / `NetworkStream`?

I've got a C# application in which I want to read data from a Unix domain socket (on the sending side I have a Java application which sends buffered data). I want to read all data into a MemoryStream, as I subsequently want to parse that using CborReader (unfortunately I didn't find any way getting the CborReader itself to read the data directly from the socket). Now, to my question: I can't figure out what the best practice should be for fully reading the data from the Unix domain socket into a MemoryStream. My tests indicate that I can't rely solely on NetworkStream.DataAvailable but also need to call Socket.Poll(), so I've come up with the following code: ```csharp...
TTreF01L5/12/2024

Delegate with Task problem

I decided to work with delegates. I chose to do different kinds of sorting. I made a Sort class, where the name and the SortMethod response are located, but when I started to look at the results, I saw that the sorting that was not performed until that moment of output is simply not output (an error appears on result = null). Does anyone know why var result = await sortDelegate.SortMethod; doesn't work?
No description
Hharelc20055/12/2024

Help with a project

I'm doing a project where you take mp3 files and translate them to music sheets , I already found an api that converts the mp3 to midi , but I havn't found an api for taking midi and converts it to music sheets but I know there are several apps who do it mainly musescore but I tried their api and I wasn't able to figure it out , if someone can help me I would really appreciate it.
Mmorry329#5/12/2024

Fighting with the longest common prefix puzzle

Link to the puzzle description https://leetcode.com/problems/longest-common-prefix/submissions as always I had a small hiccups . Here's my WIP code ```public class Solution { public string LongestCommonPrefix(string[] strs) {...
No description
Xxvlv5/12/2024

Easiest way to serialize System.Numerics.Vector3 using System.Text.Json (.NET 8)

I'm writing a 3D level editor in .NET and OpenGL and need level data to be stored as human-readable text, so I'm using System.Text.Json. Since Vector3 exposes its data as fields instead of properties, it always gets serialized as {}: ```cs using System.Numerics; using System.Text.Json;...
Kkamyar5/12/2024

How to learn good software / OO design?

Hi everyone, Hope you're having a fantastic day. I just finished the book "C# the player's guide" and I've enjoyed it immensely. I'm also getting my MS in CS so I'm a little bit familiar with coding and doing projects. I've been self learning for a couple of years and have taken it seriously for the past 6 months. I'm doing Java projects In uni and use python for leetcode and scripting. My main weakness/problem right now is that I don't know how to design software. Like when should something be a new class? when should I use a separate file? etc. I start with a vision of how the code should be but I keep facing walls and I need to mutate and rewrite and change the structure which is a huge waste of time and energy....
VVasshi5/12/2024

Help display 2 tables from Sql Server in WPF C#

Please help me display 2 tables from my database linked via ADO.net. I’ve been trying to figure out how to do this for 3 hours now, the videos don’t help and there are no good programmers around me.
No description
TTahaA5/12/2024

Can't retrieve data because of JsonIgnore

I'm using JsonIgnore to not include the data in the JSON file (the two properties where I'm using [JsonIgnore] are not allowed to be put inside the JSON file). The problem is that no matter what I've tried until now to retrieve the data in the overriden ToString() method, the datamodel that should contain the TimeTitlePair is always empty/null. I have never had C# up until this semester and this is one of the places where I struggle. I'll show the full code below:
AAlex5/12/2024

Storage for http request routes

In the method to search route I'll provide "Method" and "Path". Is there a better way to store routes that Dictionary<string,Dictionary<string,delegate>>?
AAdamently5/12/2024

C# help

Been trying to set something up to do auto shouts using C# code with Streamer.bot {on twitch that adds a set variable when shouted, Also starting a timer for X amount time to get that Variable removed so next time they chatted it reshouted them, Re~adding that variable & timer. This is what I've found, But dont quite know how to implement it into doing what I'd like. '''cs using System; using System.Collections.Generic; /*Shoutout Timer * ...
Sskmkqw5/12/2024

Integrational testing and authentification

Hello evereybody. I've recently updated my projects with authentification. Before that, i managed users as simple database resource with simple CRUD operations. Now my AppUser inherits from IdentityUser. I also added a new endpoint for user registration. But now i need to update my integrational tests and im having problems with inserting seed data into test database. How to fix my WebApplicationFactory and Utilites classes to add/delete seede users to database?
KKaenguruu245/12/2024

Conveyor Placement System

I've been looking around but all I can find are solutions on how to move items on conveyors. However, my struggles are currently on how to make a placement system that works for me. Here is how it should work: You select an input object (imagine it as a button). From there you can move your mouse to a dot in a grid where you want to place the first part of the conveyor. As long as you left click somewhere, you add the current mouse position (snapped to a grid) as part of the conveyor and then you can set the next point. When you select an output, it will add the output to the conveyor and stop. Now, if you want to add a second output, you can click anywhere on the conveyor (again snapped to a grid) to "extend" the conveyor from there....
EEvgen5/12/2024

С# Blazor Class organization and authorization

I am writing an application on the Blazor platform and I need some help with organizing this application. The application is a kind of psychological test. It should work for both an autoresized user and an anonymous user. I need help with class organization and advice on authorization...
Ddyxnie5/12/2024

Properly import dll in csproj

I am currently porting a Wii Mote Controls API from Unity to Godot and I have a couple dlls I have to import because i get the error: ```cs E 0:00:01:0602 nint HIDapi.hid_enumerate(ushort, ushort): System.DllNotFoundException: Unable to load DLL 'hidapi' or one of its dependencies: The specified module could not be found. (0x8007007E) <C++ Error> System.DllNotFoundException <C++ Source> :0 @ nint HIDapi.hid_enumerate(ushort, ushort)...
ZZarchical5/12/2024

2D Position to Relative ImageBox Position

Basically, to help you visualise, I'm making a management system for my racing game and I have my track map on my Windows Form. In my game, my track positions for my corners are: Bottom Left: 145, -160 Bottom Right: -155, -160 Top Left: 145, 150 Top Right: -155, 150...
FFwedi5/12/2024

Trying to understand MVVM and MVC. Blazor ASP.NET

I'm trying to desgin a web portal using blazor but I can't really wrap my head around how I could code it. Mainly how exactly I could connect the database and the front end. Sorry if I'm asking too much. How could I make use of design patterns like mvc and mvvm to help me out with this? Is one strictly better or more modern or are they both useful and practical? Do I have to pick between the two or is it possible to use both patterns at the same time? ...