Sharing DTOs between my API, Blazor web app and WPF client

I have recently been revisiting a project from a year ago where I had an ASP.NET web API and a WPF client. The WPF client would call the API and each project had a separate models folder where I dupli...

3 May at 15:59

How to handle no matches case in List.First in c#?

In [IEnumerable.First][1] function, how do I handle the case if there are no matches? Currently it just crashes... ```csharp MySPListItem firstItem = itemCollection.First(item => !item.isFolder); ...

30 Apr at 13:26

GridView Command Arguments out of sync after dynamic row inserts

I have a gridview (for displaying data only) with multiple LinkButton objects in each row. In the gridview's DataBound function, I iterate through the rows of the gridview and dynamically to add new "...

3 May at 14:34

Calling multiple external apis.

I'm creating two azure functions, and each one will call different external api. I'm wondering about approach to this. I currently have a `IApiService` and `ApiService` which basically is doing th...

3 May at 14:33

C# how to convert WORD to PDF?

I'm searching for free method to convert word to pdf. I searched for free cli tools, for libraries, but there is no free method i found. I only found this library from nuget - "Microsoft.Office.Intero...

3 May at 14:29

c# csvreader delimiter in value

How parse csv with text in? example csv: ```csv name;comment;count; firstName;LastName;someComment;5 ``` I found on the net that you need to escape the value in the column with the symbol ...

3 May at 14:15

RPC calls - state of the art

Up until recently we had a database where only a client for the classic .NET Framework was available (ODBC setup would have been a horror). My application basically is a webservice (implemented in WCF...

3 May at 14:14

Covariance in C# .NET 4 Framework

Is it possible to cast a `List` to `List` in C# 4.0? Something along these lines: ```csharp class joe : human {} List joes = GetJoes(); List humanJoes = joes; ``` Isn't this what co...

30 Apr at 12:19

Elegant alternative to int.TryParse

I feel that every time I use `TryParse` that it results in somewhat ugly code. Mainly I am using it this way: ```csharp int value; if (!int.TryParse(someStringValue, out value)) { value = 0...

30 Apr at 12:10

Blazor Server App checking checkbox on task list leaves next item checked

I have a task list that users can check off from the list, which disappears because Show Completed Tasks is not checked. However, when the task disappears, the next task item is checked, smh which is ...

10 Mar at 04:4

Access Dns from ASP.NET Core 8 Web API in Docker container

I have built an ASP.NET Core 8.0 Web API that gets the hostname of the connected client with the following code: This code worked just fine as long as I ran it in Visual Studio. Now I want to deploy m...

Deserializing JSON text to an object in C#

I have the following class: On the other hand, I have this json string: When executing: I got this error: > Exception: System.Text.Json.JsonException: The JSON value could not > be converted to System...

10 Mar at 04:15

Is there a way to store a template of interpolated string in C#?

I have this class called `BaseMessage` that contains string field `Message`: And I have another class `ProcessMessage` that derives from `BaseMessage`: Overall this class is created in 500 different p...

10 Mar at 13:7

C# Getter non nullable but setter nullable?

Is it possible to use C# accessors such as the backing field is nullable but the getter is not ? I want the getter to promise to the rest of the code the value is not null Since get; set; share the sa...

10 Mar at 04:30

How does the .net CosmosDb SDK handle tasks in bulk support?

In the [examples for using][1] the bulk support, the tasks created by the SDK are awaited as such: In a more real world scenario, there might be a lot more await/async going on. Developers often await...

Intercept a message rabbitMQClient C#

I am making an integration service for a third party application. This application uses rabbitMQ for its communication. The problem I am having is that whenever rabbit publishes a message, the first t...

10 Jan at 09:20

I need help creating mouse-centered zooming

I've been trying to make a system in my 2D unity game where you can zoom in and out by scrolling, and it should center that zoom around the cursor, like zooming in on a web browser. With the way the g...

10 Jan at 09:35

Removing Noise (Jumps and Drops) from Sensor Data for Fuel Consumption

I am working with fuel consumption data received from a sensor, but sometimes the data contains noise (sudden jumps or drops) that makes it inconsistent. My goal is to identify and remove these outlie...

C# WPF Binding issue

I got this CurrentPage property on my mainViewModel like: public int CurrentPage { get { return _currentPage; } set { if (_currentPage != value) { _currentPage = value; OnPropertyChanged(nam...

9 Jan at 09:43

Why must an internal method of a public interface be implemented via a public method?

I have a public interface. One of its methods is marked internal. And it has to be - it takes an argument that is an internal type. I write a public class that implements this interface, I do so via a...

9 Jan at 09:44

How can I pause a task in C#?

I am a beginner in the use of task in C#. I have implemented a file generation window in my application which generates 3 different files. I have implemented the file generation function on a single t...

9 Jan at 09:44

Use reflection to invoke methods in an assembly that contains a derived-class from the base-class that lives in another assembly

I have two projects/assemblies in a .NET Core solution. 1. Project A contains a base-class called `FooBase` 2. Project B contains a derived-class called `FooDerived`, as well as a bunch of other class...

1 Jan at 10:58

Why aren't the string formats for the float equivalent, and why does "N9" produce a value that is different?

I would like to understand what is going on with this code: where the value of `flt` in the debugger is `0.123`: [![enter image description here][1]][1] The documentation on [the "#" custom numeric fo...

1 Jan at 11:3

How can I execute C# code using Roslyn from a string and use global variables from a Dictionary<string, object>?

I'm working on a C# application where I need to execute C# code provided as a string input using Roslyn. The challenge is to execute this code and access global variables stored in a `Dictionary`. The...

1 Jan at 11:5

Entity Framework keeps throwing Duplicate Primary Key Error Despite Rollback

Running on .NET Framework 4.6.2, I have a method that uses Entity Framework to insert a row into a SQL Server database table. It uses a transaction that gets rolled back if an error is thrown: publi...