C#

C

C#

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

Join

βœ… "Place Geocoding API" how do I get my current location's geometry?

Hi I've created a method which returns the latitude and longitude of a location given by state, city, street address. The next step is: I want to create a similar method which produces latitude and longitude of my current place....

ARM64 SIMD fails assertion where x86-64 SIMD does not

Found something that is possibly a bug, somewhere in C# but I dont have the skillset to diagnose the exact issue. during JIT compilation, I found a differently defined behavior between x86 and ARM for SIMD: https://godbolt.org/z/PjPKEKPqc On NativeAOT,...

Tell IDE that field is set to not null in a method call inside constructor

I'm trying to eliminate some code duplication in my C# project. My class is part of an object pool, so I’d like to set certain fields once in the constructor, and then reinitialize the object later using an Initialize() method. However, the compiler (and IDE) warns me that my non-nullable fields might not be initialized, since they aren’t all set in the constructor. Is there a clean way to let the compiler know that these fields will be set later (e.g., in Initialize()), without disabling nullable reference checks or making everything nullable? Example image attached....
No description

xUnit `MemeberData` function with parameters raises a type error

I am trying to run tests, where I generate a varying number of inputs for my tests. Please help me achieve this. I have been unsuccessful with my current implementation (image), and I am willing to hear how I could improve or redo this. I have no problem starting from scratch. See code attached in image. When I run this test however, I get an error message saying that the parameter 2 was not compatible with the type of the value that is passed to GetNTuples. The specific type error I when I try to run the test is:...
No description

Panels wont size with FlowLayoutPanel (more details listed inside)

how do i make categories within the FlowLayoutPanel that will organise the MP3 files i drop in, as well as staying colour coded? i cant get other panels within the FlowLayoutPanel (white) to size with it. how do i get this to happen?...
No description

c# hw help

i need to complete steps 6, 7, 8 but i am pretty lost about how to do it
No description

βœ… How can I move around controls based on form size?

very new to winforms, trying to get my controls to move with the size of the form. where im at right now when i resize it things either get cut off, or theres a bunch of dead space. how would i go about making the controls move around based on the size of the form sorry if this is a silly question πŸ™...
No description

ClangSharpPInvokeGenerator emitting duplicate/out of order macro bindings

I am invoking ClangSharpPInvokeGenerator on a bunch of headers that altogether constitute ~30,000 #defines and nothing else. The important bit is that these constants are split over tens of headers that are to be amalgamated into a single class/file. The settings are: ```...

βœ… I want to use "Route matrix" with C# backend. How do I know the structure?

I was reading Google website about "Get a route matrix" and how to use this api. Now, the JSON structure is totally different compared to C#, so I failed to use it. I used chatGPT and it created the right structure in seconds, but the thing is that I want to learn how to build the structure by my self. what GPT gave is:...

Migrate .NET Framework 4.8 / .NET Core 5 to .NET 9 (.NET 10)

Hello folks πŸ‘‹! I maintain a solution that contains over 400 projects. They are a mix between .NET Framework 4.8 / .NET Core 5 / .NET Standard 2.0. The majority of web projects are built on .NET Framework with Microsoft.Owin, and some of them still use the old non-SDK project format. There are also several WinForms back-office applications, which we are planning to migrate to web. I’m aware that not everything can be upgraded, i.e. legacy libraries that are already out of support. My current approach is to write wrappers around such dependencies, and then gradually replace those wrappers with modern equivalents....

Is there a way to unload a class from the ram?

After seach in the internet how could I unload a class, the only way I have found is to use AssemblyLoadContext. Is there another simpler way which saves me from compiling in different dlls?

βœ… C# help

I don’t understand how to do the steps collision with the coins and collision with the potions.
No description

ERROR MSB4025

Hello I'm using Visual studio Code with C# Dev kit extension. I'm trying to build MonoGames tutorial game. But when I attempt to run my code I receive, "Build Failures". My terminal states that /media/erobros/CodeProjects/DungeonSlime/DungeonSlime/Game1.cs(1,1): erro MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1. This is reproduced anytime I attempt to run the code. I even deleted the entire project and remade it and still am receiving the same error. My CodeProjects partition is on my secondary NVME it has plenty of space I'm afraid I may have gummed something up. My OS is Linux....
No description

βœ… Calculating the amount of gallons needed to paint a room.

I am trying to create a program where I calculate the amount of gallons needed to paint a room in C#. My question is: the formula is outputting a square footage of 300 ft instead of 396 ft based on the example. So is my formula wrong? Also the instructions require the use of read only get methods and copilot is suggesting the use of _backingfield variables to hold accessed data. Is there a way to just use the get; set; method taught in the book? ...

error during deserialization of a yaml file

I'm building a system that add the config file in the yaml format feature in my program, the program will throw this exception:
YamlDotNet.Core.YamlException: Exception during deserialization
System.InvalidCastException: Invalid cast from 'System.String' to 'dinfo.core.Handlers.ConfigTools.YamlConfigStructure'.
YamlDotNet.Core.YamlException: Exception during deserialization
System.InvalidCastException: Invalid cast from 'System.String' to 'dinfo.core.Handlers.ConfigTools.YamlConfigStructure'.
...

Aspire KeyVault - How to configure secrets and map them to IOptions?

I’m using .NET Aspire Azure Key Vault integration with the Azure KeyVault emulator to define secrets for my Aspire app. In production I’ll use a real Key Vault. The problem: Aspire forbids resource names with consecutive hyphens (--), but the Key Vault IConfigurationProvider expects that format to represent nested config keys (e.g. clerk--webhook-secret β†’ Clerk:WebhookSecret). For example:...

Help with RestSharp and Flurl GET request

I dont understand the libraries of RestSharp and Flurl. I just need to do a simple get request that returns a string that then i convert into a json. I already managed to make a succesful get request with a regular HttpClient so i know that the api works and its these libraries that i fail to understand...
No description

MSBuild: Excluding objects if %(Filename) matches any in ItemGroup

Given a target: ```xml <Target Name="ExplicitRemoveFromFilesToBundle" BeforeTargets="GenerateSingleFileBundle" DependsOnTargets="PrepareForBundle"> <ItemGroup> <FilesToRemoveFromBundle Include="@(FilesToBundle)" Condition="$([System.String]::new('%(Filename)').Contains('TerraFX.Interop.Windows')) AND ('%(Extension)' == '.dll')" />...