C#

C

C#

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

Join

βœ… Cache vs Persistence Repository and DI

anyone have recommendations, for a asp.net backend, a decent way to cache db results and make available to services? I was trying to register the cache as a singleton and the persistence repository as scoped, but I haven't fingered out an elegant way to do it. I figure this problem must have been solved a long time ago. I was thinking, services should NOT care if its CacheRepository or SqlServerRepository or PostgresRepository as long as it is IRepository, but I couldn't figure out how to make Cache IRepository as a singleton periodically refreshing from Postgres IRepository as a scoped...

Service Provider Question

I have a Blazor WASM intranet site with a backend API. I would like to have a really easy way of switching between dev/test/production api, where both the URI and the Name can be utilized in blazor. I created an APIConnection class, which has three classes that implement for each of dev/test/production (1st screenshot). Then I have added that class to service provider (2nd sceenshot). I can easily change the name of the class when I need to switch....
No description

Blazor Auto render mode authentication using external ASP.NET web api with ASP.NET Authentication

I'm a new guy into Blazor Authentication. I have tried to create an auto render mode blazor application, and because this is using external web api project (ASP.NET web api project) so the default individual template would not suit the requirement. Then I have tried to learn from official documents, stackover flow and some ai tools, so I got my template application on my git repo "https://github.com/TokisakiSusumu/AutoRenderDemoApiFromClient" so basically it is using its own Auth provider and Auth services for both SSR and CSR and both of them will point to the controllers in the server project and then it sends all the authentication api call to the backend web api which contains the dbcontext of the actual ASP.NET Identity tables. Currently it is kind of working but not in the normal way and I can't figure it out anymore and want some help. Currently the Login page in the Client project can only use @rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false)), if it uses @rendermode InteractiveWebAssembly then it would give the error as the screenshot shows. And if it is @rendermode InteractiveAuto, then the SSR basically won't work, what will happen is first time (SSR) it tries to login, api seems went through but I don't have the authentication state, so it will redirect me to the login page again (this time it is CSR), then it will work. and I have no idea why this happen. As well as the log out method, currently it is a form in the server project and the controller will then send a return LocalRedirect("~/"); back to be able to make the whole work flow of log out work, but I'm not sure if this is the correct way of doing it....
No description

How to determine whether the NuGetPackageId of RuntimeCopyLocalItems is in _ExcludePackage in Condit

```csharp <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <_ExcludePackage Include="Microsoft.Extensions.Configuration" /> <_ExcludePackage Include="Microsoft.Extensions.Configuration.Abstractions" />...

βœ… Hash collision checkin

I wanted to do some fun testing with SHA256 and ya how do i do collision checkin? πŸ˜›

βœ… In Ef Core I can't update-database

I have almost tried every way (sql server configuration also), but still can't update database. Do you have a any suggestion?
No description

βœ… Database Design and C# cass

Guys I need help for database design and C# class Suppose there is One table Address Table and other tables are Office , School, Hospital obviously these there will have address so which is best way store address ? Means should I put AddressId in these 3 tables or should I put Id of these 3 table in Address Table...

βœ… TUnit or XUnit for a new solution?

If you had to go ahead and implement tests from scratch for a prod solution, would you roll with XUnit 3.0+ or TUnit? I feel like NUnit and VsTest are already eliminated from the competition.

βœ… How can i fix this?

i was wondering if someone could help me write my asking for age method error is Local variable 'ageInput' might not be initialized before accessing error in LOC 49 https://paste.mod.gg/kihrmrjohlvd/0 what ive tried and looked at https://stackoverflow.com/questions/57947128/use-of-unassigned-local-variable-in-an-if-statement and tried changing
```cs ...

βœ… Flow of registering a new user

I have got help here with creating the flow of the user-registration in my project. I was recommended in this discord to create 3 layers: dto -> second layer (which gpt named domain) -> Model. I managed to create this flow, but now I have 1 problem: In which layer I suppose to put restrictions like "confirm password must match first-password" or "password has to contain at least 8 digits" or "FirstName much contain only letters", etc... for example: (picture) ...
No description

βœ… How can I save a single string when my program closes?

In my program I've got a file browser, and I'd like to make it so when you open the file dialogue it starts at the previously selected path. In my testing it's been quite annoying having to go to the same path over and over again. The only method of saving the path that I can think of is writing it to a text file, but that sounds like a bit of a waste just for a single string. Have I got any other options?...

How to glue cpp with c#

I have a project that aims to provide an api for a cpp library (Minecraft bedrock plugin loader, Endstone), and I need to import a lot of dlls. The question is, can I somehow generate it https://github.com/Mih4n/FPUCS/blob/main/DotnetLoader/DotnetLoaderLibrary/Plugin/PluginImports.cs https://github.com/Mih4n/FPUCS/blob/main/HostLoader/src/plugin/EndstoneExports/PluginExports.hpp...

βœ… .NET IdentityServer4 Password Reset + Logout Fails to Invalidate Angular SPA Session

Hi, having an issue with my project, need some help on this, Problem title: -Password Reset + Logout Flow via IdentityServer4 Doesn’t Clear Session β€” Angular SPA Redirects as Still Authenticated Stack Overflow Link: - https://stackoverflow.com/questions/79747644/redirect-issue-after-password-reset-and-logout-flow...

Is it ok if i understand classes like Polymorphisim Abstractions etc but i dont know how to use them

Like i understand what polymorphisim is and different classes but when i get to the writing them myself part i freeze and dont know what exactly to do

I have trouble with using dynamic returns on nuget package

I have a build a asembly with a public method public static dynamic AssertThat(object? current), it returns specific assert implementations based on the object type. It works perfect on project using ProjectReference but fails when using PackageReference The error is ``` 'object' does not contain a definition for 'IsTrue'...

βœ… Does there have any best practice for learning the AspNetCore?

I want to learn the AspDotNetCore through working on a project directly, I think it will be faster than reading some or watching some videos. I know AspDotNetCore has many packages, so i wonder is there have a better order to learn them(Microsoft.AspNetCore.xxxxx "xxxxx" is specific packages). Or just maybe can it be possible to start a project like user-admin-backend-sys which uses severals of packages in AspNetCore, and when it does finished, the time i can already have good usages of these packages. So, could guys provide me some advice to start this AspNetCore in a more practical way?:pepelaff:...

Harmony Patching Transpilers - Identifying a Switch Statement and it's cases

I am having issues accessing the cases of a switch statement and adding to them with a Harmony Transpiler. I was thinking that their may be specific op codes that pertain to cases but it seems that in IL, the operand of the switch stores the indexs of the case statements. Is there a way to, using the operand of the switch statement, figure out what case number is what and also be able to add a default case?...

Use of inline arrays to model arrays of structs

For a native type with the following shape: ```cs public struct CHRDATA { public uint hp; public uint mp; // ... hundreds more fields...

βœ… cant switch buttons.

I got a task is to randomize a 4x4 board with 15 visible buttons and one hidden. When a button next to the empty space is clicked, it swaps places with the empty spotβ€”updating its text, background, and visibility. The goal is to sort the buttons in ascending order, with the hidden button in the bottom-right corner. but my problam is that when i click oln a button whos next to an invisible one this exception : System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' ...
No description

Getting constant address instead of ephemeral one

So, I am developing a simple WakeOnLan program to turn the computer on and off ( using an agent ). And the thing works, but the problem is when trying to get an answer. Code: https://pastebin.com/WiupUPQZ But when the agent receives any packet, I get an IP with an ephemeral port and when trying to answer I get an exception, however I have port forwarding for these computers in the router. How do I get the constant port in the IPEndPoint?...