C#

C

C#

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

Join

Is writing tests like this worth it

Im using the implementations and sqlite in memory to test that the services do what they are supposed to - i guess they fall into integrations test or unit tests but i want your lots opinion https://github.com/UmbrellaCrow612/PoliceCaseManagement/blob/master/tests/Identity.Application.Tests/AuthServiceTests.cs

Update Policy for Cache of API Results

I'm busy building an MCP for my (for now just mine) Postman collections, and using the Postman API for things like fetching a list of collections, or a particular collection. This API isn't much good for analysis of any kind, even simple searches, so I'm going to cache the results in a local db that I can hopefully execute json queries on. What strategy can I use to determine when I must update the cache db? It's going to be rare that someone would use Claude just to find one collection or request, so using it not being in the cache as a trigger isn't the most sound policy. Maybe an update on every startup of the MCP, or on every n queries to it, or what?...

So this big project idea I have

I've been told the best way to learn is to do, so I'm going to put my money where my mouth is and start working on an application that helps create a character for the TTPRG Cyberpunk Red, in the same way that D&D beyond does. However I'm not quite sure where to start, I mean I know that I need to make a BUNCH of different stuff in visual studio for this but I don't know if that would be in a consoleapp, or something else, or if this would be better in python, I just want to make something that people can use and something I can put on my resume and stuff with pride. Any advice is welcome!...

Loop invariant

Hi, I'm a computer science student and i'm trying to understand loop invariant. I just know that is a proof of correctness for an algorithm and it is very similar to mathematical induction. Maybe an example will help me to understand or maybe some of you know an intuitive way to understand this subject. Thanks in advance!

✅ Update .NET (SOLVED)

How do I update .NET? I used the dotnet.microsoft.som/en-us/download/ and got the .NET 9.0, but I don't seem to be able to use it as shown in the picture.
No description

BehaviorTree Implementation

Hello! I am working on a BehaviorTree (https://en.wikipedia.org/wiki/Behavior_tree_(artificial_intelligence,_robotics_and_control)) implementation. I need the BehaviorTree to be serializable so that it can be saved and loaded, as such I am trying to figure out how to store the leaf nodes or Tasks. My initial thought was to have a public class in my namespace that just held a bunch of static methods. Each method corresponding to a Task. A leaf node would hold the string of the method name and invoke the method via the System.Reflection library.
I then thought about a second method of using OOP to create a base class of BehaviorTreeTask and then derive new classes for each type of Task, each one overriding a base PerformTask method....

✅ Why won't the loop loop?

```cs public class Game { public Task gameloop = Task.Factory.StartNew(() => {...

How to get value in big TagCompound

I`m making minecraft schematic analyzer in c#, and i need to get BlockList and BlockPalette from entity. It looks like this: ``` entity: (Compound) CanUpdate: 1...

Question about Avalonia structure, addon capability and generall seperation of projects

I want to make a small Desktop app using Avalonia, my current structure is: MyApp.sln contains: - MyApp.UI -> for UI stuff only - MyApp.Core -> for logic...

Unable to (somewhat) gracefully terminate some processes

Hey! Newbie here with very limited skills trying to learn. For context: I currently have a batch script that uses the command-line tool TASKKILL to end a bunch if processes when needed. I'm looking to implement this in my current C# app in a somewhat more "proper" way. I've been testing this by running PowerToys minimized and trying to end that process as gracefully as possible. The TASKKILL command seems to be able to end PowerToys without the use of the /F (force kill process) parameter....

✅ Brand new to C# and Unity

For some reason my else statement isnt attaching to the previous if. Im wondering if i missed something or not. I recently set up sprinting right before it, and heard you can only put one update per class, so i have to cram all my movement updates into this one area, and it looks just like a bunch of if else statements spammed everywhere.
No description

✅ How to test for memory corruption in your implementation

So I have a method Foo that does some SIMD and pointer shenanigans. Now I want to write tests for it. One thing I'd like to test is out of bounds accesses of the data I process. My thought was that I setup three contiguous pages [A B C] and apply a page guard to A and C while the entirety of B contains the test data. The idea is Foo going out of bounds is not a critical error in this test, it should simply fail the test. The problem is: in order to use page guards I have to make the page read only. However, making the page read only triggers an AccessViolationException in C# when I write to it and the process is shut down. Since [HandleProcessCorruptedStateExceptions] is no longer supported I cannot prevent the entire process from shutting down. Any idea on how I can test for out of bounds accesses without killing the entire process?...

WPF horizontal scrollbar is slow and doesn't move to click

I'm making a custom control which has a scrollviewer that can display "long" data horizontally. Think something like a video editor, or a timeline type control. I noticed two issues: 1. If the scroll area is large, I can't click/hold/drag the thumb very far. I have to keep doing it over and over and move it a little bit each time. 2. I can't click on the space between the thumb and and another part of the scrollbar to move the thumb to where the cursor is. ```xaml...

Sidebar Hover, Display Sub Items (Blazor / .css)

About the project Hey there, ive been making a versitile tool for sidebar for some work related stuff. currently its an advance resuseable sidebar with infinite nesting, and it supports eventcallback on click of an sidebarelement The issue...
No description

✅ Question about front-end frameworks

In college we mostly built front-end with vanilla JavaScript or a bit of jQuery. I want to learn a modern front-end framework that: 1.uses TypeScript (I want to learn it as well), and 2.has many ready-to-use components out of the box....

✅ C# Winfrom Chart

Is the animation feature built-in or do I have to create it myself?

Need help with MVVM

Hi guys, i need to make a NotePad, i choose to make it with Avalonia, i want to use MVVM, but i don't understand it, can someone help?

Help with Whisper.net (AI Voice detection)

I'am trying to make a substitle generator using whisper and ffmpeg. But i noticed that when nobody is talking (in the video), the subtitle shows too early... Is there a way using Whisper or anything else to fix this? Thanks. Watch the video to understand well, even if its not in english : https://streamable.com/tkzeah

400 bad request on seemingly valid POST

I'm guessing this is a really stupid thing I missed or something like that, but I'm not sure what exactly it is. I have this post handler: ```cs // added with app.MapPost("/usernew", UserPost); public static void UserPost (string email, string userName, string password)...