C#

C

C#

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

Join

Docker

I am trying to start databse by docker but it fails by saying that that port is already in use "Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5432 -> 0.0.0.0:0: listen tcp 0.0.0.0:5432: bind: address already in use" But then i run - lsof -i :5432 It shows nothing. No other docker image or container is running....

Collection was modified. Enumeration operation may not execute.

Code: ```cs public async Task<bool> DeleteFolder(Folder folder) { if (folder.SubFolders.Any()) {...

Learning how to use ASP.NET and Angular

Hello chat, I have a question. Being a beginner this week, approximately how long would it take for me to be efficient in ASP.NET/Angular? Would one estimate that it would take 1-3 months as with regular programming? Also where is the best place to pratice the above without having to rely on youtube/tutorial-hell?...

Calling a method in a class running on a separate thread from the main thread

Hi. I'm not very good at threading stuff! I'm developing a plugin for a 3rd party app. The app provides hooks via a ISystemEventsPlugin interface. Whenever an event happens in the app, it is raised in this interface. I am wanting to start a class ("process"?) on another thread with its being instantiated by a specific event fired by the app (SystemEventTypes.BigBoxStartupCompleted). This is only fired once. I have successfully instantiated the desired class on another thread (I think - it runs OK and I can see it as a separate thread in the "Parallel Stacks" debug window). However, my query is how do I pass subsequent SystemEventTypes firings to this instance. ...

Get values from appsettings in .NET Core

Hello, I have this function in which I try to get a value from app settings file with the IConfiguration but it seems the method I got to use doesen't exist in this current context. How can I solve? private readonly IConfiguration _configuration; public APIKeyValidation(IConfiguration configuration)...

Need help with text files

There is a text file with numbers. First number means category and five others are points. I need to sum the points but have trouble doing it. Also there may be several categories with same number. If there are, they need to be showed as one same category and their points need to be summed.

Verbosity to the point of unusability in generic graph class

I am trying to create a graph class, I'm using a lot of generics, it works fine but adding a weighted edge of weighted vertices is extremely unwieldy and basically unreadable.
weightedGraph.AddEdge(new WeightedEdge<Foo, WeightedVertex<Foo, int>, int>(new WeightedVertex<Foo, int>(new Foo(), 0), new WeightedVertex<Foo, int>(new Foo(), 0), 0));
weightedGraph.AddEdge(new WeightedEdge<Foo, WeightedVertex<Foo, int>, int>(new WeightedVertex<Foo, int>(new Foo(), 0), new WeightedVertex<Foo, int>(new Foo(), 0), 0));
This is insanely verbose but I have no idea how I could improve it without sacrificing type safety or versatility....

records, with expression, required property

I'm hitting a strange behaviour and not sure if it's intended. I have the following record definition: ```cs public record Options {...

ScrollViewer and resizing Canvas problem, please help!!

Hi! I'm developing an application as a final work of one of my subjects at university, whose main purpose is providing an UI in order to keep track of your exercise with some bar graphs and stuff (in the photo). These graphs have to be developed exclusively in WPF, we cannot use extern libraries. However, I find myself in trouble because, as the user can add their own data, the Canvas has to resize dynamically and also has to redraw continuously its own content. This leads us to the main problem, which is that, although I supposedly resize the Canvas, the ScrollViewer that contains the Canvas doesn't, giving an strange functionality to the user in which they have to resize the window in order to see the full graph (and if the window takes the whole screen they wouldn't see anything, just a tiny part of the graph). If anyone could please help me, I have to send this project at night (GMT +1), and I'm trying to achieve a great mark even if I might not succeed. Here's the XAML (i have the scrollviewer disabled due to the problem i have): <ScrollViewer Name="elScrollViewer" Grid.Column="1" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" Margin="5,5,2,10"> <Canvas Name="elCanvaGraficos" Grid.Column="1" Width="580" SizeChanged="elCanvaGraficos_SizeChanged" Loaded="elCanvaGraficos_Loaded" /> </ScrollViewer>...
No description

Adding middleware

Hi! I face an issue whilst using the azure serverless signalr with azure function as bindings. When Signalr is running using websockets the authorization header is null and i must use the query to retrieve the token. How can I register it in my function? this is my Program.cs ```csharp var builder = FunctionsApplication.CreateBuilder(args);...

Anyone use Neovim and has it working for dotnet?

I cannot get some things working such as razor .cshtml working and all solutions are quite old. Is it possible to easily get this working or is it worth for dotnet using an ide like jetbrains... (macos)...

Update MAUI to net9.0 issue

I just updated our Blazor MAUI app from net8.0 to net9.0 and totally stuck on this error: error NU1102: Unable to find package Microsoft.NETCore.App.Runtime.Mono.win-x64 with version (= 9.0.0) error NU1102: - Found 102 version(s) in nuget.org [ Nearest version: 9.0.0-preview.7.24405.7 ] Anyone has any tips on how to resolve it? I cant find that we are even using that library somewhere...

Collections

Hi, I'm currently studying programming and I need help in C#. I don't really understand how to use lists and dictionary and when to pick which. Could somebody give me a bare bones explanation with an example of how to use it properly. Thanks in advance.

EF 9

Hi, I am learning C#, EF, gRPC with a small project (A Blog). I am using SQLServer as DB. I have a problem with EF, I want to validate that the user id sent to me really exists so I can't create a post with an id of a user that doesn't exist....
No description

How to implement RateLimiting in a dotnet application that is built using .net461 framework version?

I am currently working on a project which is using .net461 framework version. I need to implement RateLimiting in the application. Are there any built in tools or libraries that I can use for this purpose or Should I implement my own RateLimiter?

Any way at all to make a button click action in multiple tabs at the same time in selenium?

I tried tab switching and clicking (300 ms delay each) & clicking directly through handles & javascript executions but can't seem to do it. I am fine with somewhere between 100-150 ms delays between the each click. Thanks.

Error CS1061 PropertyStore does not contain a definition for Settings

I made a setting called Auto inject the type is bool user and false but it has this error one I use it, idk what to do, because for other win form.net projects it works, can someone please help me?

1 Error idk how fixe it

Hey I have an error in my code that I don't know how to solve if you can explain the error to me (I'm learning the C# language so the error could be really stupid)

Issue with xUnit and Integration Test

Hello everyone, I'm trying to do my first tests inside my template. I have already done Unit tests, mocking the dependencies, now I wanted to do some Integration tests to test the minimal apis flow, if they work as expected. For this test project I'm using Testcontainers.PostgreSql which allow me to use a docker container to run database, and I'm using xUnit for the tests. Said so, I'm having a small issue: I know that tests shouldn't depend one from another, but let's say I need to test those minimal apis which have all the CRUD, included the DeleteAll. I need those tests to run with a certain order, because if DeleteAll for some reason ends before the GetAll, the GetAll test will not find anything inside the database. So I need DeleteAll to run as last one. What do you think about that? What's your approach for this problem? And how can I actually implement an order in xUnit?...

Creating a level class that holds all the data for the game, should the data be private?

Hello, I am currently questioning the idea of encapsulating the level class of my project. What I am thinking is that, the level class will store data for all other classes and methods to use so, it make sense to make the data as assecible as possible by making it public so any other class or method can just access it and modify it by using something like level.data1, level.data2 and so on. Am I thinking wrong about this? Is really the best decision to encapsulate the whole class and create endless getters and setters and other operations, seems like its just going to bloat the code up and make things less readable...