C#

C

C#

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

Join

Inject User and Claims to DbContext using Factory

I've put the last 2 days trying to figure out how to solve a problem which I believe have to do with the combination of Blazor Server, State management and EF Core via Factory. I need to get TenantID from Users Claims to be able to resolve a connection string, dynamically. What I have come up to is that following registering of DbContext does not work when multiple users log in and out within same circuit i Blazor. The connection string is not updated:...

Parameter count mismatch error when trying to change what is being displayed in a Blazor application

```cs @foreach (var assessment in AssessmentService.Assessments) { var editAssessment = false; var updateAssessment = assessment;...
No description

✅ How to get better at writing EF Queries?

Maybe I just don't really understand things, but I create database tables try to separate things and do all the relationships, and then I start having to do these massive includes like this, and I feel like its just going to cause performance issues ```csharp public async Task<IEnumerable<Category>> GetAllCategoriesTaskListsAsync(string userId, string categoryName) { return await _context.Categories...

Vulkan?

What library for using vulkan should I use?

ASP.NET + ReactTS project, how to debug with Firefox in VS?

When I add a ReactTS project to the solution, VS creates a .vscode folder with launch.json inside This file contains the following: ```json { "version": "0.2.0",...

CopyToOutputDirectory is not including directories

I'm doing a project here i'm working on 2 diferent computers, one is Windows with Visual Studio and the other is Linux with VS code. In windows, the project runs well, without any errors and everything in the right subdirectory, but when i try to compile in linux, the program returns a runtime error saying it cannot find the files cause they are not in the right directories.

✅ Overlaying a Semi-Transparent Panel on an Animated GIF in C# WinForms

Hi, I've been trying for days how to add a semi-transparent panel above a picture box that contains a gif in c#. I do know how to do that with a picture that is not moving, but I want to do that with a running gif. Could somebody please help me?

✅ Difference between property, method and fields.

Hello guys, I know there is a difference between method and fields, with method representing an "action" while the field an "attribute" of an object. But what about property? I know that when we declare a new class for e.g, their is something called as the "automatically implemented properties"; I know that these are setters and getters implemented using simple line of codes. Then I encountered this phrase: The properties of an exception object can be accessed within the catch block. For example, you can use the Message property to inform the application user of an issue. ...

✅ What is a DLL (Dynamic Link Library) file? Why is it useful?

Hello guys, can someone explain what is a DLL file and why is it useful please. From what I've read, DLL are files that contain compiled code, that is the intermediate code that will be interpreted by the .NET runtime. But notice the call stack in the picture; they are all DLL file within the same main file, so I'm a bit confused, the compiler doesn't compile everything related to a single main file into another main compiled file?
No description

BL - UserManager custom role

Let's say when registering a new user to the web api. For my use case (since I am doing role based access priority) I need to create a default role "User" I wonder how it is done normally. I am thinking about doing it directly inside the program.cs in the server side In my last project I did it like this hardcode alongside admin user...

Parsing data from several sources into a common format.

I have several data sources that I get data from that I must parse into a common format. Say this is the common format (simplified example): ```csharp public record ProductDto(...

How to automate translating an English XAF application to Hungarian (or any language)?

I have to translate my Visual Studio 2022 DevExpress XAF app from English to Hungarian, which means I have to localize it. I know how to translate the texts one-by-one and I see that there is an Import... button to add a .csv file that imports the translation .csv file. Obviously I don't want to manually translate hundreds of labels, but I don't have a .csv to do it either, and the Translate... button just copies every label from 'Default Language Value' to 'Translated Value'
No description

Problem with binding

Hey guys, im having issues with binding in this code: https://paste.mod.gg/bxttdnuopcri/4 i started doing my game from the start to make it easier to code later...

✅ Newtonsoft JSON - file not found

i have this code inside a Song.cs class ```c# public void load_from_file(string path) { string newPath = System.IO.Path.Combine(Environment.CurrentDirectory, path);...
No description

Exception Handling in C#

Hello guys, sorry to disturb you all; consider the following code: ```C# try {...

Immediately delete image file after it being closed

In my program i have byte[] imgSource. I create image file in temp folder: ```c# if (container != null) {...

✅ How can I check if an array need to be resize when adding an element

```C# class CustomList<T> { private T[] items; private int size;...

Creates new object instead of updating it

Hello, guys, I have a very simple MVC WebApp and I faced a problem. So thing is for some reason my edit method creates new instance in database instead of updating given object. From what I can tell issue is within my html form, because if I add input field for Id there it works fine.

✅ Can custom attributes use interfaces somehow ?

I have an interface named IConfiguration and I'm wondering is it possible to write a custom attribute so I can do [StaticConfiguration("Key"]var settings: Settings so that the StaticConfiguration attribute will get the config for that key from IConfiguration and parse it into the type Settings?