C#

C

C#

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

Join

Rainbow using Hex vaValues

Random question: if I wanted to make a rainbow using hex color values, how would I go about it? Surely it's not as simple as just adding 1 to the hex value and then just displaying the corresponding value as a color and then repeating, is it?

AboutView not registered?

/// App.xaml.cs ```csharp protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e);...
No description

Generated OpenAPI document uses PascalCase instead of camelCase on requestBody properties

Hello, I'm still new to .NET and I've been trying to solve this issue for 2 days now. I'm using .NET's Microsoft.AspNetCore.OpenApi package for generating OpenAPI document. It automatically serializes all model properties to camelCase, except for requestBody. I have an upload controller that receives form data: ...

Razor or React?

I would like to do a small pet project - a website. In the backend I will use ASP.NET, but in the frontend I am a complete zero. I would like to be able to show this project as a portfolio of work for the backend. Plus to understand how the frontend connects with the backend, at least on a minimal level. But I don't know what is better to use for frontend Razor Pages or React....

✅ Is there a difference when we use { get; init; } vs { get; } ?

```C# public record Person { public required string FirstName { get; init; } public required string LastName { get; init; }...

✅ What is a primary constructor in C#

Hello guys, was just reading a bit about primary constructors. My question is, primary constructors is just a "fancy" way to write less code instead of declaring a whole constructor? Or are there any reasons why we would use primary constructors?

Application Insights OpenTelemetry fresh install not showing stack trace

I just installed Application Insights OpenTelemtery into a fresh copy of IdentityServer 7. I'm getting a 500 error on login. The error.type field shows System.InvalidOperationException, but no stack trace is shown. Identity Server 7 comes with SeriLog installed by default. I'm not sure if that's somehow intercepting something but it seems as though if it can get the error.type, it should be able to get the stack trace. Normally I see here a checkbox Just My Code, and when I uncheck that, I see the full stack trace....
No description

✅ Early return with yield

How to i early return despite using yield The method goes like ```csharp IEnumerable<int> ProcessXml(string path)...

How can I enforce `[StructLayout(LayoutKind.Sequential)]` metadata to be included in nuget package?

Background I have a C# library 'A' which is essentially a P/Invoke binding layer of a C++ library 'a'. And I have another C# library 'B' which depends on 'A' to add more P/Invoke functions to it. Some P/Invoke function parameters in 'B' uses the structs from 'A'....

Maui - pre build targets iOS

I have a Maui app. It’s a white label application that will have many brand styles applied to it. To do this I am running a target in the csproj to copy images and files around pre build For example like this. This is an example of it. ...

✅ Is it possible to override ToString method for Anonymous type in C#? (Not using overriden one)

Hello guys, just wondering if it was possible to use another implementation of the ToString method for anonymous type. I was just using LINQ to perform the following: ```C#...

Cant bind styles to elements

Hi!! Actually I am very new to WPF and would appreciate some assistance with a problem I have with this. So this is the element tree looks like: Main Window - > contains Navbar -> contains Nav Button <- used by Base Button...

✅ Event Handler functionality

Hi, I have an assignment where I need to create a list of rooms, each represented as a unique object. When a user clicks on a room, they should be able to press a button to request a booking for that specific room. However, I'm unsure how to use the selected room's object to transfer its details to another page, where the user can continue adding booking information. Any guidance would be appreciated!

FileNotFoundException: Could not load file or assembly 'System.Data.SqlClient, Version=0.0.0.0, Cult

``` public void makenewuser() { string constring = "Data Source =LAPTOP-3KI3JMHO; Initial Catalog = Stormz; Integrated Security = True"; using (SqlConnection con = new SqlConnection(constring)) try...

Array as Public Property; Need to Set Value at Index

I come from C/Lua/VBA background, very new to C# or anything like it. Using .NET 9 and Onvif.core with VScodium/Omnisharp on Windows. Onvif.core has this class: ```C#...

C# Compress with large window size (26)

I want to compress files that are big so i need to have a larger window size but i dont find any way to do it brom brotli encoder and all the third party libs are ass slow as hell with same parameters help.

im watching a course about asp.net and creating some kind of web

but everytime i try to do "dotnet ef migrations add init" it says "Unable to create a 'DbContext' of type 'RuntimeType'. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[api.Data.ApplicationDBContext]' while attempting to activate 'api.Data.ApplicationDBContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728"
No description

Planning an app out before starting

I want to make a gong fu cha (tea brewing style, the main thing is that it involves even up to 10 steeps, first ones are short and they're getting progressively longer) timer & steep counter app with a statistics tab. The timer should allow to set a base steep time and an increment to be added each round. The app should allow to see how many brewing sessions there were each month. Each session should have the tea's name in it and a space for flavor and scent description. I'll be using AvaloniaUI and focus on mobile. I guess I'm going to need some sort of database for the descriptions and saving the sessions, I worked with entity framework and postgresql before. I want to give test driven development a try, seems like a good thing to know, although I don't know if I'll be able to do it before determining the app's structure down to each function and accurately tell what needs testing and what doesn't. Did I miss anything important?...

Serializing a Function in Unity using AnimationCurve

Hey there guys, I'm working on a game with Unity right now and I have a few classes which basically represent certain types of functions that I want to use in some contexts. What i would like to know is if there is a way to translate my functions into animation curves (ideally using a custom attribute such as SerializeCurveAttribute) so that I can use Unity's built-in serialization for said curves. I'm not quite sure how to go about this, as I've barely written any attributes, and the decompiled code for Unity's SerializeField literally contains nothing. Here is the code for my curve classes: ```cs public interface ICurve...

FirstOrDefault and other methods are not working in LINQ

```C# using System.Diagnostics; using Microsoft.AspNetCore.Mvc; using practical.Models;...