C#

C

C#

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

Join

Trying to embed custom font in WinForms project

I'm currently trying to embed the 'Rubik' font onto a WinForms project following the steps on the correct answer in this SO post: https://stackoverflow.com/questions/556147/how-do-i-embed-my-own-fonts-in-a-winforms-app I include the font non the Resource Explorer of the project and then mark the generated .ttf on resource as an Embedded Resource but then the project doesn't build due to the error 'Could not find a part of the path D:\Documents\Workspace - C#\FactuCrossing\FactuCrossing\Properties\Resources\Rubik-VariableFont_wght.ttf and ```Invalid Resx file. System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\Documents\Workspace - C#\FactuCrossing\FactuCrossing\Properties\Resources\Rubik-VariableFont_wght.ttf'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)...
No description

Trying to understand required members

I can't seem to set the value of a required member through a subclass's constructor. https://dotnetfiddle.net/Gz6b7M Any help is appreciated....

I am getting every time new token I have set token expiration time for 1o minutes.

Can anyone explain why this is happeninig everytime when I logging in with same POSTMAN reruest why every time it is assigning new token,
No description

Dynamicly scaling objects to window size in Wpf

Is ther a way to dynamicly scale objects to the window size? Right now, I am creating like grids inside of grids to get an object to be at a specific location and make it resize to the window size. But is ther an easier way, that doesn't involve creating like 10 grids?

.exe wont run outside of Build Folder even when using Fody?

Question is in title would love to get some help on this as I am confused as shi since it used to work before

How to get a Type by string without specifying the assembly name, if it's among loaded asms

Okay, it's been forever since I had to do this in C#, but I need to get a Type by name without having to specify the assembly name, if it is among the currently loaded assemblies for the app domain. What's the best way to do this. Basically I want it to do what Type.GetType() does but a bit more permissive in that it searches all loaded assemblies instead of just the calling assembly when it comes to nonqualified names

Generated assembly with xml file which contains all documentation

I using this code to generate assembly with xml file and I doing something wrong? Like in IDE after referencing Assembly-CSharp.dll I can see comments but not after hovering?
No description

Problem with Pop3Client

Hey, I'm making a post service/ smt like that app for my school asignment. I'm having issues, because the login credentials that work for sending emails (MailKit) dont work for retrieving them somehow (Pop3Client). ```cs // MailPage.xaml.cs public void LoadMail() {...

Blazor WASM: Injecting a service

I'm trying to inject a service to extract details (dimensions, so far) of the browser. The code for the service is from https://blazor.tips/blazor-how-to-ready-window-dimensions/ . The service is registered in the Client project's Program.cs: ```C# builder.Services.AddScoped<BrowserService>();...

Blazor WASM + prerender - handling forms on client & server

I'm trying out Blazor WASM + prerender and I noticed that form submission is handled by either server or WASM C#, depending on whether the latter is loaded (yet). Given that some logic must run on the server (e.g. DB access), what's the standard approach to "marshalling" the invocation to the server? I definitely prefer to have WASM handle the initial submission for interactive validation, status display, etc...

✅ Path Resolution in .NET MVC Project

Guys, I added the wrong path to my.NET MVC project for CSS and favicon icon ; it should have been ../ or ~/, but it worked well with ./. Is there any rational explanation for this?

✅ Random error only when app is run on same server as database

I made a simple dotnet application that uses a remote database When I run it on my local computer it works flawlessly, I dont see the error and the application works When I run it on the same server as the database half of the time I get errors half the time it works correctly with no error I was told the connection needs to be closed but I dont think I did that correctly as I still get the same errors...

How and what to Test

I'm trying to become a more professional developer so I'm adapting to best practices and all that But recently i wanted to get into Unit testing my C# applications but ran into an issue: I have no idea what to even test in the first place, for example what if i develop a desktop applications, a Discord bot, a web API using ASP.NET or even a library, Id love to write Unit tests but i have absolutely 0 clue what to actually test someone send help :SCcrying:...

Specifying 4xx Details

I have a POST request that may cause a duplicate entry if it were to execute. As a response, I send back 409 Conflict to make clear what happened. However, I have some trouble adding some detail to explain what exactly happened. First, I tried the following, which is not RFC 9110 compliant because it returns a simple text/plain: return Conflict("A string explaining which property is already reserved");...

updating a MySQL database from EF Core

Ive got a MySQL database i am accessing via Entity Framework Core using Pomelo.EntityFrameworkCore.MySql. I initially generated the Data and Models based on the database, but now Ive made changes to the models (in c#) and i want to push those changes to the database. How do i do this?...

NRT: How to correctly annotate my generic-class when inheriting from another generic class?

Hello. I'm trying to correctly annotate nullable reference types (NRT) to a generic class derived from another generic class. Here is some simplified code: ```csharp // Some dependency interface IOther {...

Looking for a logging solution

I'm trying to figure out how to log my SQL or database commands into a configurable JSON file. This is for a school assignment, Ive tried adding events to each query, I don't fully understand it still this is the main criteria: Database commands shall be logged. The log file location shall be configurable in a manner similar to the database connection string. The log shall be in JSON format:...

IDisposable ownership semantics

This is primarily a question regarding whether or not C# has introduced any sort of syntactic sugar or support for a "nicer" way of expressing transfer of ownership. For the purposes of this question, nullable types is fully enabled and static analysis that will issue CA2000 as an error is also turned on. Consider a method that returns a type that implements IDisposable and needs to either return it, or ensure it gets Dispose'd if an exception occurs - Currently I'd write something like this:...

WPF: Binding selected item of ComboBox inside ItemsControl

Hello, I'm currently exploring WPF and kinda stuck with one particular case. I have ItemsControl with ItemTemplate being a ComboBox: ``` <ItemsControl ItemsSource="{Binding Values}">...

Dev express label printing problem in Debian how can I fix it?

```18:42:41.811 | ERROR | API=0.0.0.0|Paper size (Width:15000hmm Lenght:10000hmm) not found System.ArgumentException: Paper size (Width:15000hmm Lenght:10000hmm) not found at DevExpress.Pdf.Drawing.Printing.UnixPdfDocumentPrintHelper.AssignMediaInfoSettings(IUnixPdfDocumentPrinter printer, LibCupsInterop libCupsInterop, CupsPrinterInfo printerInfo) at DevExpress.Pdf.Drawing.Printing.UnixPdfDocumentPrintHelper.Print(IUnixPdfDocumentPrinter printer, String printerName) at DevExpress.XtraPrinting.Native.UnixPrintingSystemExtenderPrint.Print(String printerName)...