C#

C

C#

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

Join

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....

entity framework net 4.8.1 urgent help needed

heeyy, im currently working on my graduation project and im working on a wpf .net 4.8.1 project and got entity framework installed, but every time i hit the update-databse command it says that it cant find the resx file, but its set as an embedded resource, i really dont know what to do and i got only 1 week left

How to get indents for code formatting right in Scriban

I'm trying to use a Scriban template for generating a C# model class, and it's working OK so far, except for indentation. The template looks like this: ```cs using Cassandra.Mapping.Attributes; namespace {{model.name_space}}; public class {{model.name}}...

Online/offline colour menu colour change

Hi all, as the title states I am trying to get the menu items to change colour to green if pingable, red if not pingable. An online/offline thing if you will. I am very new and still learning. Currently this is what I have, im trying to use the code in the converter.cs and the main functions are in the MainViewModel.cs any advice is more than welcome!...

Find all instances of a substring in a string

I would like to try and find all occurrences of a substring in a string without regex, and without looping through the string with IndexOf. Is this possible? Oh don't ask why, it's really an experimental, academic exercise.

Auto Code Cleanup moves top comments in razor file

Hey there, Ive been stuck on an editor, Rider, issue for a while now, but cant find anything on how to solve it In my razor files (a blazor component, not an @page) I often have a comment at the top of the page, with underneath it @using statements, but when I "Reformat and cleanup" the code, by right clicking on the file, it moves the code about so the @using statements are at the top, and then being followed by the comments which werte at the top of the file beforehand. I cant find anything in the rider docs, or the .editorconfig that could help me so far......

✅ Verify Signed Message with Server's Public Key?

Relevant Docs: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsacryptoserviceprovider.verifydata?view=net-9.0 Code in reply. After calling RetrievePublicKey() on client and then ProtectedSign("Hello") keep getting false printed because _clientRsaProvider.VerifyData(dataToCompare, SHA1.Create(), signedBytes) is False. ...

Silly OOP question about constructors

I am learning OOP and came across this. A way to reuse constructors: ``` public Dog() : this("NoName") {} public Dog(string name) : this(name, 1) {}...
No description

How to Prevent ClearText Submission in ASP.NET Core

I want to prevent cleartext submission to encrypt all sensitive data, including passwords, during data transmission

[SOLVED] Accessing HttpOnly Cookies during Prerendering

When using a Blazor Web app (WASM) with server-side prerendering, the page initially loads on the server and then on the client. During the prerendering phase, I can send a request to my API to retrieve some data that is authenticated using an access token that was stored in the cookie. But the HttpContext does not seem to have any cookies during prerendering. How can I access the cookies in this situation?

Help needed trying to integrate PJSIP in a wpf app

I was wondering if I could get a build of it like .dll file only for the windows, no max and mobile things. Because im not able to use it myself and make a release of it, one configuration error after the others thanks a lot

How should I include 3rd-party JavaScript Libraries in my ASP.NET Framework SDK-style project?

So I SDKified this ASP.NET Framework 4.8 website. I see that we have lots of nuget packages for 3rd-party libraries like infuser, trafficcop, etc. I also see that we've committed these javascript files wherever we felt like it and referenced everything to those paths. I also see that there appears to be a SO article that says not to use nuget for javascript files, even though you technically can. ...

Graphic Editor using WinForms

I have to create an application in winforms. It will create a polygon in the top of the image to colorize the image. What Control to i really need to build this application.
No description

creating migrations on an existing DB to add a column(efcore)

so I have a webapi project, dotnet 8 efcore 8 and postgres project was DB first and hence scaffolded. now I wanna add a property to an entity of mine AND/OR add a column to a table I have always done db first and never done code first and have never touched migrations. tried adding migration but doing so it wants to create all tables with updated columns. tables already exist and have data I'd rather not lose (though it wouldn't be end of the world as it is a personal project for learning) so wondering how can I add a column without dropping my tables and not updating my table with sql command scaffolding it again. Most resources I've found involve somewhat hacky way of adding migration and deleting the content in up and down methods in migration though I don't understand how that might help ?...

Missing logs in Aspire after changing env and IDE

Recently I made a move from Windows device with VS 2022 to a MacOS and Rider. For some bizzare reason all app console logs stopped being monitored. For example the 1st API call trace is being logged but everything afterwards is not. At the same time I can see all the logs being written to a server log file. Any idea how to fix it?

✅ StreamReader returns empty string on valid file stream

I have this code:
using var reader = new StreamReader(stream, Encoding.UTF8, false, 0x400, true);
str = reader.ReadToEnd();
using var reader = new StreamReader(stream, Encoding.UTF8, false, 0x400, true);
str = reader.ReadToEnd();
...
No description