C#

C

C#

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

Join

How to hide Back Button in Maui 8 Appshell

ok again a tiny little thing that should be a single line of code is driving me nuts, how do i disable the damn back button that appears at the top left of the window? i have tried Shell.NavBarIsVisible="False" in App.xaml, appshell.xaml and i have tried doing it with code in appshell.xaml.cs ```c# protected override void OnNavigating(ShellNavigatingEventArgs args)...

Inheritance or composition

This is going to be a long one, totally get it if nobody makes it to the end 😅 I'm writing an open-source library for writing durable workflows, similar in principle to Azure Durable Functions, where you can write persistent workflows using async/await. However, unlike Durable Functions, my library introduces a dedicated awaitable type called DTask. Because DTask requires infrastructural support, you can't just await one inside a regular async method. To run them, providers must implement its infrastructure components (for storage access, serialization, etc.). One of these components is called DAsyncHost and, as of today, is an abstract class: it exposes and implements some methods to interact with these durable tasks (StartAsync, ResumeAsync), but also defines several abstract callbacks that implementations must override. For example, OnDelayAsync determines how to handle DTask.Delay, OnSucceedAsync defines what to do when a durable task completes. Link to the class: https://github.com/gianvitodifilippo/DTasks/blob/main/src/DTasks/Infrastructure/DAsyncHost.cs I went with an abstract class so I could provide virtual methods with default implementations and add new features in the future without breaking existing implementations (thanks to virtuals). However, I'm not a big fan of abstract classes and I usually prefer composition over inheritance, and I’m starting to wonder if DAsyncHost should have been a concrete class that could instead be injected into those classes that today are its child classes. I'm struggling now even more because I want to add a new overload of the StartAsync method that allows callers to pass a context object that the host can access during the whole execution. To do so, I thought of adding a type parameter to the type (DAsyncHost<TContext>) and a new StartAsync(TContext context, ...) method, but this started to feel like a smell to me....

✅ Beginner Projects

Hi everyone, I'm just starting out on my journey with C#, and I had a question about building Windows apps. I'm still pretty early in the learning process — so far, I've made a Tic-Tac-Toe game and a To-Do list app, both in the console. Now I'm thinking about creating a simple expense/budget app, but I'd like to make it look and feel like a real app (with a GUI). I'm wondering: is it too early for me to start exploring this, or should I stick with console projects for a bit longer?...

Is it possible to reverse a string letter by letter using only regular expression?

I am learning string manipulation. Learned a bit about string and StringBuilder. Now onto Regex and I'm trying to do everything which I do with string methods and StringBuilder methods by using Regex alone for learning purposes. But reversing a string letter by letter seems pretty hard by just Regex.Replace(intialString, pattern, replacement) I guess pattern can be:...

requesting not working on windows 10 ONLY windows 11 works fine

This is a short snippet of my code, pretty simple, uses a api and whatever. But no url works at all so its not just this url its any and also any windows 10 pc i have tried spits out the same issue ``` private static async Task<List<Dictionary<string, object>>> GetPlayerDataAsync(List<int> ids) { string playersApi = "https://api.rec.net/api/players/v2/progression/bulk";...
No description

✅ .NET not Working

Hi , did anyone ever encounter this problem ( i'm on ubuntu ) or can help me with it , i've been stuck on it for this whole day , tried uninstalling and reinstalling .NET SDK but didn't work , i also uninstalled then reinstalled ubuntu 3 times today , it's getting really exhausting , i would appreciate it
No description

ASP.NET MVC - need opinion for viewmodel properties

I'm new to ASP.NET MVC, and I'm trying to make a simple project with N-tier architecture. I'm conflicted with how to represent a Country on my ViewModel. To put it simply, I want my domain model to only hold the CountryId, but I want the ViewModel to display the CountryName that corresponds to that CountryId. Right now I use this...

Physics

Hi guys! I have a question. Im calling this Step method in a FixedUpdate method. But as the documentation tells me of Jitter2 i need to impliment maxSteps....
No description

Adding Python project to Solution in combination with Docker error

As the titel says, I have added a Python project to my Solution. My docker-compose file can find my Dockerfile in the Python project and all of that seems to be OK. However, when I try to launch it all, I get the following message; ```...

Datagridview

Im trying to make make this this if someone can help me I would apperciate it
No description

✅ Creating a single global object that can be accessed by other classes?

I'm someone who comes from using Pascal and Lua, so bear with me here. I want to create a single nested list with custom properties, which I can then iterate through. But it's not intuitive how we actually do that. To demonstrate, here is a snippet of the code I'm working on for Bannerlord: ```C#...

How to get .NET framework 4.8.1 installed on IIS Web Server running Windows Server 2019 via choco?

I've upgraded my .NET Framework website to .NET Framework 4.8.1. In my choco package which installs the website, I've switched the dependency to choco install netfx-4.8.1 --version 4.8.1.20250219 However, it always fails the installation. It doesn't give me much to go on. What do you recommend?...

Set an environment variable as part of a Visual Studio multi-project startup config

I have a solution with 2 main startup configs, V3 and V4, each with a good few API projects. Each of these projects reads environment variables from a text file at startup, but for the V3 config they must read one text file, and for the V4 config the must read another text file. Right now each time I switch configs, I have to go and edit the environment variable loader to use the correct file, and this is very easy to forget, so I am trying to find a way to use the startup config to determine which variable file gets read. The best I've been able to come up with so var is adding a little console app to the solution, and to both startup configs. In the V3 config the console app starts up with a V3_Environment launchsettings profile, which sets a DEBUG_ENV_VAR_FILE environment variable, and for the V4 startup, the same console app starts up with a V3_Environment launchsettings profile, setting the same variable to a different value. Then the environment variable loader uses this variable to determine which file to load the variables from....

Accessing data for multiple days from weather api

I have the program working where it displays the data for the current day but I not to sure how to get the weather data for the following days. Do I have to first send the json results to an array and cycle through?

Blazor Cascading value null exception even though instance exists

I get this error even though I think I created the instance at the top of the code block
No description

✅ Looking for a ASP.NET developer

I need senior ASP.NET developer who is expert in access VBA and Japanese. Most of project has already developed. This is paid job. Please DM me with your experience....

Updating SecurityStamp on Many users

Using .net 9 with Entity Framework Identity, i often feel very locked in to getting a user from the DB. In this case i have a need to logout alot of users if changes are made to a group they are a part of. I would usually call UserManager.UpdateSecurityStamp, but the i would have to get and track each user from the database, just to update that one. I've found the implementation to generate a SecurityStamp but it doesn't feel right to copy that into a new class. What i would like to do is use Ex...

Unit Testing in Minimal Apis

```c# using Backend.Common; using Backend.Common.Api.Extensions; using Backend.Data; using Backend.Data.Types;...

Maybe the case for object pooling?

I have a large array I am processing. Each item is a large object that has multiple processors (classes with state). Creating those 10 for example proccessors for every item in the list will be expensive. Should I use something like object pooling? So I create the processor once and reuse it using a reset pattern? What's the best way to handle it? Also maybe there is a better alternative to classes altogethe?...

Cmd File can´t run on Process.Start(Filename);

I have a Code which has the right Filename (Folder included), and I am trying to run it it through Process but it simply doesn´t work. How can I make it so it runs perfectly. The cmd code itself is completely correct - it works without any Problem...