C#

C

C#

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

Join

Disposing dbContext with dependency injection

Hi! I am developing an Avalonia UI app. I am displaying there some data, which is stored in the sqlite database. The data - rows in that matter - can be deleted or added, but once they are there - they are not modified (at least for now ;)). I have a factory which gets data from db and then creates a view model passing there the data (and few other things). The factory itself I've registered in service container as a singleton and dbContext as a transient. dbContext is injected into the factory. As I am not tracking entities changes and not adding or deleting data in that place, I've configured the context with optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);....

[VS22] Brackets auto format

Hi Whenever I want to declare an array below a comment, Visual Studio moves the line. Does anyone know which setting causes this? (see attached video)...

Issue referencing a library within a cloned GitHub project

Hi all, I know this sounds quite silly and probably is.. I have been struggling to reference the namespace "DirectXTex" in: https://github.com/Neodymium146/gta-toolkit/blob/master/RageLib/Helpers/DDSIO.cs From what I see/know. DirectXTex is a c++ library of sorts to process DDS files (an image format used in game textures). ...
No description

How can I check if an index of a 2d array is out of bounds?

tittle ```cs if (array[value1][value2] == outOfBounds) { // do smth }...

Hosting an API

Hello! I want to host my API to the web but I don't rlly know what service to use. I have an ASP.NET Core API, Clean Arhitecture with a local SQL Server Database. What would be the best method to get it on the web along with the database? Thanks!

How terrible is this Result implementation?

```cs public class SuccessResult : Result { public object? Data { get; protected set; } ...

Blazor css not applied

Hi, i have a component css file for my blazor component where i have definied ```css .preview-container .markdown-body {...
No description

Controlling state changes from the root object

Hey all. I have the following structure of objects, which basically consists of a PhaseHolder, which contains a collection of Phase. Each Phase can hold a Comment, and each Comment can hold a list of Reply. ``` public class PhaseHolder { private readonly List<Phase> _phases = new();...

Why is the struct allowed but the class isn't?

The error is CS8618 - Non-nullable variable must contain a non-null value when exiting constructor. Consider declaring it as nullable. The struct is readonly if that matters....
No description

Window title bar causes layout issues

I have issues with layout being different when the app is executed. It gets messed up when the WindowStyle is set to any border style like SingleBorderWindow, but when it's set to None, the layout is as designed in the editor, how can i fix that?
No description

Database In ASP.Net Core

Hello! So basically we all know when we create a SQL Database in Visual Studio Community with EF and SQLServer and we can store data there. My question is this: when we add the app to a website like Heroku or a Hosting App in order to publish it to the web, does the database with all the data gets added too or is there a separate process for that? Thanks!

Fresher Interview

Hello everyone, I'm going to have an Interview for Fresher .NET position. There would be a test before the Interview. I wonder if I can have some advices from you. Thank you in advance !...

Controller methods that rely on JWT authentication using another service

Is there a way to handle these methods without writing so much duplicated code? For example CRUD methods like this: ```...

โœ… Need help with folders in VSCode

Who can help? How can I open a folder with projects in vscode and not just one folder in which the project is, before I could open a folder in which there were several folders with projects, but now it displays this error.
No description

Trouble Setting up double controllers in a single MVC .net project, API controllers and MVC controll

Hi all, Hope so you are having a good one. So basically its a complete web solution which also have a mobile application in the flutter, now for that reason I need to have API controllers. I am bound to use one project, to avoid double hostings and other complexitites that might come along the way. What I did is Created MVC .net project set up API controllers in it about auth and stuff...

โœ… very simple fix, im just not smart enough.

hey, could someone tell me how to get rid of that blue highlighting when you hover over a button in wpf? would really help thanks ๐Ÿ™‚

Noob C# enjoyer building a project from other people

hello, i git cloned a project from github and iam using vscode i already installed c# and c# dev kit, the project has .csproj and .sln but iam not sure how to build using vscode, the project iam trying to run on vscode: https://github.com/BoyBaykiller/Newtonian-Particle-Simulator
No description

Where i should use async await?

I have two methods. One of these will be used from "public async Task<int?> SomeASPNETControllerPostMethodAsync()". Should i use await async everywhere or only in Controllers? Which one is the best for performance?...
No description

Edit view directs to 404 not found

A beginner's mistake - the problem is that i have been getting Site Not Found 404 error (as per screenshot) while I wanted to display the edit dashboard view on localhost:https://imgur.com/a/mw5wBkD i think the connection between my view (html and js) and controller has gone wrong: https://pastebin.com/n4cfnwLp Could anyone kindly point out what I have been missing out here?...
Next