C#

C

C#

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

Join

Restoring packages takes way too long

I use dotnet 8 and JetBrains Rider. Recently after creating a new project I noticed that restoring packages takes at least 10 minutes. Every time I rebuild a project or install net nuget packages I have to wait. The project is new and I only have a few nuget packages installed. ```xml <Project Sdk="Microsoft.NET.Sdk">...

how to delegate on static method

Hi, I want to delegate from a static method to delegate trapped exceptions from Godot. By nature, all un-caught exceptions from this block are caught inside Godot and only logged at the end. ```csharp catch (Exception ex) {...

✅ Separate C# Dll

Hello everyone, I have a project I made in C#, but even if I change the design, the DLL changes and therefore the value I get changes. To avoid this I copied the project into the same solution and the names were the same. I changed the namespaces and made it compile as a DLL, not as an exe. But now dll project can't find the Service and Web references and I get thousands of errors that they are not defined. How do I solve this? Or can I do it in an easier way?

Database is not fetching data. Applied everything properly.

I am sending data from postman. Method is receiving data but when comparing data send by client and from data. It is not showing any data. See customer and card var. both are null. I don't know why data is not fetching from database. There is no any error.
No description

Calling static method of interface via it's type

There's an interface called ISerializer. ISerializer implements two static methods called Serialize and Deserialize. There's a class that implements ISerializer called ArraySerializer. ArraySerializer is requires an generic type parameter of type ISerializer......

Uncaught OperationCancelledException when shutting down IHostedService

Is there a way to detect that OperationCancelledException was thrown specifically due to application shutdown (e.g. pressing "stop" button in IDE)?

✅ Difference between `string[]` and `IEnumerable<string>`

in the following the code, the output seems to be the same: ```cs using System; using System.IO; ...

Task factory issue

I've implemented a function using Task.Factory to call a third-party API for data recording. However, I've been encountering an intermittent issue where, at times, the function is not triggered as expected. Occasionally, the task seems to end before it even starts, and other times, the function never actually executes. This issue has persisted for several days, and I'm seeking a reliable solution to ensure consistent task execution.

Migration not reflecting Model correctly

Context: I'm using .NET core 6.0, ASP.NET MVC, trying to initiate the db with Migrations Got this error:
PostgresException: 23502: null value in column "parent_id" of relation "post" violates not-null constraint DETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.
PostgresException: 23502: null value in column "parent_id" of relation "post" violates not-null constraint DETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.
...

smart AI search application (research)

Hey, mates 👋 I wanna create smart endpoint search which integrates smart AI assistant (llama 3). So, I have some questions related to AI: 1) which libraries should I use (I heard of preview of semantic kernel for .NET 9, is it good and how soon it will 1st release?) 2) how can I tell smart AI assistant about my web api endpoints, so it knows they are existing? Also I would like to tell my AI assistant about related information on endpoint. So if endpoint have any documentation in code (xml docs), AI can read and learn from it...

✅ I don't undertand the error: capacity was less than the current size

Hey I have two versions of code and second one doesn't work first version: ```cs int[] array = Enumerable.Range(0, 1000000000).ToArray();...

✅ Include Source Generator With Library

I created a source generator for a framework I'm making. I'm trying to make the include tree look like this: ``` Generator -> Framework -> Application ^ ^ Generator applied to...

✅ Weird VSCode & WPF bug with C# Dev Kit

Im trying to make a WPF app in VSCode (im trying to make it without XAML though i didn't remove any of the XAML files) and this error keeps appearing in my VSCode This problem is not present when i debug or build the project, it is only an intellisense problem Using C# Dev kit & C# extension...
No description

Insert into Access Database

Hey all, I've been trying to Insert into my access database for some days now and I'm still getting a syntax error which I have no idea why, my connection works I was able to delete buy I cannot add for some reason

✅ How to enable json mode for gpt-4o?

I'm using OpenAI dotnet oficiall API and want to make sure that output of the model would be only in this format.

Possible race condition?

Maybe I'm just totally off but... I'm not sure whether _credentials is implemented safely. I've been reading a lot on how async works under the hood (specifically the task scheduler) and I don't know whether this variable would be susceptible to a race condition if AuthorizeUserWithCodeAsync is called in rapid succession (see this endpoint which will be calling it). My fear is that if this endpoint is called in rapid succession, _credentials could be accessed or overwritten in an unintended way. Is this just a lock and move on situation or is this actually safe?...

✅ Creating random & unique page id

I want to generate id for a page that will be used to access it, something like example.com/2121424221. But generated id should have about 10-15 digits and be unique. How could I do that?

need help with binary serialization

Hi, need help with binary serialization, I need to pack game assets into a bin file the data can be class contain other classes or struct with list of other data
No description