C#

C

C#

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

Join

unregistered services

I am implementing my own version of MapIdentityAPI<>() to add some custom functionality. to do this I've copied the code for the method and dependencies out of Microsoft.AspNetCore.Routing into a separate class from where i can call this CustomMapIdentityAPI<>(). i have finally purged all the errors and I've gotten to testing, but now i am getting this error:
System.InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.IEmailSender1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered.
System.InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.IEmailSender1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered.
...

Periodically (asynchronously) yielding in an otherwise synchronous method

I have a long-running CPU-bound algorithm that is being executed in a Blazor WASM application. I would like to cooperatively allow the UI to update / do event loop stuff etc. Would you think this approach would work: ```cs /* we have garanteed async yields via the flag, so we should return the...

change from backgroundworker to async/await

I want to change backgroundworker with async/await. In my current scenario i had a backgroundworker declared in the controller. it has two method dowork and RunWorkerCompleted there. So my UI has call controller function that call backgroundworker.RunWorkerAsync().. how i change all this to async/await ? But those async/await stays in the controller.

Raw mouse input from a win32 hwnd.

Hello, i am writing a game with raylib, but the mouse input is inconsistant and pretty terrible so i wanted to know of any ways(im fine with any deps) to get raw mouse input. all i really need to recieve is the mouse coordinates. It needs to be precise and fast

Sell me on interfaces (and components if unity)

Hello! Sooo, for games I suppose the most common interface to think about would be something like health or damageable, or smth alike. However suppose that every object that could be damaged (let's say characters, obstacles, towers??? buildings?? idk), already inherit a base class "entityBase". Why not just add the functions those classes would have anyway because of interfaces to entityBase?...

I need help with a windows service

I am making a windows service with setup project where I have 4 parameters that I enter when installing the service which are server, database, username and password, this creates a user.config file where these values are saved and I want to read them in my service but the service reads the app.setings file, how can I read these parameters that I set when installing the service? and I am using properties.settings
No description

List, Collection Initializer and Capacity

Hi! Does creating a new List with new List<T> { new T() } (or any number of elements > 0) starts with the proper capacity in order to avoid resizes or does it start at 0 and then grows to add the elements and I should be using new List<T>(1) { new T() } (for instance) instead? Thanks for helping me figure this out!

Routes for learn C#/.NET/ASP.NET being a go developer

Recently I have curiosity to build web apps o desktop app with ASP.NET,, I have develop on languages as Go or C but wanted to ask for a route that shows me the way to develop on C#/.NET/ASP.NET so I grab all the necessary things and not start to learning to “code” again. Bonus: Currently I develop on a Mac, its possible to use this stack on Mac OS and develop from there?...

EFCore generates unwieldy query

Hi all! I have the following EF code: ```csharp var user = await _db.Users .AsNoTracking() .TagWith("Get user with permissions")...

Purpose of Dependency Injection

In this example what's the benefit of DI here. I can just create instances of EmailService and MessagingService class and call the SendMessage method on them without having to create an extra instance of the NotificationService class. ```cs namespace basic_programs{ interface IMessagingService {...

critical mass(?) of service registrations causing scope validation to go from 5 to 30 seconds

does anyone know how to go about looking into why adding one new scoped service registration would cause ValidateScopes going from 5 seconds to 30 seconds at app startup? The registered service itself has a few injected services, which themselves have injected services, etc… On that newly registered service, if i comment out all injected services it goes back down to 5 seconds. I’m not sure really how to go about diagnosing this problem (aside from turning off ValidateScopes in my host builder...

Swagger + Database problem

I have database in this text file and I'm trying to delete it but I have problem in this picture: Microsoft.Data.SqlClient.SqlException (0x80131904): The DELETE statement conflicted with the REFERENCE constraint "FK_Orders_Employees". The conflict occurred in database "Northwind", table "dbo.Orders", column 'EmployeeID'. If you have any ideal please let me know. Thank you so much!...

Data base limit for values in `IN` clause

Hello guys, how to manage big sets of records (more than 1500), when querying table? My database (Firebird) has limit in 1500 values per query. Is there an efficient way to overcome this?
No description

Seeding Data Into Database

Hello there, I'm still new to asp.net and i've been learning through a course on this Course. At episode 83. they were talking about seeding data into database but when i tried to apply the code they used i had an error about the required fields being null ...

Using JavaScript with Blazor

I'm currently working on a project that interacts with Google Maps API. It is now mandatory to use Javascript Map API, since it's needed some map manipulation. I have been stuck trying to load the map in the web page without success since yesterday. I read a lot of guides a saw some videos but the outcome is always the same, he cannot find the file. Does anyone have any idea what it could be wrong?...

e commerce database help

Hello, I came up with database base design, but I'm not sure if it's correct. If it's correct can you help me with the request to fetch data for the product page efficiently? User can choose product size and color in dropdowns and based on choice, I display price for a certain variant of product. Right know I only have an idea to fetch all variants.
No description

C# Code for checking if the player is touching ground doesnt work

im making a celeste-like game, and for some reason, the jumping mechanic doesnt work. After some debugging, i found out it was because my IsGrounded boolean was set to false when i was, infact, touching the ground.

✅ Understanding and working around `this`

I am developing an API that uses .NET 8 Identity. i had it all up and running, but i needed the default endpoints defined in app.MapIdentityApi<IdentityUser>() to work a little differently. i was told in order to get this functionality i needed to re impliment those endpoints. So i dug into the libraries (spesificly IdentityApiEndpointRouteBuilderExtensions.cs in the namespace Microsoft.AspNetCore.Routing), found MapIdentityApi, and coppied it into Program.cs. So far so good. ive coppied in a bunch of other code and ive got it all working... Except... the signiture: ```cs public static IEndpointConventionBuilder MapIdentityApi<TUser>(this IEndpointRouteBuilder endpoints)...
Next