C#

C

C#

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

Join

✅ dotnet test: Testing with VSTest target is no longer supported by Microsoft.Testing.Platform

Running dotnet test produces the following error:
c#
Testing with VSTest target is no longer supported by Microsoft.Testing.Platform on .NET 10 SDK and later. If you use dotnet test, you should opt-in to the new dotnet test experience. For more information, see https://aka.ms/dotnet-test-mtp-error
c#
Testing with VSTest target is no longer supported by Microsoft.Testing.Platform on .NET 10 SDK and later. If you use dotnet test, you should opt-in to the new dotnet test experience. For more information, see https://aka.ms/dotnet-test-mtp-error
I am using TUnit, and it is constructed on top of Microsoft.Testing.Platform, any idea what might be going on?...

JSON import and export in blazor

So i have searched far and wide and i cant seem to find how one imports or exports data in json in blazor, could someone help me?

✅ Xunit v3 running test cases in parallel

Hello, tests are running in parallel, but not test cases. One of my tests has to process more than 50 fixture files, and it currently runs synchronously. How can I make it run in parallel? ```c# [Theory]...

✅ Possible bug in EFCore nested complex properties as record type

Hi, I'm facing an issue while binding the following data models: ```cs public sealed class BeatLeaderScore : AbstractScore {...

My class needs property type which can only either be string or int -not sure how to best implement

Working on a project to make a simple IT monitoring system - just for fun. I have a INormalisedDataPoint - this represents the interface for ingested Log/Metric data which has been processed and normalised. It has a property called Messages, where I intend to store a List<IMessageField> - so Messages would include things like CPU%: 95%, dataSource: my-macbook, ipAddress: ..... and so on. I will be ingesting both logs and metrics (numeric values). ...

Efcore Dynamic Linq, AND and OR

Hi, a textbook dynamic filter for optional properties in a dto would look like something like this ```c# var query = context.MyEntity .AsQueryable();...

Console key input shenanigans

So all i want is to be able to type in things and press esc to call a method but due to me being a dumb person i cant do it and i really could use some help

Regarding resume writing.

Hello everyone, I have a question: Regarding resume writing. Let's say I know 10 out of 23 (GoF) patterns, how should I write that on my resume? If I have pet projects, should they be listed as experience? ...

More ideal/efficient way of drawing pixels on a canvas

Hello, I'm trying to build a sort of whiteboard application with Avalonia. I'm new to Avalonia and .NET in general but want to use this project to learn. So currently I have a simple canvas and using Xiaolin Wu's Line Algorithm I'm drawing lines on the canvas by placing small rectangles (simulating pixels) on it when the mouse is clicked and drawn on the canvas. This works fine to an extent but the whole line-drawing process bogs down after the canvas is populated a fair bit, I can imagine this is because my way of handling it is inefficient, after all I'm just adding numerous small rectangles as children of the canvas. I'm looking for a more ideal way of doing this whole drawing process....

Need help saving data from checkedlistbox

I'm working on a checklist project to keep track of which songs from which albums I've edited and I'm having trouble figuring out how to save both the checked states and list text as a beginner. The method I was trying was to create individual text files for each album but I'm not sure how to write and read the true/false statements for a checked box in the same line as the text and need some help getting pointed in the right direction for this
No description

✅ need help with successful build but error when running

Hi, I am in process of converting an app from .net framework 4.6.X (don't remember exactly except that it's 4 at beggining) to .net 9.0 and at first I ran into a issue where one NuGet package simply don't exist on .net 9.0 so I commented all the code related to it for the time being but I am getting now this, how can I check if this is another case of package simply not exisiting on .net 9.0 or a different issue? ``` 'InventoryKamera.exe' (CoreCLR: clrhost): Loaded 'InteropRuntimeImplementer.TessApiSignaturesInstance'. Exception thrown: 'System.IO.FileNotFoundException' in InventoryKamera.dll Exception thrown: 'System.TypeInitializationException' in InventoryKamera.dll...
No description

✅ How to get data from entity without includes?

I have this: ```cs var shiftTask = await dbContext.Shifts .Include(x => x.Resource) .Include(x => x.Function)...

Best way to test something that depends on a ClientWebSocket

In one of our services, we use ClientWebSocket to send over some data, however we now need to write integration tests for said services. The current setup basically creates the service from a factory method that reads some config from an environment variable and the scoped service instantiates a new client to connect to said websocket, do the job it's supposed to and dispose thereafter. I am fairly new to this codebase and thankfully have the freedom to change it if necessary, primarily because the codebase is only a few months old as well I've never worked with WebSockets like this either so any extra feedback on how to improve this code would be great...

dotnet test app.cs

.NET 10 can run a C# file directly using dotnet run app.cs. But my .cs doesn't have a Main(). It's actually a small xunit test class for https://adventofcode.com/2024/day/N Can I get away with not creating a .csproj for test files?

LibVLC - Audio Length

Hey there - so basically i wanna find a way to get the audio length of a File in seconds without opening it, and I already tried, but i failed, down below I will send the code of my try 🙂 thanks for help if you can

✅ WPF Radio Buttons help needed

for a task for school, i need to work with radio buttons. ```void RadioButtons() { rdb0.Checked += Rdb0_Checked; rdb1.Checked += Rdb1_Checked;...

✅ Hello :) How do I suppose to create a post method to clean my cookie?

I have a post method which "log out" the user. I have another method which log in the user and sends a cookie to the frontend. Now, I want to use the log out in order to clean the cookie, this is the method: ```cs...

✅ Learning C# basic things

Ive already got most basics of C# down but they were on a foreign website i wanna swap to microsoft documentation i just didnt understand it at first so im trying to know what page/section i start on if i already know most basics this is all the basics i know
No description