C#

C

C#

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

Join Server
Kkenvnx1/25/2024

Polymorphic query handling in EF Core - Thoughts?

So I'm having to deal a lot with entity polymorphism and querying the db to avoid having to execute multiple separate queries. I'm not sure about best practices here, but i also have to eagerload certain nav props from the derived types. Anyone know a better way than this? ```cs private async Task<IReadOnlyList<CoreProduct>> GetCoreProducts(IEnumerable<IProductRequest> requests, int internalPropertyId) {...
PPrateek1/25/2024

How to show validation message for a nested object's property in a list in blazor

I have 2 models Customer and Contact. A customer can have 1 or more contacts. I'm using EditForm and Mudblazor with ObjectGraphDataAnnotations Validator and a custom validation component (taken from Microsoft Documentation). I'm using the custom validation component to validate the customer name is unique by checking the database (which works correctly) and I'm able to validate that the contactNames in the list of contact objects are unique but i'm unable to show the validation message for that particular field. I'm only able to see this validation message in the validation summary. I'm passing the validation message using a dictionary of field and its value. I've tried passing the field name as $"customer.Contacts[{index}].ContactName" (The relevant part of the code is under the 1st comment from the bottom in the AddCustomer.razor file) but it doesn't seem to work. For code and more details refer to https://github.com/MudBlazor/MudBlazor/discussions/8092...
Tthefake1/25/2024

making an overlay

I want to make my own overlay, just like xbox gamebar or that geforce experience thing where you can broadcast, etc. I dont want to tab out of my games when I just need media controls to skip a song. I want it to be similiar to the ALT + R thing from geforce experience where you get an overlay, that shows you info. How should I do this? I’d like it to be a system tray thing that toggles the gui on keypress. Should I do this with basic .NET C# in visual studio to make the gui and make it system t...
Yyeetyoottoot1/25/2024

i dont understand why sometimes this code works and sometimes i get an infinite loop

``` public List<List<int>> roomMatrix = new List<List<int>> { new List<int> {-1, -1, -1}, new List<int> {-1, -1, -1}, new List<int> {-1, -1, -1}...
BBlackBerry-Py1/25/2024

Assigning Values to Nested Class Members

I am new to C#. I am wondering how to instantiate an object with nested class members: ```c# namespace LearnosityCookbookRecipe {...
VVortac1/25/2024

How to use Server Sent Events with HttpClient

I'm working with an API framework (https://docs.mistral.ai/api/#operation/createChatCompletion) in which you send a chat request. If you set the stream parameter to true:
tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
...
Ppxd1/25/2024

How could I implement the tree correctly using XAML?

Hello! I've started a XAML .NET application https://github.com/PerikiyoXD/RWTree/ The problem I'm facing is that I'm creating chunks of data in classes that are going to represent a tree. ...
No description
MMarc1/24/2024

Forwarding domain emails without a mailbox

I have a few domain names on GoDaddy and they charge to have a mailbox, although I don't need the mailbox, I just need to forward the email to an existing gmail or outlook account. Here's a mockup of what I'm trying to do. I have full control of the DNS on all domains and I am able to add MX records, but how can I tell gmail or outlook that they should be receiving emails from these specific emails?...
No description
AJAlma j1/24/2024

How do i send zipefile html with video and image

So I'm doing a project at school and I am using Visual studio code.. I've usually don't code so i do not have a clue but I was going to save a coding excersise we did that was a template where you inserted images and a video on the template to make a website that had both video and pictures. When I saved it, there was no problem, I could also make a zipe file and open it again. But when I send it to a friend they can only open the website with the text. What has I been doing wrong?
RRudyJapanHero1/24/2024

Having Trouble setting Outputpath for FrostyHash.vcxproj

I'm not entirely sure where to set the output path in the vcxproj due to it looking different to the cproj's and need some help figuring out how to set up the outputpaths for it so i can compile the dll this is the error i am getting trying MSBuild version 17.8.3+195e7f5a3 for .NET Determining projects to restore......
GMgr8stalin's mustache!1/24/2024

How do I set environment variables for a MAUI Android app?

at work my team and I have been struggling with how to get values (versions, prod urls, etc.) we store within environment variables in our build pipeline. our process works fine for our web app, but our environment variables don't seem to exist when our MAUI Android build is running. we tried troubleshooting this in our local build as part of a group debug session, and i noticed that when i asked my teammate to call GetEnvironmentVariables from the immediate window, we got the same batch of variables back every time. our environment variable was nowhere to be seen, but when we ran our unit tests, the tests picked up the variable just fine....
JJoellao1/24/2024

Database Scaffolding going wrong.

Hello all, reading the title you can imagine what I want to ask today. Using efcore to add migrations and scaffold the tables. I have this relationship ```csharp public class UserEntity : IdentityUser<int> {...
FFraznoFire1/24/2024

best way to handle multiple codebases interacting with same db?

Hi everyone, I’m working on a “bank” project that has two codebases, the first is an ASP.NET based API that the website front end interacts with, and the second is an Azure Functions based service worker that is used to run scheduled tasks, such as interest payments. Both use EF Core to talk to the DB Essentially, I have the API ready to go, but it has several data validation checks when interacting with the database, such as source account has enough currency to cover the transaction etc. I’m not sure what would be the most scalable way to replicate that code to the Azure Function, so that if I make any changes to the model used or something, how can I make sure that the function’s code stays in sync without manually copying it across?...
No description
Hhubdyxx1/24/2024

Rider projekt problem

Rider says that Project is not specified when i want to run it. I made console project in new repository
No description
Jjetblacksalvation1/24/2024

Blazor Modal Service

I want to use this service in blazor webapp. But i cannot figure out where the types they use in the guide are defined
No description
WWhiteboy1/24/2024

✅ EF with MySQL getting double/triple time values ?!

So i assign task to user and set the assignTime to DateTime.Now so i should be able to get remaining time right? ```cs var userTaskAssignment = dbContext.UserTaskAssignments.FirstOrDefault(assignment => assignment.TaskId == taskId && assignment.UserId == UserId); if (userTaskAssignment != null) {...
Ssteadfast1/24/2024

Where can I learn to make a desktop applications in C#?

I want to learn how to develop desktop applications in C#, but I'm not sure where to start.
Ccandrd1/24/2024

EF6+.NET Framework+ Postgre issue

Maybe the title is confusing but i need help, i want a really basic code first app. I researched 3 days but i can't find any solution to this problem. When i try to enable-migrations PMC gives me this error. I can share my codes if you want. My connectionString is true.So don't ask me this please.
An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.
An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.
...
VKVignesh Krishnan1/24/2024

Securing .NET Framework Applications Against SQL Injection: Unraveling Windows SSL Vulnerabilities

I have developed a .NET Framework 4.7.2 Windows application that utilizes a SQL Server database. In this application, I have employed the SQLClient package to establish connections to the database. The connection parameters include encryption, ensuring that queries in outbound traffic remain concealed from the Microsoft Network Monitor and Wireshark. However, a vulnerability was discovered when employing the Echo Mirage tool, enabling SQL injection or hooking into the .NET app process on Windows. This allowed for the viewing and alteration of queries using the tool. Through my analysis of the SQL injection tool's traffic log, I identified three types of hooked modules: Windows Socket, OpenSSL, and Windows SSL. When configuring Windows Sockets, I observed that the traffic protocol was TCP, and the queries were encrypted, providing a secure environment. However, configuring Windows SSL revealed a vulnerability. I could view and modify queries by injecting the process in Windows, and the protocol was displayed as "???" with source and destination set as 0.0.0.0....
EElmishh1/24/2024

how would i set a keybind while the process is minimized

im working with mouse input and movement and i need an easy way to kill the program incase something goes VERY WRONG any way to very easily set a keyboard button to Eviroment.Exit(0); or any code at that?...