C#

C

C#

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

Join

✅ How to stop Bootstrap CSS from overriding the layout.css of my Razor page?

So I've been trying time and time again to understand why I can't get my pages to look how I want them to at all! I've tried adding a colour background to my main body of my pages but it doesn't work unless I remove the bootstrap.css, but when I do that, my page looks terrible, like a coloured notepad rather than a nice website... I'm really struggling to understand how I'm meant to do the CSS Files.. I have the _Layout.cshtml...

✅ Winform with Blazor -> HotReload Slow

We've now started migrating our project to .NET 9, and we're experiencing issues with hot reload. Here's our setup: We have a Windows Forms application that serves as a host. The host contains a single Blazor WebView component which runs our main application. When making simple changes (like adjusting a div's margin (.razor file) or changing something in a cs file (non blazor)), it takes approximately 30 seconds for the hot reload to apply....

How Can I add Security Definition in Scalar

In Swagger We could Use ``` builder.Services.AddSwaggerGen(options => { options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme...

My MAUI App Cannot Be Deployed When Running Debugger?

My .net8 maui blazor app was running perfectly fine and was freshly pushed and merged while functional, but when I attempted to change the maui icon and splash screen properties of the svg's, in an attempt to use png's the app stopped working and I decided to undo everything. The problem is that now the project won't work anymore even though everything has been completely reverted and I don't know how to run it. I did the first 5 minutes of this video which doesn't really do anything weird when it broke, just a few svg properties and changing icon stuff only. https://www.youtube.com/watch?v=5cgrKARU3Bw ...
No description

Ignore strong names

I was using way too long hunting down the reason for a CS0012, I had the assumption that a non strong named assembly reference can bind to a strong named assembly reference just not the other way around which I thought was logical. (btw an error message with more info could have been useful) But yeah, no some debugging and browsing of roslyn code base eventually made me notice that if either is strong named both must be. This means nuget packages that come shipped strong named (like newtonsoft.json) will break comparability with older libraries, potentially, and including in my case, some you don't have control over. Older versions, in most cases, works just fine in my use case....

✅ New to C#

Recently ive not been doing great learning this as my first langauge. Im slowly losing interest in doing the same things. Anyone knows a good site that gives you fun troubleshooting questions?

✅ New to C# and need help! Guess the number game.

Hi everyone I need some help I started to learn c# about a month ago and I need to make a little game but i dont know how. All I know is that i have to use "Random willekeurig = new Random(1-1000); " for a random number between 1 and 1000 AND I need to use if {}MessageBox.show "The number is higher/lower" else {} Congarts u did it!!!!. Can anyone help me with a code please ;(. -VisualStudio -WindowsFormsApp...

Aspire python app giving certificate errors when debugging

So I followed the guide here https://learn.microsoft.com/en-us/dotnet/aspire/get-started/build-aspire-apps-with-python?tabs=powershell And after adding the following code: ```trace.set_tracer_provider(TracerProvider())...

Possible to use a class as composite key in entity framework?

```csharp class Book { [Key] public required BookIdentifier Id { get; init; } }...

WPF local: when using Dependency Injection

Hello, My WPF app is utilizing dependency injection following https://achraf-chennan.medium.com/net-core-dependency-injection-for-wpf-core-62dc282690f8 (which removes StartupUri from the App.xaml file). When I'm attemping to utilize data binding, but local:SessionConverter isn't being recognize and I'm not understanding how to work around it as I'm unable to set the DataContext in the main window due to the parameters....

Inject IDbContextFactory or DbContext directly?

Hey, I was working with a project earlier that I've made and I saw I was injecting the db context with IDbContextFactory<ApplicationDbContext> and then manually creating a db context every time I was going to use it. I was doing this: await using var dbContext = await _dbContextFactory.CreateDbContextAsync();...

✅ How does dependencies works ?

Hi guys, i'm having issues using dependancies to build an "API Rest". To be more precise, i'm trying to implement a Dbcontext file in which i'm trying to get DbSet function to work using files that are in another project, but the dependancies are confusing me. Even if i follow exactly guides and AI advices, i still manage to fail it

✅ Is it possible to access a Controller's URI at runtime?

I'm not well versed in MVC structures, so this very well could be a XY problem. Let me know if it is a bad idea to begin with. I'm trying to create a GET endpoint for /collections which returns Collections. One Collection always contains a nested Model User. On its own, this is not a problem. However, I am creating my API based around application/hal+json, which requires Resources to have a link to point to their exact location....

✅ How to add newlines in ASP.NET Web Forms?

What I have been doing is that making a Label and adding <br /> as its text. But this doesn't seem to be working on Firefox. Are there any alternative methods?

✅ MemoryStream question

If I have a byte[], and I'm instantiating a MemoryStream with this byte array, does it occupy twice the memory? Or is the MemoryStream simply referring to the byte array instead of copying the contents in the array?

mediatR 12.41 breaking change with IRequest

After upgrading to mediatR 12.41. I now have breaking changes with my code. I now get the error below when calling the Send() in the screenshot. 'OrderCancelledCommand' cannot be used as type parameter 'TRequest' in the generic type or method 'ISender.Send<TRequest>(TRequest, CancellationToken)'. ...
No description

✅ How to learn data structures and algorithms?

I am trying to learn data structures and algorithms. I use neetcode.io(only free version) and Leetcode. But I don’t really have direction besides the roadmap on neetcode.io. Additionally I have a lot of questions: How many questions should I do before going to the next topic? How should I learn the topics(try to solve a problem first and then learning from the solutions, or straight up learning the topic from e.g. a YouTube video)? Are there other great recourses?...

VerifyHashedPassword always returns a Failed result

We make it to the switch statement and it goes right to the default case since the decoded password doesn't match any of the cases. Any suggestionts for what I should do about this?...
No description

How to Start with ASP.NET Web API

Hi, @everyone I am new to ASP.NET Core I want to build a simple login & signup page using ASP.NET Web API
frontend is on react.js database is MongoDB...

Wrong DataContext Inference?

First of all I am still a beginner, so I might not completely know what I am saying. So I am building an Avalonia MVVM app, it is an inventory management system. I have used Postgres for the database. The problem here is, in InventoryView, the commands to edit and delete rows can not be resolved. Rider tells me that the datacontext for the commands is InventoryView, which should be InventoryViewModel, if I am right? I am very new to Avalonia, and only familiar with Winforms, which a lot different....
No description