C#

C

C#

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

Join

✅ Desktop app not opening

Hi, i was working on my app, nothing wrong and all of a sudden it has an error, its okay i just deleted a function that was in the Form Designer "auto-generated" code region, so ir emoved that and it usually works but it crashed and i can't open my project anymore, i can still open the files individually tho on the file explorer
No description

✅ What's the difference between "Write" and "WriteLine" in C#

i honestly dont get it, it looks the same, it acts the same. Whats the difference?

System.IO.DirectoryNotFoundException: {directory}\wwwroot\

``Building... Unhandled exception. System.IO.DirectoryNotFoundException: {**My directory**}\wwwroot\ at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters) at Microsoft.AspNetCore.Hosting.StaticWebAssets.StaticWebAssetsLoader.<>c.<UseStaticWebAssetsCore>b__1_0(String contentRoot) at Microsoft.AspNetCore.StaticWebAssets.ManifestStaticWebAssetFileProvider..ctor(StaticWebAssetManifest manifest, Func2 fileProviderFactory)...
No description

How to catch implicit conversion using SyntaxWalker and SemanticModel?

I'm traversing syntax tree and need a way to catch implicit conversion. SyntaxWalker doesn't have such virtual method and SyntaxTree itself doesn't have any info about implicit conversions. What should I do?
No description

✅ Tic tac toe

im trying to implement tic tac toe with DFS and im struggling to get it to work properly
No description

Is having two DbContext on same base antipattern or bad approach?

In company (so there is no much freedom to do with other tools I need to solve this using EF Core), we are using CQRS with MediatR, and every command handler is wrapped in a transaction. So if something fails, we roll back the transaction. Here’s the issue: I need to save certain data even if an exception occurs. The main data should be rolled back, but part of the data needs to be saved in the database. I know I can use two separate DB contexts to solve this issue, but is this a good approach?...

✅ Better way to set a property using linq?

I have this on a blazor component:
ValueChanged=@( async text => {
protocol.maxIterations = text;
await OnProtocolChanged(protocol);
})
ValueChanged=@( async text => {
protocol.maxIterations = text;
await OnProtocolChanged(protocol);
})
...

✅ When should you or shouldnt you return nested data in an api call?

Let's say I have a these tables in my database, Project, Members, Task, Comments and I want to return paginated data so a user can view all their projects, then view the tasks and members associated with the project and the comments associated with the individual tasks. Would you do this as all separate queries or do one query that returns all the data nested and paginated? Here's my current thought process. ``` - Load all Projects paginated - One api call only project data...

Google Api to C#

Hey I'm trying to connect Places Api to do auto completion on addresses. This is being made on a C# software, I already have the nuget package installed. The error: Error creating Credential from JSON or JSON parameters I'm using the downloaded json key from Google console....

code builds but hangs while running

code: https://paste.pythondiscord.com/KTVQ when i build it in release, everything works fine. but when i run in release, it just hangs and does nothing, even though all i'm doing is this: ```cs class Program {...

✅ How to save to database with ISO format?

Hello, I'd like to save datetime with timezone to database. I use NodaTime for this. Let's look into my code: BaseEntity: ```cs public class Entity...
No description

Converting a string to a list of objects using only LINQ.

I want to convert my string with a shopping list in it to a list of ShoppingList objects (it contains a bool IsBought and a string Content) using only LINQ. How could I do that?

How to host small static website

Hey guys, the website has no database and the users cannot change it's contents in any way(I believe that's what a static website means). It won't be getting much traffic as the users are around 100, I would expect a couple visits per day at most. What is the easiest way to host it, I am willing to pay for it, but would prefer a free hosting service :)

✅ How to clean up a stream of incomplete JSON data?

I'm working on adding some discord capabilities to a bot I'm working on but the data I get is really messy? I seem to just get a constant stream of data but I don't see any actual identifier of when a message ends? So I was wondering if there is any way that I could possibly keep adding a buffer to a StringBuilder and then try and extract the first json object, add it to a Channel and then remove it from the StringBuilder and keep looping it? This is 2 bits that I was working on so far.. I've cut out a lot of stuff that didn't work...
No description

✅ I keep getting the "build failed" prompt.

Not sure why this is but from my end all the files are correct and they worked before. But now I can't run any of the files when I debug.
No description

Does Polly WaitAndRetryAsync() swallow exceptions during retries?

Does Polly "swallow" the exceptions during each retry attempt?

✅ Implementing IAsyncLifeTime difference

When I implement the interface, the following happens as you can see in the picture. Why does the dispose not get set to public and have the extra IAsyncLifeTime.DisposeAsync ? I do not have any other DisposeAsync in my class?...
No description

Does not dash

Hello I have a player script, and I am trying to make a dash ability, but when I press the button nothing happens. I put a debug to see if it printed something and it did, but it doesn't accelerate my player or o anything, I also set variables in the inspector...
No description

✅ Integration testing

I just watched this video, and instead of seeding his database he is using a Faker class which generates the data. How does this work? Within he is using a CustomerRequest is this basically his DTO object? Before watching his video my approach in Integration Tests was: Seed Database...
No description

error when trying to run aot compilation with my package

i get this error when i try to compile a project which has my package added what can i do in my package to make it compile?...
No description