C#

C

C#

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

Join

SQL overwrites instead off adds

public bool AddNewCustomer(CustomerClass customer) { SqlCommand command = new SqlCommand(); command.CommandText = string.Format("INSERT INTO tblCustomer VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')", customer.CTitle, customer.CForename, customer.CSurname, customer.CEmail, customer.CContactNum1, customer.CContactNum2);...

βœ… Switch - return πŸ€” ( attached )

I’m getting an explanation on switch in C# and I don’t quite get what the last return outside the scope has to do with it - does. Any idea?
No description

βœ… new to MySql and trying to set up a basic database that will get connected to a .net projekt

ive set up my MySqlworkbench file and called it WordDatabase but cant seem to open a connection to the MySql server saying it cant connect dunno how to make it actually connect would gladly appreciate some guidance...
No description

βœ… [SOLVED] MSBuild Task says file does not exist

I've made a custom MSBuild task to zip up the newly created .dll along with relevant files for release whenever the project is built. For some reason though, it says the newly created .dll does not exist... When the log literally shows its existence in the exact location like two line up: ``` CopyFilesToOutputDirectory: Copying file from "/home/newmaz/Documents/HFF_ObjectGrabber/build/obj/ObjectGrabber/Debug/Debug/ObjectGrabber.dll" to "/home/newmaz/Documents/HFF_ObjectGrabber/build/bin/output/ObjectGrabber.dll". ObjectGrabber -> /home/newmaz/Documents/HFF_ObjectGrabber/build/bin/output/ObjectGrabber.dll...

βœ… bracket pairing isn't working

my brackets keep joining into the wrong pairs whenever I finish my function how do I solve this
No description

βœ… Memory issue in ASP.NET Core video playback endpoint

```cs [HttpGet("filePreview")] public async Task<IActionResult> GetFileForPreview(string filePath) { if (!System.IO.File.Exists(filePath))...

Struggling with Securing Environment Variables in Deployed Desktop Apps

Hello, I'm creating an Avalonia desktop app that takes user input and generates a pdf by overlaying input text over a template image. The end result is a certificate for the completion of a canvas course for the interns at my company. The pdf generation is done, and I didn't have any issues with that. However, I would like the end user, whoever is handing out a certificate, to have an email send to the certificate recipient when the pdf is generated. I've used Gmail SMTP to successfully send the emails, but I couldn't figure out how to secure the environment variables in the deployed app. I then tried setting up an AWS Lambda function to hide the environment variables, but now I have the API Gateway endpoint that I don't want hardcoded into my application. It seems like any solution to this will just continue to push the issue further back. So, my question is: is there any way to deploy a .NET desktop application that does what I want it to do while keeping environment variables safe? My thought is that I might need to set up some kind of authentication and an actual web server on an ec2 instance to do this. Maybe I should just drop my goal of sending emails from within the application, but it seems like there would be some way to do this....

Trying to figure out what project preset type is best for deploying my project.

Could use some tips; I'm looking at deploying a project at work towards a Linux server. i currently have an ASP.NET Web API project (for the backend) and i've got an MVC project for the Frontend. I've been recommended to use a Blazor app for the frontend; Which makes me wonder if it's generally considered good practice to place both the Front and Backend into the same Project for easier deployment? Or should i keep them separated in their own projects under the same Solution?...

Go To Declaration doesn't consider RID for a Nuget package

I'm developing a OS-specific library with bunch of #if directives. As an example, consider the following method: ```csharp public static void Method1() { #if WIN_X64...
No description

typeof(T).IsAssignableFrom does not work as I expected

There is a method in a generic class PluginLoader<TPlugin> : IPluginLoader<TPlugin>: ```csharp private static TPlugin? CreatePlugin(Assembly assembly) { var types = assembly.GetTypes().Where(t => typeof(TPlugin).IsAssignableFrom(t)).ToArray();...

βœ… EF Core 8: System.InvalidOperationException: 'The instance of entity type cannot be tracked..

Hi guys, I'm getting this error
System.InvalidOperationException: 'The instance of entity type 'OccurrenceRule' cannot be tracked because another instance with the key value '{Id: 0b87b74b-c1b9-48f5-954a-2613fbab92d0}' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.'
System.InvalidOperationException: 'The instance of entity type 'OccurrenceRule' cannot be tracked because another instance with the key value '{Id: 0b87b74b-c1b9-48f5-954a-2613fbab92d0}' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached.'
but the thing is for the query where OccurrenceRule is loaded, I'm using AsNoTracking() method since there won't be any changes for that entity anyways. ...

βœ… I need help

I am new to coding and i dont know where to start i have tried learning it but i cant. Do u have anything that can help me learn to code C# ?

βœ… Abstract Class vs Interface

I am building a WPF financial application from some VBA code I'm rewriting in C#, someone else wrote the VBA and so far I've managed to translate 40% of the functionality. I have the following structure: public class I03 -> reads + filters out invalid financial transactions from a text file interface ILineItem -> defines properties for the following classes:...

Help with license system

i need help with adding a license system in my project

No permission for file saving when hosting .net apps on docker.

I'm learning ASP .NET and I'm trying to make a simple API that recieves files and saves them on filesystem. Everything works fine when saving locally, but when running on docker and saving to a volume I always get permission denied. The problem seems to be caused because owner of the volume is "root" but current user is "app". I'm not really sure how to change it....

One IEnumerable with 1 item mysteriously becomes empty after I query a second IEnumerable

The variable pkeys has one item immediately after the query that returns it is executed, but then when the query that returns ckeys query is executed, suddenly pkeys shows Enumeration yielded no results while ckeys contains one item. ```cs var pkeys= qry.GetTableColumns(tableName) .Where(col => col.Kind == Column.ColumnKinds.PartitionKey) .Select(col => new PropertyGenerationModel(col));...

Global variable not identified

I do not understand why this function can identify this global variable, i'd like to manipulate it inside the function
No description

entity framework help needed pls.

So I have this method which is the main logic of Spinning mechanism. And well those are the main models where I have issue, Issue is that when I assign dateEnded to session which means that this certain session is ended right, in this spin logic in one of t he first statement it checks that, if the session is ended it creates new session which I want to be saved in the database. and I am 100% sure I assign playerId to it but well the error says it can't be assigned the null and doesn't saves Here is part of debugging pics too and it txt file there is spin method....