C#

C

C#

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

Join

Why do my Admin controllers trigger OnRemoteFailure in ConfigureOpenIdConnectOptions when using cust

Why do my Admin controllers trigger OnRemoteFailure in ConfigureOpenIdConnectOptions when using custom authentication policies? I am configuring authentication and authorization in an ASP.NET Core application using both OpenIdConnect and Microsoft Identity. The goal is to make the frontend controllers for my site use the OpenIdConnect (IdentityServer4) and the admin controllers use AzureAd. Here's a summary of my setup: In Startup.cs, I have configured authentication and authorization as follows:...

MSTest: How to assert 2 collections

I am trying to make a unit test to see if the objects in 1 collection (and the order for that matter) are the same (as in different objects, same values) as the ones in another collection. This fails, as apparently CollectionAssert.AreEqual is a reference test. ```cs...

Could not load file or assembly '...' with a weaved DLL

I have a DLL I have weaved with Mono.Cecil, called Draco.Compiler. The weaver adds an assembly reference to Draco.Coverage, as the compiler DLL will call out to functions of this. When I execute with dotnet exec Draco.Compiler.dll, I get the usual exception indicating a failure to locate the assembly:
System.IO.FileNotFoundException: Could not load file or assembly 'Draco.Coverage, Version=0.2.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Now opening up the weaved DLL with ILSpy, all looks good and ILSpy actually manages to locate the dependency assembly as it's in the exact same folder as the weaved DLL. I'm not sure if ILSpy has a different/simpler assembly location strategy or something, but is there any way I could debug why this assembly loading fails when running with dotnet exec?...

visual studio installer including .net6.0 desktop runtime issues on installation

I want to package .net6.0 desktop runtime in my visual studio installer project. So, I put it in the right path and added it to custom actions and it actually builds the installer. But when I run the installer, it installs my app, and then when it tries to install the .net6.0 runtime, it actually shows the below error I attached in screenshot. I tried to remove /quiet in arguments so that I am able to see what is happening, when I try this, it opens up the installation window for the runtime, and midway as it installs it, it says not able to install, and the error message is Another installer is running. It actuall installs successfully when I run it manually. I tried many things and also setting the condition: NOT Installed AND NOT (REMOVE="ALL"), but it keeps resulting on the same error. Does anyone have any idea on how I can include .net6.0 runtime as part of the installation while using visual studio installer project? Thank you!...
No description

✅ OpenApi generation

I have following class generated from swagger ```cs [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v11.0.0.0))")] public partial class RandomSearchDto...

Generically creating a delegate from a MethodInfo with parameter upcasting

I am trying to create a delegate of type TDelegate that allows me to invoke a MethodInfo instance with some upcasted parameters. A simple example of what i want is as follows: ```cs using System.Reflection; MethodInfo someFunctionMethodInfo = typeof(MyTestClass).GetMethod(nameof(MyTestClass.SomeFunction), BindingFlags.Static | BindingFlags.Public)!;...

ServiceController refuse to run on window platform

I try to make new servicecontroller to monitor an indicated Service, the whole program is done on windows 11 computer but I still got not supported platform exception. May I ask to see what should be wrong or what should I check ? The program also run on WPF Library Class with framework is .Net5...
No description

✅ [closed] Where do people get .NET 9 RC 2?

It mentioned as requirement in some Aspire repos. But best I can find is .NET 9 RC 1.

✅ confusing list logic

So, I have a program that allows me delete objects in an array through the console, and the objects are all displayed to the console like in this image (AT THE BOTTOM) And for the objects that I want to delete, I need to the 1-based indices of the objects I want to delete, or a range of indices that i want to delete But I'm having a problem with the code: each iteration deletes objects before the next iteration/deletion, interrupting the next iteration/deletion...
No description

✅ Designing a configurable object in EF Core

Hi everyone! My goal is to have an object for a web project where you can configure the fields it has: ``` public class Structure {...

403 Forbidden

Hello! I am trying to hit an endpoint on Crunchyroll so I can get my auth token. I have looked at various sources and cannot get past the 403 error. I've never used the application/x-www-form-urlencoded content type before so I am unsure if I need to encode it. Format:...
No description

How to get user information when using google authentication in dotnet 8 MVC?

Hi, I'm developing a web application in dotnet 8 MVC. I need to use third-party authentication using google authentication. I have implemented a basic authentication however I cannot retrieve user information like gender, date of birth, mobile phone from claims.
Code files: https://pastebin.com/L8VX6i92 - Program.cs https://pastebin.com/6tjj83ed - ExternalLogin.cshtml.cs What I have tried?...
No description

CS0050: Inconsistent Accessibility

Receiving error message only on methods that return <IEnumerable<obj>>. I checked all my access modifiers and they appear correct. Could anyone assist?
No description

Debugging memory leak

Is there any tool to dump the runtime object dependency tree? I am trying to debug what is holding on to some objects....

Binding problems, property not updating

Hi, im currently creating a snakes and ladders game where the user get to roll a dice and then move a gamepiece by it self on a board with numbered squares. The other player is a CPU and rolls the dice and moves automatically when its the CPUs turn. When landing on a ladder the player goes up to a new square, and on an snake it goes down. But i also want to implement a certain feature where if you land on a certain tile in the gameboard you swap positions with the other player. This is now only...

✅ Cohesion vs Coupling?

i’m having a really hard time understanding the difference between them. Anyone got an easy explanation to it?

Error when migrating from Legacy Blazor WASM into Blazor 8 ServerInteractive

Hellol, As in title I migrated project (Copy pasted old project files into new Blazor template). Page renders visually, but I have no interactivity and at startup I get error ``` blazor.web.js:1 [2024-09-23T10:57:23.330Z] Error: Connection disconnected with error 'Error: Server returned an error on close: Connection closed with an error.'. log @ blazor.web.js:1...

✅ static, what does it actually mean?

does someone have a good explanation to why and when to define a class or method as static? sometimes i get errors which i don’t understand why, but as soon as i define them as static it works perfectly fine. why?

Tried many things to fix this SqlClient exceptions, but no hope

It is a started project given to me, and I have to run the project first, and then exectue the stored procedures. We are using SQL Server for this. I am facing the below error as I run the project ``` Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "database_name" requested by the login. The login failed....

Is it possible to use Reflection to replace a static readonly field without the static constructor?

So, say for example I have a class like the following: ```csharp class Test { static readonly string Value = throw new NotImplementedException();...