C#

C

C#

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

Join

File stream Speed Question

alright so i want to make a program that takes all of the c# files in a directory, copies all of their content to that single file and trim the using statements

✅ I DESPERATELY NEED HELP GETTING STARTED

I have 1-2 hours left before a deadline and I only just realised the entire thing is in C#. I need help. Please.

How do you declare an Array's Count property to be consistent within a Struct?

I'd like to make a struct with one of its variables being an array that's a consistent size, even if not all data points within that array are filled. ```cs public struct Location {...

✅ How do I add system.windows.forms?

I’m still really new to c# but it’s my understanding that I need to add system.windows.forms to visual studio before I can make use of it to add a button (my end goal). How do I add it to visual studio?

When using iis run the project the 401 error handled in program.cs is not working(works in localhost

```csharp builder.Services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; ...

✅ EntityFramework Core trying to add Navigation Property that already exists

I'm getting this fault:
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 19: 'UNIQUE constraint failed: AspNetUsers.NormalizedUserName'.
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 19: 'UNIQUE constraint failed: AspNetUsers.NormalizedUserName'.
...

✅ Roslyn: Get file scoped namespace

Hi, i'm using the new file scoped namespace ``` using System; ...

Live Templates: Jetbrains Rider

hey trying to make a live template. i want to that where is System.Linq.Queryable.Where(), then also apply this to other methods like Select() and Count(). Chat GPT and the Docs talk about setting 'method context' or defining the context its available in, but i cant find where to do this. i don't appear to understand how this works. the The shortcuts only works if i start with where and doesn't wait for a char within the Where(). the actual result of this is Where(char => ) ...
No description

✅ iis problem

I have a question: in asp.net6.0 I handle the jwt unaothorized error in program.cs: // Adding Jwt Bearer .AddJwtBearer(options => {...

RFC3339 to DateTime

Title says it, I can't find anything online for RFC3339 to Datetime, only the reverse

✅ [Solved] Linux - Workload ID android is not recognised

Hello! I'm trying to use Monogame with IntelliJ Rider to make a game for android. In the Monogame setup guide, it says to install the android workload using dotnet, but when I try and do that, it says the workload ID is not recognised. I use arch linux and I've installed the .NET SDK & Runtime and the android SDK manager using the package manager. With the SDK manager, I have installed build-tools, cmdline-tools, platforms and platform-tools. ...

Add sound to audio input

Hi! I have an api that takes an audio from some input, e.g. microphone, and passes it furher to some external device. How can I add some sounds, or modify the sound before its passed to audio port? I need to add some distortion to the audio, like e.g. phone talk with very pool connection. Unfortunately, I can't modify the api

Question about IIS /API Issue

Had a really weird issue at work today in production where a specific endpoint on an api stopped working and would return 500 just saying 'An Error Has Occured' (or something like that). From the checks I did this 1 endpoint had just stopped working while all other endpoints in the project (and even endpoints in the same controller) continued to work. We had no code or database changes deployed to production around this time (or even for the previous week). It also seemed like the error wasn't even getting to the bit where it actually runs the endpoint logic etc, almost like it was at the IIS level or network level or something. I say this because one thing we noticed is that it would return a 500 response even if you called the endpoint unauthenticated (but if it actually hit our code it would have returned unauthorized) In the end restarting the app pool the api was in from IIS fixed the issue. Any ideas?...

Get route information on controller

In my response model, I have stuff like method and path of the route. Is there any classes or methods I can call to inject that into the function? Example```cs class FooController : ControllerBase { [HttpGet] // I know it's a get here, but not during runtime...

✅ Html CSS Button

Hello So i currently want to put a link on a button so when you press on the button you get to another website I saw a video and I know but the problem is I got many buttons and I named them all but how do I tell the computer which button I want the link on...

✅ Q about the "?" symbol when declaring vars

Hello everybody ,I have seen some c# vidoes where people declare variables with "?", for example "int?","bool?" , I have asked copilot what does it mean and he said that its just "normal variables" but they are special in that they can also store Null . my question is : how accurate is his answer and in what case/context will I use :"type?" instead of "type" thanks...

✅ Covariant return type properties

Am I missing something - I thought that property return types could be covariant if they were readonly. So why does this not compile? ```cs public abstract class C {...

How do I reference either the x or y field of a Vector2 depending on some condition?

Hello. I'm resizing a grid, to do so I use two functions, the first resizes the grid in the X axis, the second on the Y axis. I would like to merge them but I have difficulties coming up with a solution. My main issue is that I would need to have some way to tell the method to either use (and update, very important) the x or y field of a Vector2 depending on some boolean (if changeXAxis = true then use coordinates.x else use coordinates.y, if it makes sense). I have tried multiple things, for example setting variables with a ternary operator like so:...

✅ AddHttpClient and AddHostedService

I have a hosted service that I register with my DI as so serviceCollection.AddHostedService<ExampleService>() and everything works fine. However I now need this service to use it's own HttpClient. That seemed like no issue, Just add serviceCollection.AddHttpClient<ExampleService>(x => x.Timeout = Timeout.InfiniteTimeSpan) and I should be good to go, or so I thought.. Everything resolved correctly and the program ran, except for the fact that the injected HttpClient did not in fact have infinite timeout. A quick breakpoint check later and i find that the configuration action isn't triggering, or from what I found online, that client isn't used at all and it's instead falling back to the standard HttpClient that AddHttpClient adds for everything that isn't the targeted type....

✅ Obfuscate

How do I assign an OBF to an application I made in C#? When I used ConfuserEx, I couldn't assign an OBF because I was using Guna2. Is there another application?