C#

C

C#

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

Join

c# API + angular front end

Hi, This is more of a design question... I have a web api written in C# and a front end writtein in angular. The web api has a settings file associated with it. The web api and front end are both served by kestrel (same port). The front end has some settings as well (in the assets folder). One setting, for example, for the front end is a theme. The theme can be changed using the front end, where it makes a request to the API to set the theme setting....

[ASKING FOR JS] Javascript wont load after post refresh

this is offtopic cuz Its more about javascript, why do whenever I post refresh the second time, it wont execute my javascript code..but if I want it work, I have to refresh it or redirect to it.. ```js <div> <table>...

Query Rider TODO etc. comments for a solution, project, or file into console output

The TODO list Tool Window is very useful, but I would very much like the ability to pull that list into a markdown file as tasks for an Obsidian markdown note. Any ideas on how to do this, or must I copy the TODO patterns and filters into my SourceReporting Roslyn based app and apply the filters to all comments in a CSharpSyntaxNode or something?

I have a huge exam next week

So I have this huge exam next week as well as two projects that are due next week. I’m new to c # and everything seems so picky and confusing. I’m so overwhelmed by everything. Can someone please help me...

Code Forces Problem Way Too Long Words

So I am trying to solve problem way too long words from codeforces here 's the link to check it https://codeforces.com/problemset/problem/71/A now in my code i have created logic for word which have more than 10 characters would become in a special abbrevations and words which are less than 10 characters would be print as it is but i am not able to filter and remove int if user inputs integer with string here is my code ...

SignalR

await _hubContext.Groups.AddToGroupAsync(HttpContext.Connection.Id, "MND"); await _hubContext.Clients.Group("MND").SendAsync("InvokeNotification", User.Identity.Name, "responseMessage"); Not working and I can't find out whether the user is added to group or not...

Switch Expressions

Im trying to convert different numbers in a switch expression while switching over a Type and noticed a strange behavior, that when I do an int.Parse(...) Im actually getting a double out of the function, see my example here: https://dotnetfiddle.net/QrgZqP why is this designed this way?

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.?