C#

C

C#

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

Join

✅ which .net version should I be starting with?

i downloaded the latest version from the dotnet website, 9.0, and attempted to use this -> https://github.com/gui-cs/Terminal.Gui to build out a simple console app with a TUI, but I got an error saying that i need to be on .net 6, which is marked as end-of-support. is it fine to stick with 9.0, or should I roll back to 8.0? its not terribly important that I be able to use Terminal.Gui, I just don't want to be locked out of using other libraries because the version of .net i'm using is too new....

WPF Datagrid scrolling

I have a Datagrid that is bound to thousands of rows, so I have enabled RowVirtualization, but I also have large “RowDetail” sections so I can’t use ContentScrolling. But RowVirtualization requires ContentScrolling so I’m not sure what to do

SourceLink with private, authentication-required repo

Been trying to get this to work off and on for many months at this point, so hoping I'm missing something. We've got a number of new NuGet packages on a privately-hosted BitBucket server. They're configured with SourceLink support. When using Resharper, we can navigate into the source code of the packages after providing user credentials as shown. However, Visual Studio's native SourceLink integration doesn't seem to be able to comprehend the authentication portion of it. Whether I'm using the Git Credential Manager fallback or not, any attempt to debug into the same packages fails with a "Source Link authentication failed" error. There's an Authenticate button on the error screen, but it does nothing (i.e. the button can be clicked, but there's no popup or other control displayed). I'm running out of things to try, and really need this to work to meet our developers' needs. Git credentials are stored in the Windows Credential Manager, and work properly in git natively. Interestingly, if I try to open the SourceLink URL in the error through a Windows File Open dialog, it presents a Windows Security popup that allows me to enter credentials, but my domain credentials (used for normal BitBucket access) are never accepted, no matter which variant I try. Opening the same URL in a browser immediately downloads the file, as I've logged into BitBucket via the browser and therefore have appropriate session cookies in place....
No description

VS Code Fails to Highlight Missing Symbol in @code Section of .razor File

I couldn’t debug my app and wasn’t sure why at first. The only error I got was:
Unable to launch browser: "Could not open wss://localhost:7171/_framework/debug/ws-proxy?browser=...
Then I opened the solution in Rider, which pointed out the actual issue:...
No description

Enemy slower nearer the player it gets

Hello, does anyone know how to make a script to make the enemy slower depending on how close they get to the player? (the game is in unity, 2d and it's top down if that helps. c# ofc)

WPF buttons

Hi all, I am very new to wpf c# or just coding in general. I am trying to recreate these kind of buttons (To be exact I just want the rounded corners the image in the aligned in the center and just a single caption underneath like the WPF GitHub) I have this for my code but it is generating a lot of issues and also doesn't apply the corners or semi transparent background ...
No description

WPF .NET 8.0 cant find System.Management Reference

Hey folks, I just recently got into C# and want to create a Desktop app to get comfortable with it. I created a WPF Project with .NET 8.0 as the Target Framework and wanted to get the name of the user's mainboard. I used this piece of logic, which requires the ManagementObject, which requires me to use the System.Management namespace...
No description

most efficient way to add "" to text in script?

i have question, whats the most efficient way to add "" to the script? lets say i have 100 lines of text my writter wrote for me, he used enter to make the lines correct lenght, but didnt add the "" do i have to add each one each time for each line? or is theres a smart way to add it for all 100 lines?...
No description

✅ Modern T4 Replacement for Design Time Codegen

Hey all! I'm currently working on a library in which I was previously using a T4 template to generate many variants (varying on generic arity) of a struct type. I'm essentially at a point where I would like to rewrite the template for easier maintainability going forward (and to support multi-file output), and was wondering if there might a better option for design time codegen. Especially since T4 seems to be stuck on Framework and the syntax highlighting is very finicky. One option I did some looking into was utilizing raw string literals and interpolation within a C# script file and running it via dotnet-script during a pre-build task, but alas, Rider is yet to add support for .csx files. So, without proper intellisense, diagnostics, and highlighting, it unfortunately doesn't give me a better workflow than I had using T4....

✅ Hosting ASP.NET (.NET 9) on Linux vs Windows

Hi, Is hosting an ASP.NET application on Linux just as straightforward as on Windows these days? It’s a Blazor WebAssembly app with a Web API backend, built on .NET 9....

Folder text/code grabber

hey yall, so im making a windows form app. I want to add a menu that connects to a certain folder. eg. you program something in my app, save it to your folder, and want to access it again later, i want it displayed in this menu. how would i do that?

✅ EF Core migrations with Docker

I'm trying to do a simple blazor app that works with database but I can't find a standardized good practice to perform migrations. I'm running both db and blazor app via docker compose.

Wanting to make a basic, super simple, proof of concept platformer game in c#

For a Uni assignment, i need to make a project. I decided to go with a simple game wher you control a square that moves and jumps around. I'm a bit overloaded on where to start (Using visual studio 2022) and was wondering if anyone could help.

✅ Help Using SignalR with Groups

Hello guys I am building a discord like GroupApp.I made it work sending the messages.However I want to save them and in a state of a reloading the page to display them again.

State of caching in EFCore 2025

Hi. Sorry if the question is banal but I have application using EFCore with postgresql for data access. In my situation whenever I do operation that touches user profile (read/write) I would like to cache the entire user for 10 minutes and then whenever I make changes also apply them to cache and actual db after that, refreshing the 10 minute cache... ...

SignalR: OnDisconnectAsync() doesnt get called when i host on IIS Server

Hello, i am facing a problem where OnDisconnectAsync() doesnt get called if user exits abnormally (close app,connection lost...). It works fine locally but not when hosted on IIS.Any help? Thanks in advance

XAML Binding

Trying to bind an input from an input in our viewlayer, but it comes back as null and i'm a bit uncertain as to what's going wrong. Linking everything i think is important (first time asking here, and very new to coding) Employee class: ...

Hangfire implementation in Repository pattern

Hi, sorry for newbie question. I am trying to add hangfire to my project. I believe I am using DDD to the best of my ability trying to incorporate hangfire and follow DDD architecture i've hit a snag. here is some code snippet from my hangfire implementation in each layer:...