C#

C

C#

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

Join
NMRNacho Man Randy Cabbage5/3/2024

Binding DataGrid to DataTable. DataGrid's ItemSource is null on first load. - WPF

I'm trying to bind a DataGrid to a DataTable located in my viewmodel. The columns are dynamic hence why I'm binding to a DataTable and adding the columns and rows in the viewmodel. The relevant VM code looks like: ```cs private DataTable _data; public DataTable Data...
AAlex5/3/2024

Google External sign in using Identity

I want to learn how to implement a google external sign-in route (and Identity in general) in my ASP.NET Web API but I can't find any recent tutorial on that topic. Microsoft's official tutorial is for RazorPages only and tells you to add AddAuthentication().AddGoogle() and everything should work. I want to create it for Web API because I need it for the React front end. I found a few tutorials but they are 3-5 years old. Can you suggest any tutorials on this topic or for Identity in...
TTreF01L5/3/2024

JwtBearerAuthentication

Guys, I'm so damn tired. I can't figure out why my code isn't working, been sitting with it for 12 hours now. I want to create a jwtBearerAuthentication and use it with SwaggerGen(). However, I don't get a header with the Bearer token in the request when I use Swagger (no errors), and when I use Postman to validate this request, I get an authorization header, but the HttpContext.User.Claims will be null. There are no errors and that puts me in a quandary.
FHRFredrik Høisæther Rasch5/3/2024

SourceGenerator and LibraryImport

I am considering writing my own source generator. Among other things it will also generate some PInvoke bindings. Ideally, I'd like to use LibraryImport instead of DllImport in the generated source. But since LibraryImport in itself is a generator, can I do this?...
Llil_big_doot5/3/2024

Is it possible to pin an array using reflection?

I have an interpreter I'm working on and I'd like to support some usage of pointers, but right now all .NET interop is based on reflection or calls to functions I've defined ahead of time. As far as I can tell there's not a way for me to pin an array through a reflection call, but I want to avoid emitting a dynamic method because that won't work on iOS/AOT Alternatively I was thinking maybe there's a way I can pin the array without using fixed so then the duration of the pin is managed manually by me? Not sure if there's something like GCHandle that can help me out here...
HHalfbax5/3/2024

Publish Failure of Class Library with WinAppSdk dependency

I have added a class library that references WinAppSDK. Now I am unable to publish my program. I don't encounter any errors while building, only while publishing.
Cannot resolve Assembly or Windows Metadata file 'I:\projects\Name\Shared\Name.Core\bin\Debug\net8.0-windows10.0.22621\win-x64\Name.Windows.Core.dll'
Cannot resolve Assembly or Windows Metadata file 'I:\projects\Name\Shared\Name.Core\bin\Debug\net8.0-windows10.0.22621\win-x64\Name.Windows.Core.dll'
...
RSRusty Shakleford5/3/2024

Issues with DataAnnotationsValidator and ValidationSummary

I am currently following a tutorial to learn Blazor (I'm working in 8.0). I have a MessageWall.razor file, containing: ```@page "/MessageWall" <h3>MessageWall</h3>...
NTnaber top5/3/2024

Saving Feature Help

I got a list I use in my app want to add a saving feature but don't know which filetype to use besides txt whats your recommendation?
Rrestingphantom5/3/2024

Update or create portfolio EF CORE

I have a venture in my db that has 1 portfolio linked to it (the portfolio is the venture information), Right now I have a API call for venture in which I can alos change the portfolio details, Could/should I make the venture call also be able to add a portfolio if one doesnt exsist already or should I do this in seperate api calls if so how would I go about linking the new portfolio to the venture?
VVerpinZal5/3/2024

Attempting to retrieve a Windows process name causes Access Violation Exception.

The code snippet below is supposed to retrieve the parent that launched my application and display it. It can be explorer or any other Process through which my application is launched. Actually, this code works. Problem is, while Release works, Debug can't get past the searchById line. ``` var processId = Process.GetCurrentProcess().Id; var queryFromId = string.Format("SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {0}", processId);...
No description
TTOKYODRIFT!5/3/2024

✅ How to fill the object without populating properties?

I have this record: ```cs public sealed record WorkingTaskWithFlights: WorkingTask { public List<Flight>? Flights { get; init; }...
JJammyG5/3/2024

no such table

I'm not sure why i'm getting this, I do have a table called users. Am I formatting the query wrong?
No description
HHensoro5/3/2024

How do these parameters even work?

I have a project where I need to transfer information from my GUI's textbox and turn it into an average(census) but I have to do it from a class file. Our professor gave us this method with parameters and told me to pass the information but i don't know how and its messing up my code.
No description
RRdZoid5/3/2024

listbox SelectedIndexChanged on load?

Hello, I'm newer to C# and I'm making a windows form where a listbox lists customers and populates txtboxes to the right if the index changes, er is supposed to because it does it on load. Where would this be caused to fill in even when the form loads and the index hasn't changed?
No description
Wwhatsinaname5/3/2024

did anyone use Seq for logging?

I wanted to run the Seq but the source I wanted to integrate is azure application insights. Is there a way to do that?
S2spooky2play5/2/2024

Branching paths for a text based adventure game (language agnostic)

How would i create a system of branching paths for a text based adventure game? i dont want it to devolve into a ton of if-statements because i have done that before and it is a mess to keep track of and maintain
Jjs5/2/2024

invalid index error which i dont understand

```cs string temp = selectionItems[selection-1].ToString(); string name = temp.Substring(0, temp.IndexOf(",")); string toppings = temp.Substring(temp.IndexOf(","), temp.IndexOf("£")); string[] toppingsArray = toppings.Split(", ");...
No description
CC3lamity5/2/2024

C# interfaces

If anyone could help me with some information or videos on how do I implement graphical interfaces on C# and if the dev app is different from macOS and windows?
NNorwayFish5/2/2024

What is the Base Class Library?

If I understand this correctly, the CIL does not have instructions for performing syscalls, therefore all of the syscalls are done through call instructions into native implementations. Then it follows that all of these implementations are a part of the dotnet runtime. If this is true, what exactly is the BCL and why does it come with the dotnet SDK but not with the runtime?
Next