C#

C

C#

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

Join

Microsoft Graph – Handling DeleteAsync Response?

Hey everyone! I'm using the Microsoft Graph SDK for .NET to delete a calendar event like this: await _graphService .Users[_teamsUserId] .Calendars[obj.CalendarId]...

Problem with ToString on a float

I have C# code that calls ToString("0.000000") on a float variable (which according to the docs means that its going to be rounded to 6 digits of precision) I have a case where the value in the float is -14.6511173 and according to the documentation, it should be converted to either "-14.651117" or "-14.651118" (I can't tell from the docs which way negative numbers are supposed to be rounded) but the output I get is (for some reason) "-14.651120". I am on .NET 5.0. Can anyone tell me why I am seeing 20 instead of the expected 17 or 18? If I ask it for another digit in the ToString, I get "-14.6511200" instead of the expected "-14.6511173"...

ASP.NET Identity: Error when adding duplicate usernames in AspNetUsers table

Hey everyone, I’m using ASP.NET Identity with a custom user validator to ignore duplicate username errors: builder.Services.AddIdentity<ApplicationUser, IdentityRole>(options => { options.Password.RequireDigit = true; options.Password.RequireLowercase = true;...

Usage of AsyncLocal in singleton DI service to override authentication tokens

I am creating a discord client library, which is based around DI and is supposed to be registered into a DI container, like in service worker or aspnetcore apps. One of it's use cases is of course bots. It's DI services like IUsers etc use an ITokenProvider to retrieve a bot token. Bot is not the only mode of operation, but... The library will support discord login on the web. It will have an aspnetcore authentication handler that can store user's access and refresh tokens and so you can call discord api as the user. However, ITokenProvider is singleton and because of different contexts this library can be used, it can't be scoped. My idea was to use AsyncLocal<Token> for a concept of ambient token. When a discord user authenticated request cames in and request handler wants to execute api request on behalf of that user, they can just set the ambient token, call api like from IUsers and then reset the token. Normally a bot token would still be used....

Help Needed with SQL Server Express Installation

Hi everyone, I’m trying to install SQL Server Express (Basic Edition) on my Windows machine for a Microsoft Windows Object Oriented Programming project, but I keep running into an error. Every time I attempt the installation, I get the following message: Oops... ...
No description

✅ Facing issue in Kubernetes

Facing issue in Kubernetes . Architecture of our system Webapp exposed using ingress controller .api runing internally . Webapp is not able to comunicate with api . But same configuration running jn dr server . Can you guys help us sorting this thing #help...

Need help on returning values

Hello, I've made a simple function that changes a value to whatever number has been entered by the user, as you can see in the image attached to this thread. It seems to work just fine. What I would like to do though is to have it check to see that if someone didn't input number, then it would repeat the input request for a number until the user gets it right....
No description

✅ Am i misremembering how Getters work?

I have a private list in one class and I need to be able to get a copy of it in another class. I have an auto implemented getter for the private list, but I still can’t get anything I thought the getter on a private property was supposed to let you get the item while it was private...

✅ Where do I start?

Hi I'm a new coder who has a really good idea for a game, but I don't know how to code. I know people say to not start on your dream project when you're learning a new medium because it will only make your learning curve steeper, but I got autism and that's how I operate. I do projects that I like and learn as I encounter new problems. My question is is there a course I can do to learn this sorta stuff? Like is there a code.org type thing I could do to learn how to code C#? I'm using unity

Can someone give me a explanation of a Constructor?

So I was under the impression in order to make a new data type you needed to use a constructor, but I just watched a video that showed that as long as you had the public class variables set up, then you have created the data type. So could someone help explain the difference between these two and the best case uses for doing one over the other or like if you should do one of them since the other is bad scripting.
No description

Minecraft Launcher

Hi guys. I'm developing a Minecraft Launcher using Visual Studio. I've sorted out almost everything, but I'm stuck on the most important and hardest part, and I really need your help! When a user clicks the 'Play' button, I need the launcher to automatically install Fabric and download a specific set of mods. Crucially, this needs to happen in my custom .launcher folder, not the standard .minecraft directory, and it must launch Minecraft from there. My intended logic is: every time 'Play' is cli...

✅ .ini file does not save the intended value

I've tried to save but it still does not save my value. File path is correct because when I click save the value became empty even though it had value before. I use Salaros Configuration package hense the configparser. For the full source code, it is right here at Github: https://github.com/PavarisP/FPS-Creator-Game-Launcher I'm new to C# and programming in general. Trying to make a launcher for my own game to let players to customize the settings in launcher instead of manually set in the ini file....
No description

✅ Issues regarding having a fill property for a sprite

Part of my assignment requires me to change the color of some ball sprites. But this enemy class that uses a sprite keeps instantiating to base sprite because that's how it is in the abstract class for eenemy. My teacher says to cast it, but I'm not sure how

Directory.Build.targets is ignored (with Rider?)

I'm trying out Rider for the first time, and I'm guessing I have some kinda configuration issue, cause I can't get https://github.com/reactivemarbles/DynamicData to build with a fresh clone. I didn't have any issues building in VS a few weeks ago, and it built successfully in CI/CD last week. There's been no changes to project or solution config in months. It appears that MSBuild is ignoring the Directory.Build.targets file in the solution root, because all the build errors relate to some #if symbols that are conditionally defined in that file. If I remove the conditions and just define the constants statically, they still seem to be missing. Putting them in Directory.Build.props works, though. Is there some Rider configuration that could be causing this? Or did MSBuild maybe change recently? I'm using the copy of MSBuild (17.14) that's bundled with .NET SDK 9.0.305, which is the latest SDK version. Also confirmed I get the same behavior in the CLI with just dotnet build in the solution directory....

✅ Ram leak winforms

i've a problem: my windows forms app consumes more ram when i do smth in it and doesnt free this ram. idk what's going wrong. Please help - https://github.com/ivantr30/AffairList

Primary Constructor

How good is it to use Primary Constructor?
public class EfUserRepository(AppDbContext appDbContext) : IUserRepository
public class EfUserRepository(AppDbContext appDbContext) : IUserRepository
...

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 {...