C#

C

C#

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

Join

Webview2 missing from toolbox

Tried to manually add it by right clicking and choose item -> browse and add the .dll manually as shown in image but i get an error i tried pre-relases and older version everything, edge is updated on my computer and i am running vs2022 community any tips?...
No description

I dont see the problem?

Can someone help me see the problem? i attached some photos....
No description

Microsoft Visual Studio autochanging a line of code because its "obselete" but the AI ruins the code

so intellisense change rb.velocity = new Vector2(speed * x, speed * y); to rb.linearvelocity= new Vector2(speed * x, speed * y); This ruins the code because linearvelocity messes up 2drigid stuff. How do i turn it off?...

Cant import scoped Javascript in Blazor Standalone WebAssembly

In the past I have already done this in InteractiveServer Blazor, which is to import {page}.razor.js in my razor page through IJSRuntime in the OnAfterRender step of the page lifecycle. as follows: Page.Razor.cs ```cs...

Worker Service .NET8 how to gracefully shutdown as a docker container

I'm a junior developer just starting to work with Docker, and I have a question regarding graceful shutdown of the worker services. I created a default worker service in Visual Studio, and my Worker class looks something like this: ```csharp...

My Database doesn't appear to be populated, yet when I run my program, the website does show correct

The information from my database initialiser does show up on my website, but when I look in the SQL Server Object Explorer, there seems to be no data Initialiser Code if it helps: https://paste.mod.gg/bxebrzqarvwn/0...
No description

Launch an api project multiple times with different appsettings with Aspire

I have an asp.net project X which should talk with multiple other asp.net projects Ys. I would like to start them all with Aspire, but I would need to give every instance of Y its own appsettings. Is this a possiblity with Aspire? I saw that I can run a project with different launchprofiles, but I'm not sure how that could help me in my situation. Thanks for the help!

✅ Dependency restores to incorrect package

I have a dotnet solution called A.sln which depends on another solution B.sln. Both A.sln and B.sln have some child projects which has some const value differences depending on the platform: * A.Win64.csproj, A.Win32.csproj, A.Posix64.csproj, A.Posix32.csproj * B.Win64.csproj, B.Win32.csproj, B.Posix64.csproj, B.Posix32.csproj ...

My static String in library project becomes null when i enter a controller in API project

Hello so i have two projects. A library project(where you define models and call API Controllers) and API project. In library project , i defined a static class with static string and string is not null. but i am having a problem when i call a controller this string becomes null and when i exit the controller , it returns to its ordinary value. Does someone know how or why? Thanks in advance

How to access functions in another class in the same namespace?

Hey dudes. I come from a background of Pascal and Lua, so bear with me if this is an obvious question. I've got a big class, and I want to move some of my functions into another one to keep things tidy. But it appears to not be as simple as just making another class in the same namespace, and calling the function from there. That throws the error: An object reference is required for the non-static field, method, or property 'Util.CanMarry(Hero, Hero)' So what's the approach to adding functions that are called by another class? Pic 1: The new helper class with a function in it...
No description

Default literal and non nullable reference types

Hi there 👋 I create this post to chat about the default literal. How come that the default literal for every non nullable reference type is null ?...

In String constructor `String(Char*)`, `Char*` is character pointer or character array pointer?

I was exploring System.String class here: https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-9.0 And one of the constructors is String(Char*) Its description says: Initializes a new instance of the String class to the value indicated by a specified pointer to an array of Unicode characters....
No description

✅ When and when not to use a DTO?

I know you shouldn't really send the exact database model to the client and instead choose only the data that should be sent to the client, but when if you are querying the database for a super specific projection of data, and the DTO would end up looking exactly like that projection. Should you still make the DTO or is it perfectly fine to just return the projection as the response, or query the database directly into the DTO.?

How to manually upgrade a websocket connection (preferably with a popular package like Fleck)

For authentication (this isn't a traditional web server so I planned on not using like ASP.NET, plain console). I'd prefer not creating/managing a websocket connection from scratch, but if there's no other option with C#, i guess ill have to.

EF attributes vs built-in C# keywords (like required). Differences and when to use?

Essentially what the title says. In this code ```cs using System.ComponentModel.DataAnnotations; namespace Easygym.Domain.Entities...

How can the color of this section be changed for every page?

this is a MAUI project and i dont know to change it
No description

Fetching XML files from Azure Storage Explorer sometime fails

So for work we have a Azure Storage Explorer Fileshare where the customer sends XML files. Our Job fetches files from this fileshare every ~20 minutes maybe. Some files works fine and some just straight up fails with this code ``` var xmlFileByteArray = _azureHelper.GetFileBytes(fileName, sourceDirectory); if (xmlFileByteArray is null)...

TS6385

I have met this TS6385 (JS)'(handler: (S:JQueryStatic) => void): JQuery<document>' is deprecated I have try to update Ensure jQuery Types are Up to Date but it's not solves this problem. It have problem with "ready". How could I fix it? Thank you so much $(document).ready(function () { loadDataTable();...

array exercise

i want to generate numbers that are unique and dont duplicate int[] x = new int[10]; for (int i = 0; i < x.Length; i++) { x[i] = Random.Shared.Next(15); Console.WriteLine($"{x[i]}");...
Next