C#

C

C#

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

Join

Cant debug or see tests when using vscode in wsl with docker and xunit

Ok so Im working on windows a friend in linux. It works fine for him but for me noup. Im using wsl cuz of docker and vscode. It is an asp.net app. Db is postgres. Im trying to write integration tests to test the controllers etc using Xunit, CS-Script. .net.8 I dont see any tests in the test explorer nor do the tests hit any breakpoints when executed from the console. ...

Entity Framework Tracking not making changes to db

hoping someone can explain what im doing wrong i have a method that fetches all entities that i need into a list<entity> this data is then returned to a variable in my business logic layer...

Issues with wpf binding

Hey guys, i'm having some issues with bindining a number Score to a Label in wpf, here's my code: ```cs public partial class MainWindow : Window { public static int Score { get; set; } = 10;...

✅ How does server fetch information from the correct user?

Title says it all. i have a asp.net and have implemented all the api endpoints and all that. and up to this point i have just gave the users their ID in the DB and they required to give that ID back to get the information they want. but now im thinking this is not very secure way of doing it. i have set up authorization and whenever a user wants to fetch a user specific info then i check the given token to the token that is stored in the user info. if it matches then i'd return the requested stuff. ...

Transitive compile assets in nuget

Hi everyone! I'm banging my head against this issue I can't figure out. I have to (nuget) package a bunch of native libraries alongside a dotnet wrapper. I've set it up according to the docs (https://learn.microsoft.com/en-us/nuget/create-packages/native-files-in-net-packages) the following way MyNative.Package +-- runtimes...

Flyout Disappears on Window Resize: What Could Be Wrong?

My toggle button is working correctly for the sidebar I designed with a flyout. My goal is to toggle between a view where only the icons are visible and a full view. However, if the window is resized, the flyout completely disappears. What could be causing this? Am I missing something while configuring the flyout? ```c# ...

How to Correctly Reference a Method in App.xaml.cs

Hey, reviewer. The ChangeLanguage method should work, but referencing is a challenge at the moment, since I get the error 'App' does not contain a definition for 'ChangeLanguage' and no accessible extension method 'ChangeLanguage' accepting a first argument of type 'App' could be found (are you missing a using directive or an assembly reference?). The OnLanguageChanged method works until I add that reference for ((App)Application.Current).... How do I correctly reference to a method in App.xaml.cs?...

Stylesheets

<link rel="stylesheet" href="~/ProjectName.style.css" asp-append-version="true" /> Hello, there, can someone please explain me what this link is refering to. I used search across my whole project and there is no file with such name. I even checked for hiden files. Also when I launch an app and inspect a page on Chrome it will show me that this file was loaded and will show its contents(some css obv). It comes by default with MVC template in _Layout.cshtml file...

Cannot access a disposed context instance.

I'm receiving the ObjectDisposedException about a DbContext being disposed while using IDbContextFactory<> to initialize my database context. After searching online for potential ways for me to approach resolving this, none of them seem to apply for my case. Code: ```cs logger.LogInformation("{Availability} Guild {Name} has just been created.", $"{(gatewayEvent.Guild.IsT0 ? "A" : "Una")}vailable", gatewayEvent.Guild.IsT0 ? gatewayEvent.Guild.AsT0.Name : gatewayEvent.Guild.AsT1.ID.ToString());...

I need help, I don't know what to do.

I am new to game development. Every time I try to add this code to my player, I get the following error message: "Can't add script behaviour 'MouseMovement'. The script needs to derive from MonoBehaviour!" Can someone explain what I need to do?...
No description

Need Help with a Minimal API

I am creating a simple API that takes in the values for a new microservice and stores them in a database --- eventually consumers will read the database entry and create the underlying infrastructure. There will be 3 types of services, APIs, Cron Job and Consumers. APIs and Cron Jobs will have all of the same information, but consumers need additional information related to their infrastructure needs, so I created a separate model for the consumer that still inherits the base service model. My questions:...

✅ Proper way of using EF DbContext in a BackgroundService

Hello, The dbContext and the BackgroundService have different scopes. I've seen there are 2 solutions. The possible options are: injecting the IServiceProvider, or the IServiceScopeFactory, then manually creating a context. Which one of the interfaces is better to use? There surely must be some difference......

Project which programatically calls MSBuild does not properly configure NuGetSdkResolver path

I'm writing a hosting library and want to expose solution building to native code -- so I'm using Microsoft.Build.* stuff from native land. The actual dispatch appears to work fine but it fails with
Could not load SDK Resolver. A manifest file exists, but the path to the SDK Resolver DLL file could not be found. Manifest file path '.\Build\Debug\SdkResolvers\Microsoft.Build.NuGetSdkResolver\Microsoft.Build.NuGetSdkResolver.xml'. SDK resolver path: .\Build\Debug\Microsoft.Build.NuGetSdkResolver.dll .\Example\Example.Managed\Example.Managed.csproj(0, 0)
Could not load SDK Resolver. A manifest file exists, but the path to the SDK Resolver DLL file could not be found. Manifest file path '.\Build\Debug\SdkResolvers\Microsoft.Build.NuGetSdkResolver\Microsoft.Build.NuGetSdkResolver.xml'. SDK resolver path: .\Build\Debug\Microsoft.Build.NuGetSdkResolver.dll .\Example\Example.Managed\Example.Managed.csproj(0, 0)
...

async/await and parallelism

the problem that spawned this question is that i get a "collection was modified" exception and i don't know why that is the code is a client for a device, the _message linked list is being accessed in three ways: from a heartbeat loop, from the i/o eventhandler, and from the public methods of the commands -- after an await (also _messages is never enumerated with a for/foreach) so i understand that asynchronous model has following properties: - multithreading: yes, easily verifiable (thread pool, background threads, and all that)...

✅ How do you log and trace requests in big production applications?

I've recently realized that I don't really know how to log data (other then writing it to a file or console). I've also heard you can trace back a request using logging (or smth). I want to make a small project that would use "better" logging, yet I dont know where to start, what technologies to use, how it works, etc. Pls give me any info/hits/tips on what you use in production

✅ System.Threading.Channels - Consumer is blocking the main thread where the producer is

Hello, The producer writes to the channel with WriteAsync(), but the consumer blocks the termination of the producer. The outcome should be a non-blocking read, so the producer would complete in the meantime. The following is the consumer:...

How do I write integration tests

Here is my scenario: User interacts with UI (Avalonia) -> user inputs information, lets say its checkboxes in a checklist -> user clicks I.E submit button -> command on view model takes all the data the user inputted on the UI and sends it to an api parsing service -> api parsing service formats all the data into the expected API objects and sends it to the writing service -> writing service sends it off to the api. What I want to automatically validate is that the API response in every command is successful. Our services are broken out into interfaces like IApiParsingClient, IApiWriteClient, and I don't have an issue hard coding test data somewhere to do this. I need to learn how and where to start...

✅ Looking for a Windows Desktop Software Developer

Hello everyone, I am looking for a partner of sorts. I am looking for someone to not only share project ideas with, but to learn with and grow with as a Windows Desktop software developer. I currently develop Windows Desktop software applications using Visual Studio 2022 Community and C# with the .Net 8.0 Framework, but any version of the .Net framework is fine with me. I am hoping to connect with any likeminded individual that is interested in learning and growing, not only in C# software development, but Desktop software development of any kind (preferrably C++, C#, VB.Net, Python, or Java). I have been learning C# Desktop Development off and on since 2013, and continue to grow and learn more each time I begin working on a project. If you are interested in being a buddy that is interested in growing in the Desktop software development field for Windows, then please shoot me a DM!...

✅ need coders

i need someone who can make mods for a game

I can't afford to sign my app

Hello. I have been developing an app made for the Windows platform for a few months. I plan to release it soon, but I can't afford even close to the amount of money that signing certs cost. Is there ANY other way? I really don't want to ship an unsigned app since many of the features I need require it to be signed. ...
Next