C#

C

C#

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

Join

Identifying something with an attribute with IIncrementalSourceGenerator

I am currently using ForAttributeWithMetadataName. According to the documentation, it has a chance of generating false positives. What I am currently doing is checking the identifier and seeing if it matches the attribute name. This doesn't work in the case where an alias is used, however. Is there a consisstent way to detect an attribute?

WinForms error after inserting a picture

Hello, I inserted a picture on a button and realized that its way too big scaled, so I deleted and and insertet a new picture with another name. Then I restarted VS22 and get an fatal error saying I cant open the designer. If I put a File with the name of the old file it works fine. I already deleted the button in the designer and everything related in the code, but I cant fix it...

WPF Framework Canvas Automatic Scaling based on largest coordinate in list

Hi. First of all, thank you for reading! I have a MVVM WPF application and having some trouble with the Canvas and how to draw shapes that are automatically scaled to the canvas size. ...

Mono.Cecil weaver messed up branch targets

I'm trying to write a simple Cecil-based weaver that simply logs each seqeunce point. This is simple, I can iterate over all of the sequence points and insert an Ldstr to load the log text and a Call instruction to something like Console.WriteLine. To make sure that branch targets don't get missed out on this logging, I go through the instructions again, and patch each branch target to make sure that they now point to these preceding log instructions. The weaver code is attached because it's too big for discord (only 120 lines tho). It works for loops, if-else statements, but for some reason when I use an if-else in a for loop, the jump targets get completely messed up. The smallest example I could find where it messes up is weaving this: ```cs public static class Class1...

Access is denied

Hey, I have this problem that when I try to run code on Visual studio (with or without debugging) it shows me "Access is denied" I tried running it as administrator, changing setting and even reinstalling the either app but nothing worked.. I posted about the same problem here couple days ago but nothing worked

MSB4019 error when building Windows game binary on Linux

I'm learning C# and MonoGame, and I wanted to verify that I could successfully build a redistributable windows binary of my WIP game, so I decided to first confirm I could do it with one of the MonoGame sample projects, in this case AutoPong (see https://github.com/MonoGame/MonoGame.Samples). Attempting to build, I get the following
/usr/share/dotnet/sdk/8.0.108/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1355,3): error MSB4019: The imported project "/usr/share/dotnet/sdk/8.0.108/Sdks/Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets" was not found. Confirm that the expression in the Import declaration ";/usr/share/dotnet/sdk/8.0.108/Sdks/Microsoft.NET.Sdk/targets/../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets" is correct, and that the file exists on disk
/usr/share/dotnet/sdk/8.0.108/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1355,3): error MSB4019: The imported project "/usr/share/dotnet/sdk/8.0.108/Sdks/Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets" was not found. Confirm that the expression in the Import declaration ";/usr/share/dotnet/sdk/8.0.108/Sdks/Microsoft.NET.Sdk/targets/../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets" is correct, and that the file exists on disk
...

Blazor: calling a function on submit

Please someone tell me if I'm approaching this the wrong way: when a form is submitted I want to display a modal for which I have a function "ShowModal()". I attempted to call it at the end of the HandleSubmit function appointed to the form. However, the page reloads on submit...no modal is ever shown. Example below: ```c#...

Cartography/imaging: understanding projection between heterogeneous 2D coordinate systems

Assumptions; the question is very agnostic to any languages or tooling, although I am approaching with CSharp and SkiaSharp specifically, but is neither here nor there concerning the core question. Which is: projecting between a world coordinate system and canvas resolution coordinates. The world coordinate system is very large, 1.5M whole numbers, represented as decimal for centimeters and fractional cm precision; neither here nor there except to understand the A coordinate system. The B coordinate space of course is the target bitmap, in whatever resolution, may be 8K, 16K even 32K, bandwidth and memory permitting, square. Thus far the naive attempt is to apply a simple world per bitmap ratio, or pixels per world, depending upon the point or rectangle bounds conversion. But there is always an error. Example image: the circle and points are accurate relative to themselves; but are inaccurate to the target bitmap in question, the scaling being something like 183 units per px error involved applying any ratios to the source coordinates. This error can vary depending on the source bitmap resolution, of course. So the algorithm should be robust keeping that in mind....
No description

✅ Having trouble handling errors when registering a new user

So my application is a .NET web api with a React front end, and im trying to handle all my errors on the backend during the register process and I dont seem to understand how errors are handled. When a user signs up im trying to account for all possible issues they could run into. For example wrong password length, missing special characters, uppercase, etc and then the same for email for example is it a valid email, is there any mistakes in the email for instance test@test,com as opposed to [email protected] I noticed that modelstate is always valid with email part, but for password things seem to work. the error that gets thrown when the email is not in a correct format actually comes from here var result = await _userManager.CreateAsync(user, registerRequestDTO.Password); and it throws this error "Username 'test1@test,com' is invalid, can only contain letters or digits." and I can't seem to figure out how to make it handle this error correctly so that it is in the format below, I don't think I can just hard code it because what if a different error is thrown, i want it to always come back in the format, Key: ['array of errors', '...' ] like below....

GUI programming tool

Hello, im looking for a "drag and drop" GUI Desktop app creator, since windows forms just wont get into my head and the software I want to create unfortunately doesen´t exist and I need it for personal use only. Are there any good, easier options?...

✅ Visio for C# class program

HI. Does someone know how in microsoft Visio can make the "Applies to ->" and the arrow?
No description

✅ Making a chess program. Why is this happening?

I don't understand this error and nothing online makes sense to me, so can I get a firsthand explanation of what I've done wrong? Or probably done wrong?
No description

Tilemap control in MAUI

In WinForms I have a TileViewer control, which basically just displays a Bitmap on the background image. While reacting to mouse events, I can leverage the Graphics object from said background image to draw a tile cursor and other things over the image. All together, this works as a fantastic tilemap editor for old games. In an effort to port such an application over to MAUI, I now need a replacement for such a tile display. So far my search was unsuccessful. It seems like no one has wanted this before and ChatGPT started halucinating some Draw functions that do not exist when I asked it the same question....

How to make a sliding panel animation on Avalonia>?

Hi, im working on a avalonia project , but its similar to wpf i have a login panel, (username password etc) but id like to add a sliding animation to that to make it look more professional, how would i do this?...

How to break programming plateu

Been programming for 11 months learnt the fundementals of c#. and chose a ui structure (wpf/ avalonia) but then what? i feel like i almost know nothing, bulding stuff is hard. doing easy problems on leetcode is even harder, i almost feel like im learning nothing like ive been stuck in tutorial hell...

I am trying to add a custom cursor to my winforms app

i cant figureout how to do it and when i look it up its not working

Need Unity audio help.

So basically i have 5 audio clips for walking that i want to play when walking, crouching, and sprinting. I also want it to change randomly in pitch, and frequency depending on what type of action im doing. Finally i also want the sound effect to be randomly chosen from the 5, some help would be majorly appreciated.

Using code to reference code

So I have a collider, and I have code elsewhere that tells my UI counter to go up. That code lives in LogicScript and it's called addScore. I'm trying my best to reference it within my collider's script using the tag "Logic", but there's definitely something wrong with that big logic = line as well as the logic.addscore line. Does anyone have any advice? :')
No description

Priority queue, queue empty error.

Hi, I am getting an error when trying to use the peek method that says that the queue is empty. However just before this I use the enqueue method to put something into it. Why is this error occurring?
No description