C#

C

C#

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

Join

✅ Can custom attributes use interfaces somehow ?

I have an interface named IConfiguration and I'm wondering is it possible to write a custom attribute so I can do [StaticConfiguration("Key"]var settings: Settings so that the StaticConfiguration attribute will get the config for that key from IConfiguration and parse it into the type Settings?

Problem with azure and winforms

So i am building inventory management sustem with winforms and two main forms for admin and user and user controls. So i have been using local sql and when i changed to azure, my main form bugged and the user controls disapeared from the main form but they are still in the designer, this is the error it gives me when i try to add them back, i tried three different ways for this connection string but its the same. If someone can help me it urgent...
No description

✅ NullReferenceException when declaring an array but not initializing it

Hello guys, say I created a new class and within that new class, I created an array. So we have something like this: ```C# class MyClass...

N1301 error : unable to find source nuget.org/index.html

I need help regarding this im using clean architecutre and it has a "workers" folder and it has its own dockerfile and projects and im trying to build that dockerfile but it stops in the middle when trying to restore and throws error N1301

How to configure services in my cli application:

``` var container = new ContainerBuilder() .WithSystemConfiguration() .WithConsoleVerbosityWriter() .WithSystemServices()...

✅ Data Binding System.Numeric.Vector3?

I have a collection of objects containing Vector3 properties. Is it possible to data bind directly to the X/Y/Z fields in my WPF xaml data grid or do I need to add pass through properties for them all? Seems like a lot of boilerplate when you have many vectors.

✅ For loops, while loops, and TryParses

I still don't understand them, nor do I know how to apply em.

✅ Why some people don’t like Automapper?

I’ve learned about this tool about a month ago, since then I’ve been constantly using it without any problems. But some people thinks that it is unnecessary, and I’m curious why. Is there any significant disadvantages to this approach for mapping?

✅ Matrix multiplication in C#

Hello guys, sorry to disturb you all; I have an exercise where I need to perform matrix multiplication using 2D arrays. I try to implement the following code: ```C# // //Matrix Multiplication public static void MultiplyMatrices(int[,] matrix1, int[,] matrix2) {...

Xml generic type deserialisation based on attribute

Hi there, I'm working on a server for a client app which sends requests in a fixed xml format, it has a root node with a method attribute and depending on the method there are different objects serialised into the root node. My question is, I want something which can deserialise to the root node object and then be casted later down the line to an object with the proper generic type. Said generic type will contain the correct xml model for the given method attribute....

Issue sending parent Id through recursive function

I have a function that goes through provided nested enumerable with varying depth. It returns element that pass the given condition. I'm having issue with child elements to have I'd of the parent. For that, I am trying to pass Id of found valid element through the preceding recursion but it's having 0 for all the elements. ```cs...

✅ How to avoid creating same CRUD Commands/Queries for different entities | MediatR, ASP.NET

Hi, right now I’m creating same CRUD Commands/Queries(e.g. GetAll or DeleteById) for each new entity in my project. How to avoid that?

✅ NopEcommerce

Hi, please help me to fix nopcommerce plugin bug in .Net. DM me.

SQL Server Table Import Issue

Hello all! I am having a weird issue. I am making a simple web form app that is connected to a SQL server database. On the CarRentalDatabase.edmx file I right click and click "Update Model from Database" and that imported all the tables that I needed. For some reason, the "User" table is not showing up in the CarRentalEntities class which is an auto generated file. The other two tables CarRentalRecords and CarTypes did show up in the CarRentalEntities class. Because of this, I cannot call "Users...
No description

Populate `EnvelopeRecipientCollection` on `Recipients` Property of a `MailItem` in Transport Agent

I've written an Exchange Transport Agent in C#, using the common assemblies from Exchange 2019 CU14 (namely: Microsoft.Exchange.Data.Common.dll and Microsoft.Exchange.Data.Transport.dll). I, at first, had issues populating the MailItem object on the EndOfDataEventArgs delegate. I discovered that I could do this via reflection and now I'm trying to test a condition that the message is quarantined. In order for the message to be quarantined, the recipients - which is a List<EnvelopeRecipient> has to be populated and passed into the ReceiveMessageEventSource.Quarantine method. The issue that I'm running into is that the Recipients property on the MailItem only has a getter and is of type EnvelopeRecipientCollection. So, I try to setup a Mock<EnvelopeRecipientCollection> and am able to feed that as the SetupGet(x => x.Recipients).Returns(...); however, because it's a mock, it's an empty collection and the test is failing because the recipient collection is empty. ...

othello game

```cs public override async Task<(int x, int y)> RequestMove(GameBoard board, List<(int x, int y)> validMoves) { /* while (the user hasn't made a valid move) ...

What is meant by "Generic" and where do we use them and why are they important

Hello guys, sorry to disturb you all; can someone explain what is meant by "generic" please; does this applies only to OOP concept? or any programming language with collections? Like I know the angular brackets is used to define a generic. But why do we need them? What would happen without generics?

✅ Groups & Clients in SignalR not taking requests.

I have 2 Hub tasks, 1. Connect 2. Send I save all connections that are being sent to connect with a game code, and store them in a group.....