C#

C

C#

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

Join

Data seeding with anonymous objects in .NET 9

I recently began migrating some projects from .NET 8 to .NET 9. One of the things I now run into is the Seeding part with Entity Framework Core. My seeding in my projects is done in the OnModelCreating and I add an extra environment variable to ensure that this part does not happen all the time. I then use something like: ```...

Roslyn Incremental CodeGen from text files not working

I wrote this codegen dll for internal use in the project, but i cannot reference the generated source code in the "CodeGen" project Referencing it from "Common" project: ```xml <Project Sdk="Microsoft.NET.Sdk.Web">...

✅ Nested Record Inheritance

I'm trying a bit of inheritance shenanigans, the API I'm working with wraps everything in a data object, which usually has two fields that always appear: ```cs public abstract record CharacterActionResult([property: JsonPropertyName("data")] CharacterActionResultData Data); ...

Is there an issue with C# Winforms image resizing function?

I was using this snippet of code to resize the image and display to a picture box: Bitmap resizedImage = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(resizedImage)) { g.InterpolationMode = InterpolationMode.HighQualityBicubic;...

✅ Issue with try/catch block

I am trying to catch an exception, null the bad value, and throw the exception again so the code that calls this function can handle it. I've attached screenshots of both sections of code. It's saying that the exception is unhandled even though I am using try/except blocks to catch SshAuthenticationException in both. Changing the exception to catch just Exception does not fix this. I must be missing something here.
No description

hi guys good day can anyone help me with my MVC web app regarding simple validation on modal bootstr

I am trying to create my simple mvc that add a customer using bootstrap modal with different model request. and my main concern is i want to trigger the validation in the modal only it wont go to other page.
No description

trying to update my java jdk path but having issues

I'm having issues updating my java jdk. I unpackaged the latest and successfully have a java_home env var set but it still tells me something is wrong and i need to update the pathing. It says to put the path at the machine level but I don't know what that means. Currently, I have the jdk in a marked folder under documents. This is for my maui project i'm trying to update some dependencies on. ```ACTION REQUIRED: ✗- Java Development Kit (JDK) - The selected Java SDK version 17.0.13 is not recommended. Ensure the required JDK version 17.0.14 is configured by installing the JDK, and then setting the JDK at the preferred level. 1. Install the JDK:...

✅ Issue with Collection Expression in the ubuntu-latest VM of Azure.

I have this build that fails in my azure pipeline with The call is ambiguous between the following methods or properties: 'string.Split(char[]?, StringSplitOptions)' and 'string.Split(string?, StringSplitOptions), but it doesn't fail locally. From what I understand, it's because of the difference in the SDK used locally, and the one used in the VM used by the build agent, ubuntu-latest. This SO answer highlights the reason, and how to address it: https://stackoverflow.com/a/78959408 How would you go about actually addressing it, considering that my pipeline's yml definition requests ubuntu-latest, so unless I actually downgrade to something older than a year or so, it will still happen right? ...

How to properly test my system ?

Hey I’m working on a microservices setup and wanted to pick your brains a bit. Here’s what I’ve got so far: - Service A exposes PATCH/POST /shipments endpoints...
No description

MediaPicker pictures not showing up properly after uploading with MAUI

Hey, I'm making an app where you can report an incident and also add pictures to it. After either picking a photo from gallery or making a new one, I want them to be shown after selecting. Showing them on the page is done using a collectionview binding to
public ObservableCollection<ImageSource> Photos { get; } = new(); In my Task AddPhotoAsync the taken or selected picture is put in result ...
No description

WPF Icon

Hello i seem to have a quite annoying issue with wpf on multiple projects. Icon for app is show on .exe normally but in task manager there is no icon. Only the child window of app has the icon? Is this known issue, any fixes?

clean architecture, what are the references

i dont know which scheme is true and for which cases, didn't really learn from google either
No description

dotnet ef migrations add init returns: 'Unable to retrieve project metadata.'

Just what it sounds like in the title, ef is being difficult and won't make a migrations folder which I need in order to test with. My installed sdks are 8.0.100, 8.0.405 and 9.0.203. I am on Arch Linux but installed these through the install script from microsoft. As for EF Tools I'm using version 9.0.0 but have also tried 9.0.2 and 9.0.4, neither worked and the same error is returned each time. I have tried running the command with --msbuildprojectextensionspath and it yielded the same r...
No description

How can I use .NET lock files (LockedMode) reliably across Windows, macOS, and Linux?

I'm trying to enforce deterministic dependency resolution using packages.lock.json with <LockedMode>true</LockedMode> in my .csproj. The problem is: the lock file ends up being different depending on the platform I'm restoring on (Windows vs macOS vs Linux), likely due to how runtime-specific assets are resolved by default. Is there any solution to able to run dotnet restore on any platform without modifying it?...

How do I reference a Native Dll project in a managed C# project in same solution?

Both projects are in the same solution. I added the native project as a project reference but the native dll doesn't seem to be copied to output directory of c# project because my LibraryImports cannot find it.

Where does dotnet core on linux search for root certificates?

I am trying to make calls to a service and am gettinjg the following: "The SSL connection could not be established. The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot" The target service is using ca-certificates.crt from the node it's running on (provisioned on the cloud), and I want my service to also use the root CA from the node. ...

✅ identifier "CreateCoreWebView2EnvironmentWithDetails" is undefined

I installed WebView2 via NuGet and im getting this (be friendly im just a beginner)

✅ Database-Update problem

Hey everyone! I'm trying to update my DB in my .NET MVC project, but I’m running into some issues. I used everything, but I still can not fix it. Can someone guide me on how to properly fix it ? Thanks in advance!"
No description

✅ How do i get .NET 4.x on VS 2022?

Im really new to C# and i wanted to use .NET 4.x but i don't see it in Target Framework and i already have .NET 4.x installed on my computer.
No description

ObservableProperty isn't updating on the UI

https://github.com/nevemlaci/Modpack-Autoconfig---CS-Edition I have explicitly subscribed to PropertyChanged ( here ) , and this is actually hit when I place a breakpoint there, but my custom converter is not hit whenever the property changed, so I assume there is some mistake I made that means the UI isn't being notified about the property change....
Next