C#

C

C#

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

Join

Generic converter bounding in EF Core

Is there an way to "easily" define converters for all properties which uses an generic type? Currently, I have something like this: ```cs protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) {...

.net does work with Android Studio on Mac M3

Hi! Both Android Studio and .net (via terminal) individually work on my Mac (M3 Air 24GB OSX 15). However, now I want to compile a Android GitHub project, that is based on the .net SDK and every time I try to build it, it throws out a generic "process command dotnet returns non 0 value "1"" error, or something like that I previously build it on my Windows PC already and I got that error there as well, because the project requires v9 and I only had v8 and after updating, the error disappeared. On my Mac however, I am stuck at this error. Any idea?...

Not found 404 at await fetch

I have been developing a simple ASP.NetCore web app. Now my task is to load backend data onto frontend which I struggle a lot I keep getting 404 errors on my Chrome devtool once the dotnet run is hit and a browser opens All the relevant codes right here https://pastebin.com/R8dCFJgC You can view my explorer tree per screenshot in the attachment...
No description

I can't find the problem with this bot

Hello everyone, These are code snippets from a bot that runs inside a trading platform called ctrader to modify trading positions, but the modify position shortcut (which is a signature method shortcut inside of ctrader API) is not working, please clarify the problem to be, Thanks. I attached all the code that I figured will be related to the problem, Iam new to coding so might have missed somethings ...

Hello i have a question i am trying to display this text on my game but it doesnt work can anyone h

Hello i have a question i am trying to display this text on my game but it doesnt work can anyone help me?
No description

✅ XF -> MAUI (Shell) - Trying to translate this weird navigation model 😵💫

Hey! So I'm currently trying to migrate my org's Xamarin.Forms app to MAUI (with Shell navigation) so that we don't get kicked by Apple over it. I'm finding myself using quite a lot of Syncfusion with this project! In the existing app, it used what I think is a rather convoluted system for navigating field service appointments (see diagram 1) Any ideas on how I can use this with Shell navigation? Or should I just give up on the whole rewriting to use Shell thing and try to copy over the existing structure from the old App? Biggest thing that's thrown me off is the warning on the Docs that FlyoutPage (the successor to the MasterDetailPage type that it's currently using) isn't compatible with Shell and that an exception will be thrown if you try to use it (https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/flyoutpage?view=net-maui-8.0#:~:text=property%20changes%20value.-,Warning,-FlyoutPage%20is%20incompatible). I've got access to a full Syncfusion license so I'm debating whether I could maybe make it work with a TabbedPage or maybe a BackdropControl views with their own view models, inheriting a shared BaseAppointmentViewModel with the actual appointment object? I'm still fairly new to C# (and MAUI in particular), I only finished my apprenticeship 6 months ago and already have this entire rewrite on my plate :laughCry: Aware that I've probably not explained it very well, unfortunately I can't do much in the way of code sharing to demonstrate what I'm trying to convey as it's company IP and so I need to tread very carefully with discussing in public. Thanks in advance for any help, I'm really struggling to get my head around this! 😅...
Diagram 1 - Existing sub-nav hierarchy architecture

App.xaml

Hi guys, I'm fairly new to C# & WPF, but I'm trying to make some basic macro scripts, but I'm running into a problem and I can't seem to figure out whats the problem. I keep getting the error that my 'class' property not exist in the XML namespace, but it's cleary there. What am I missing?...
No description

(MONOGAME )How to pass a method with parameters to the update method

i have 3 classes. player,map and game 1 i have a rectangle for my player and the plattfroms that are generated by a textfile. I made a method for them and tried passing it to the update method but it wont accept it since it got paramteres. How do i fix it?
No description

Returning Service result to Controller (Minimal API)

```csharp /// <summary> /// Deletes a reservation by its ID. /// </summary> /// <param name="reservationId">ID of the reservation to delete.</param>...

Remove-Migration and Add Migration not correctly working how i expected

When I remove the latest Migration and then add later a migration then changes from previus migrations is also added in the new migration altough i just deleted the latest migration. This is a behaviour which i want to avoid, what can i do to avoid such side effects?...

Building Constructors 101

Not to familiar with C# personally but I'm using it with Unity for a project-based class I'm taking. I'm trying to build a state machine, where there's the BaseState interface and StateMachine class. In my StateMachine class I have a constructor that takes a BaseState defaultState parameter. I want it to be able to take classes that implement/inherit from the BaseState interface like IdleState or PatrolState, but I really don't have a clue how to do that.

✅ Ef Core unexpected query behaviour

```cs var memberships = await db.OrganizationMembers.AsTracking() .Include(om => om.Organization) .Where(om => om.UserId == user.Id && om.InvitationStatus == InvitationStatus.Approved && om.Role > MemberRole.None)...

Dictionary vs switch in source generated code

I have doubt. Im generating a compiled communication framework and the "endpoint handler" is a dictionary is int64 key-based with actions processing the context. keyvalue pairs are generated with my source generator. My question is. if I generate the equivalent switch to handle like 150 cases in compile time. would be inefficient?...

✅ File.WriteAllBytesAsync fails to download to bin folder with no error

This is the code I have currently ```csharp RestRequest request = new($"/d/{id}", Method.Get); byte[]? response = await client.DownloadDataAsync(request); //location is Path.Combine(Environment.CurrentDirectory, "Queue");...

✅ How to speed up execution of BigInteger.Pow?

I have this: var result = BigInteger.Pow(1000, 10000000); I know this is a big number but generation of this number takes too much time. Is it possible to speed up?...

going into c#

so i realised that im not the best at frontend and even though im a beginner and am not the best programmer? i really enjoy and have a passion for c#, i guess what im getting at is, what should i do? where can i learn the ins and outs of c sharp and can i build a career off of it? im still in school if that gives any idea to how free i am during the week

"Building a C# Interface to Display Real-Time Data on macOS"

I need to build an interface using C# on a macOS laptop with an Apple Silicon chip. The goal is to create an interface that takes data and displays it, but I’m unsure how or where to begin. My background is in Java, but I now need to handle this project in C#. I’ve heard that .NET isn’t very well optimized for macOS, so I would really appreciate any guidance or suggestions on the best approach to move forward with this.