C#

C

C#

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

Join

Intelisense unexpectedly broken in VisualStudio.

Don't know what happened but recently i am unable to build even fresh project from visual studio. It produces this ```NuGet package restore failed. Please see Error List window for detailed warnings and errors. Error occurred while restoring NuGet packages: NuGet.PackageManagement.VisualStudio.Exceptions.ProjectNotNominatedException: The operation failed as details for project Test2 could not be loaded. at NuGet.PackageManagement.VisualStudio.CpsPackageReferenceProject.GetPackageSpecsAndAdditionalMessagesAsync(DependencyGraphCacheContext context) at NuGet.PackageManagement.DependencyGraphRestoreUtility.<GetSolutionRestoreSpecAndAdditionalMessages>d__10.MoveNext() --- End of stack trace from previous location where exception was thrown ---...

NuGet package project references

I need to share a project from my solution as a NuGet, to provide base implementation types for my application's plugin system. Let's call this project BasePlugin. BasePlugin has project dependencies that must be supplied with the produced NuGet package. I was able to configure that; the built nuspec file contains the required project references....

βœ… I'm looking for performance and load testing data on ConfigureAwait(false)

I cannot find any proper performance and load testing data on ConfigureAwait(false) for .NET 8 API's and azure functions. I want this info in order to make educated decision on using it.

βœ… FileNotFoundException: Could not load file or assembly. The system cannot find the file specified.

I'm modifying an application using AsmResolver and adding a new assembly into the module references, but for some reason .NET can't find the referenced assembly even though it's right there in the same folder as the one I'm editing. Attached is a minimum reproducible example, and a video showing what's wrong. I also tried editing the .deps.json file, since this guy https://discord.com/channels/143867839282020352/1288099229834805248/1288099229834805248 had success with that and a similar problem,...
No description

VS intellisence when building dotnet runtime locally

Hi! I cloned the "runtime" repo and followed the steps to setup my PC to build and test it locally. The build works but when I open some of the solution I have intellisence errors : Reference to type 'ValueType' claims it is defined in 'System.Runtime', but it could not be found Am I missing any setup ?...

Dapper Migrations

Hey, looking for tips around dapper and handling migrations / updates to domain entities. So can keep log of changes in the database and run SQL scripts r likewise to keep the database sync and allow other devs in team to sync their local databases. Basically to get the same concept as would with EF migrations. The team I’ve joined prefers Dapper for lightweight reasons and ability to control SQL ran on queries and such....

Looking for a logging solution

Working on ASP.NET program.
I have a lot of stuff i want to do for logging. First off i want to log every time an endpoint is accessed, who accessed it, when it was accessed what info was passed to the api and the datatype that the endpoint returned. Then there's all the stuff i see in the command line. i would also like to log this stuff....

EF Core - Intermediate table or Navigation Properties?

Hi everyone, A beginner question here. I’m working on a .NET project using Entity Framework Core and SQL Server. I have two entities, Organizations and Modules, where an organization can have multiple modules, and a module can belong to multiple organizations. I initially thought of creating an intermediate table OrganizationModules to handle this many-to-many relationship. My question is: With Entity Framework Core, do I still need to explicitly define this intermediate table, or can I just rely on navigation properties (ICollection<Module> in Organization and ICollection<Organization> in Module) and let EF Core handle the join table behind the scenes? ...

βœ… Any practical use to have an endpoint accessing an entity trough a non ID path variable?

Hello, I was browsing Bitly's API documentation, and saw that the endpoint trough which a link can be edited isn't done trough an Id path parameter. I have never seen something like this, what benefit can such a design have?...
No description

βœ… Razor page not updating properly

I'm going through the MS Docs tutorial on Razor pages and I'm adding the search feature. My main issue is that even though my query updates the model appropriately, the page itself does not change. I've also made sure to clear the cache in case that was the issue.
No description

Partial view not found in Razor Pages despite being in the correct location

I am looking to import a few partials into a page within the _Layout file. The _Layout file contains the following code: ```html...
No description

Many To Many relationship with cascading for both entities

Hello, I'm wanting my many to many relationship to cascade delete when either entity is deleted. My issue is I can only set one to DeleteBehaviour.Cascade at a time without it erroring. If I set both to cascade, it tells me an entity can't have multiple cascade paths. I'd like to be able to delete either Application or User and it auto delete their Followers relationship. Here is my code: ```cs builder.Entity<Application>(ent => {...

NUnit test class what has functions Step1,Step2,Step3...

So after each step you want to validated the mocked classes / the result of the StepN function. StepN only has sense if StepN-1 had run correctly. (For now I'm just talking about the ideal "good behavior" like testing for NotThrowException and not for TestThrowException")...

βœ… difference between internal and file access modifiers

the content on Microsoft Learn is a bit difficult to understand.

Blazor - Can we OnValidSubmit for every control change?

Hi, I am looking to develop and application using Blazor. I have a standard form with a model. OnValidSubmit is currently being fired by a submit button. However, I am looking to submit the form on every change of any control on the form. Googling for an hour has not lead me to an answer. Does anyone have any pointers?...

Can't override OpenApiSchema

Hello devs, Someone can tell me what is wrong in this code: ``` .WithOpenApi(...

Just learned generics...

I just learned generics and have a problem that i tried googling but still couldnt solve. I have a person class ```C#...

βœ… Migration-independent Database Seeding

Curious if EF has some sort of independent database seeding potential? I am kinda hoping to see a similar functionality to Laravel's Database Seeder where you can write the seed in a file which you can run at any time, regardless of whether or not your migrations are already ran. I find the HasData fucntiuonality inherently counterproductive as I don't want to re-run all migrations over and over just so I can work with my seed data. Laravel Seeding: https://laravel.com/docs/11.x/seeding...

Simple yolo webcam throwing System.InvalidOperationException: 'The calling thread cannot access this

any help is SUPER appreciated. This is in WPF and the error is at the end of my WebcamAsync task