C#

C

C#

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

Join

Minimal endpoints or one controller per feature in VSA?

How do you usually structure your APIs in VSA? Do you prefer a minimal set of centralized endpoints, or do you use a dedicated controller per feature? I’d like to hear which approach you prefer and what advantages you see compared to the other option.

Populating IOptions in integration tests

Hi, I'm struggling with IOptions when building integration tests specifically, as I'm getting the 'InvalidOperationException: Section 'MySection' not found in configuration' on startup. Those options are mandatory. I know two approach, which both didn't seem to work. First is with AddInMemoryCollection ```cs...

Private Library: Is there a way to flag required packages and their versions (or...?)

I've built an unpublished helper library to handle routines shared by many programs - for example, handling OAUTH2.0 for SMTP, since everyone loves their automated email reports. The library references the package Microsoft.Identity.Client and therefore the program which references the library must also reference that specific version of Microsoft.Identity.Client. However, sometimes I forget and I'm only reminded when I hit a runtime error. Is there a way to flag these requirements in Visual Studio and to get the compiler to warn of missing packages or version mismatches?...

Repository Pattern. EFCore. Single Responsibility (how much of it?)

https://paste.mod.gg/udwfheejnznx/0 here is the example of my 2 controller endpoints. there are 2 regions(#region IThinkISuccessfullyShovedToRepoitory AND #region IDonnoHowToShoveToRepos) in it 1 I think i have managed to cleanly convert, otherwise directly calling dbcontext in controller, to use repository. and 2nd region that I can't figure how much of what should go to each repo. So I understand that each repo should ideally be only using its own respective context (BlogRepo only call context.Blogs), but to what end? 100% is it a cardinal sin to include like and utlize context.Tags in BlogRepo?...

.NET 10 OpenAPI document generating patterns for simple "double" types.

ObservationDTO: ``` public record ObservationDto { public required Guid UserId { get; set; }...

Can someone explain me Claims? I don't manage to understand it well. Especially for my scenario.

Is Claim a data structure made for integrating with Databases? In my scenario I'm creating a cookie to send to the frontend. Right now, I send the user ID and UserName from the database? Those lines: new(ClaimTypes.NameIdentifier, validUser.Id.ToString()),...

ASP.NET Core auth + roles

Hey everyone! I’m building an ASP.NET Core + React app and I’d love some advice on how to handle roles properly. Current situation: Users register as normal "User". I have a flow where a user can “Become a Business” – when they do that, I update a field/role in the database (e.g. Role = "Business")....

✅ C# 14 extension indexers?

There are extension properties and extension statics, but is it possible to write extension indexers? I've tried the following, but it says "this member is not allowed in an extension block". ```cs extension(DataGridViewRow row) {...

Silk.NET.OpenGL + Silk.NET.SDL, can't render vertexes/shapes

After naively deciding to make my own game engine in C#, i've ran into a problem, i finally managed to get the window to appear, but aside from clear colors, i can't seem to get triangles or points to render, i've checked, and the context is active, the shaders are (allegedly) compiled, loaded and used, before you ask, yes! i used teh goddamn AI to teach me how to use the API, no, i didn't "over rely" on it, i did not tell the AI to generate an engine (that's not even possible, methinks), i'm dumb, but not dumb enough to just have AI make my code and then complain when it doesn't work, please do not just reduce it to "sounds like an AI problem", anyway, if anyone wishes to see the code and help me figure out what i am forgetting when rendering triangles, please do respond to thread, thank you in advance. more info: -The window opens. -The class i've made to represent a triangle is in fact reporting to be rendered....

Blazor WASM OTeL ManagedError: AggregateException_ctor_DefaultMessage (Arg_PlatformNotSupported)

Trying to add OTeL logging to my Blazor WASM Standalone app. ```csharp public static WebAssemblyHostBuilder AddOpenTelemetry(this WebAssemblyHostBuilder builder) {...

✅ "Platform linker not found." error with NativeAOT (Visual Studio Insiders)

I want to compile with NativeAOT: * I added <PublishAot>true</PublishAot> property to my .csproj file * I am not using reflection or any other feature that would break my app * I have the "Desktop development with C++" workload installed * I open "x64 Native Tools Command Prompt for VS Insiders" and where link command does seem to print a correct path...

List<> struct Enumerator vs array enumerator

why List<> struct Enumerator holds current value instead of just index to that value like in array enumerator?

Get all services injected as Keyed

I've injected some items using AddKeyedScoped and a on service I need to get all implementations In my mind, it should work ```csharp...

✅ BackgroundService blocking on Startup

I have a service that spins up a few background services, but when one of them is being started up it is blocking the Host startup and preventing any background services registered later on from starting up. The gist of what it's doing in the Execute block is this, which is pretty similar to the other services, but whereas where they will return the Task when the host calls StartAsync, this one will continue executing. ```cs protected override async Task ExecuteAsync(CancellationToken stoppingToken)...

How should my ng-app communicate with API?

Hi every one ! I am really confused. I am trying to deploy an Angular application on my Virtual Private Server (in the cloud). My ultimate goal is to make my ng app communicate with my .Net Api that itself communicates with a PostgreSQL database. ...

✅ Problem build.sh omnisharp-roslyn

Apparently there are a vulnerability in the package Microsoft.AspNetCore.Server.Kestrel.Core in version 2.2.0 which cause an error when I try to build the LSP server. The vulnerability was solved in the version 2.3.6 of the package but also show's some errors if I modify the Directory.Packages.props version of the package. I'm using Linux so don't know to much about C# environment. Any advice about updating packages with nuget/dotnet?
No description

Trying to use windows forms in unity

I have managed to get forms to both get files and save files but they have this look, which is quite diferent to the usual look of the file selector and I really don't know why
No description

✅ Neovim Config

Hey guys, any neovim users here? I'm trying to migrate from VS Code to nvim just to try it out but I'm having a hard time trying to configure the roslyn LSP, I'm neovim with the lazy plugin manager, I've also added mason, but since I installed the LSPs that I use like css, tailwind, html, etc. I couldn't take another step with the LSP configuration, does anyone know how can I configure it? Thanks! If you need I can provide any file content and I'm using a neovim app image because on ubuntu it is...

✅ Can someone help improve my understanding of the use of static?

I understand that static is used for things like objects within a class, but what does it actually do?

✅ Creditable usage for `goto`?

I don't think it needs further explanation, basically the goal is to catch any exceptions that might be thrown from inner functions that get called, but to also allow your own exceptions to be thrown when validation fails. Any thoughts? A) ```cs public static int Method()...