C#

C

C#

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

Join

Need help to port 1 big file of Visual Basic code to C#/.NET code

This code is used as a Macro in an Excel sheet to calculate a workers Fatigue and Risk Scores by collecting a list of data (Day On Duty, Off Duty, Commuting Time, Rest Time, Duty Length, Average duty per day Etc.), Link to Excel Sheet: https://lorhsems.com/wp-content/uploads/Rail/Element_25_Fatigue_Management/Attachments/HSE-UK-Fatigue-Risk-Calculator-v3.xls...

Tree structure vs composition

Trees are common in the application I currently develop. For example there is a tree of machines, where machine has a parent (machine family), the parent can have it's own parent and so on. Both machine and machine family can have parameters, these parameters are inherited from parents, so if a root parent has parameter A, the second parent has parameter B then machine will also contain parameters A and B. There is a lot of business logic attached to these parameters and the problem for me is 1) loading this whole tree structure from the database 2) iterating through parents for parameters. I started wondering, maybe composition will be a better approach. That means that instead of having parent, machine would have a list of parents with indexes (levels). So instead of this Machine A └── Parent 1...

NativeAOT + emscripten

Help!!!!! use following publish command to get js and wasm,while run the js. get the error as image, I've been troubled by this issue for half a month. Command:call E:\emsdk-3.1.56\emsdk_env.bat dotnet publish /p:NativeLib=Shared -r browser-wasm -c Release /p:TargetArchitecture=wasm /p:NativeDebugSymbols=false pause Project:...
No description

✅ Why and How does this work?

```CS using System; public class Program {...

✅ What am I doing wrong regarding my timer?

Can a timer only be used on a xaml page? Did I forget something?

How do I post single DLL on nuget, so that when i do <PackageReference> it automatically loaded it?

I got DLL of a game, stripped down and publicized, but now I need to post it to nuget. How do i pack it up?

Basic C# question

using System; namespace DecimalPart { internal class Program {...

Refresh token on Browser reload

I am trying to implement jwt authentication with refresh token logic for my school project. Refresh tokens are stored in browser HTTP cookies with CORs enabled. They are also stored in Mssql db (I'm thinking to change to redis) in server. My frontend is blazor WASM and my backend is Web API with FastEndpoints. Right now, I can't refresh the refresh token on browser reload. I have implement a refresh token refresh in frontend program.cs in the picture attached. But, that code is not being run everytime the browser refreshes. I have also attached the Jwt Authentication State Provider. Any suggestions are welcome as I am still learning on improving my code 🙂...
No description

Portfolio project and authorization

Hi everyone, I'm facing this question. I'm writing a task list (ASP.NET API + React JS). I'm wondering if I should implement registration and login (password reset), JWT, and authorization for roles. I also have a question: if I implement login and registration, I'll need to reset the password, but what should I use for that? ...

How can I improve my TestContainers with EF tests?

Hi, all: I've been trying to figure out my favorite way to implement test containers with Entity Framework contexts. I was running into an issue where my tests would persist their database changes between each testcase. To remedy this, I created a transactional test scope that rollsback the changes after each testcase. For this implementation, I have three files:...

✅ I cannot run my code

The run button is just grayed out
No description

help w homework (usercontrol)

this is the task i got: "Program starts with 2 forms: Dog and Cat (pink). Each form has: -arrUC: 2 yellow UserControl1s (each holds Labels)....

Costura.fody and folder structure

Hi, I'm using costura.fody in a framework 4.8.1 project. I'm using the last version of the package.. But I dont understand how to embed native dlls. I have an issue that says "please use the new folder structure".

✅ New at c#

someone can help me understand and start in c# i have 0 knowledge about this area and i need some help my brain just dont work

Immediate.Validations conditional validators and delegates

Trying to reimplement some of my FluentValidation rules in IV and a lot of my rules depend on .When() and Must(). I see that AdditionalValidators is something I can define but the example in the docs makes it look like a lot of boilerplate in comparison

Creating API test suite

My team has an ASP.NET Core Web API. We are only two developers. The API is mature, and has hundreds of endpoints. We had to update our framework from .5 to .8, and now we have to test the API to make sure that migration doesn't break anything. We don't have any tests at the moment, so I am creating a test suite using Postman. Creating test scripts for every endpoint is taking forever, and I've only just started. I've resorted to just creating a smoke test of sorts that is just checking valid in...

ValueType disposable scope

Is there a safe way to use a value type to manage a disposable "scope"? For example in this code, it should write "1" to the console, but it actually writes "2" because it creates a copy of scope1 and disposes it: ```cs private static int disposeCount = 0; public ref struct Scope(object myObject) {...