Is constructor the only way to initialize non-nullable properties in a class in C#?

I have switched to enable nullable in my project that uses C#8. Now I have the following class: ``` public class Request { public string Type { get; set; } public string Username { get; set; ...

How to set consent cookie in Blazor Server

I have a Blazor 3.1 App with Identity where I want to implement a cookie consent banner. In classic ASP .NET Core, there is a nice template for a cookie consent banner. ``` @using Microsoft.AspNetC...

Using System.Transaction how to update multiple rows in Entity Framework

I want to use `System.Transactions` and update multiple rows. My database is connected using Entity Framework. Below is the code I tried but it throws an error : ``` public void Update(List<Portfo...

Why do we get possible dereference null reference warning, when null reference does not seem to be possible?

Having read [this question](https://stackoverflow.com/q/59518973/284111) on HNQ, I went on to read about [Nullable Reference Types in C# 8](https://learn.microsoft.com/en-us/dotnet/csharp/nullable-ref...

Square brackets in the controller Route in ASP.NET Core

What do the square brackets in the controller in ASP.NET Core mean? E.g. the here: ``` [ApiController] [Route("[controller]")] public class WeatherForecastController : ControllerBase {...

29 Dec at 22:5

What is the ?[]? syntax in C#?

While I was studying the which actually an abstract class in [Delegate.cs](https://github.com/dotnet/corert/blob/master/src/System.Private.CoreLib/shared/System/Delegate.cs), I saw the following met...

IApplicationBuilder does not contain a definition for UseIdentity

I'm following an example to configure AspNet Core Identity on Here's the code for StartUp.cs file ``` using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetC...

UserSecrets not working with ModularStartup

I am using 5.7.1 and when I use modular startup UserSecrets are not added to the IConfiguration collection. This works: ``` public static IWebHost BuildWebHost(string[] args) => WebHost.Crea...

29 Dec at 04:30

Converting Hangfire into modular startup

I am converting my startup code into new [ServiceStack Modular Startup](https://docs.servicestack.net/modular-startup) approach and have hit a snag. I have this code in old startup ``` public void C...

29 Dec at 03:17

Is using the system.text.json no longer possible for serializing / deserialiing in c#

As described in the official microsoft docs which has been Updated in September of 2019 it says that using `system.text.json` for serializing or deserializing can be done. [https://learn.microsoft.co...

27 Dec at 16:21

How do I (gracefully) shut down a worker service from within itself?

I'm using the .NET Core 3.1 worker service template to build a Windows Service. I gather that the basic flow should be handled within `ExecuteAsync`, roughly like so: ``` protected override async Ta...

27 Dec at 13:0

Redis keyspace notifications with StackExchange.Redis For Delete operation

I've been searching to find out how to perform a subscription to key space notifications on Redis using ServiceStack.Redis library for removal of Key. Checking available tests on the git-hub and othe...

30 Dec at 06:45

Entity Framework Core 3.1 with NetTopologySuite.Geometries.Point: SqlException: The supplied value is not a valid instance of data type geography

I have a model that looks like this: ``` public class Facility { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public NetTopologySuite.Geome...

How to inject or use IConfiguration in Azure Function V3 with Dependency Injection when configuring a service

Normally in a .NET Core project I would create a 'boostrap' class to configure my service along with the DI registration commands. This is usually an extension method of `IServiceCollection` where I c...

How to use 404 routing in Razor Page OnInitialized event

In a server-side Blazor application (Core 3.1) have a Razor that accepts an identifier in the `@page` attribute. If the identifier supplied in the URL corresponds to an existing entity, the page will...

Docker System has not been booted with systemd as init system

I have an Ubuntu 18.04 image runing on my docker container. I login into it and installed `Openresty`. also installed `systemd`. When I use command `systemctl` I get this error: ``` System has not bee...

17 Feb at 10:56

Could not load type 'Microsoft.AspNetCore.Http.Internal.BufferingHelper' from assembly 'Microsoft.AspNetCore.Http, Version=3.1.0.0

I am trying to upgrade my API project from .net core 2.2 to .net core 3.1. I get this exception while I try to make the API call. > "Message":"Could not load type 'Microsoft.AspNetCore.Http.Internal...

24 Dec at 09:8

Servicestack AutoQuery not filtering results

my query /API/Json/GetJson?Desc=test1 I get all records not just the test1 records ``` [Route("/API/Json/GetJson", "GET")] public class GetJson : QueryDb<JsonModel> { public int? Id { get; set; ...

24 Dec at 19:50

Using Polly for a retry attempt from an async function

I'm trying to retry a failed operation 3 times. I'm using Polly for a retry operation. I want to get the exception in case the retry operation fails and retry again 2 times and so on. ``` return await...

16 Apr at 13:19

How to Rename Files and Folder in .rar .7z, .tar, .zip using C#

I have a compressed file .rar .7z, .tar and .zip and I want to rename physical file name available in above compressed archived using C#. I have tried this using a sharpcompress library but I can't f...

23 Dec at 07:2

How can I parse JSON with comments using System.Text.Json?

I have some JSON that includes comments (even though comments aren't strictly allowed in the [JSON spec](https://www.json.org/json-en.html).) How can I parse this JSON using `System.Text.Json`? The ...

22 Dec at 22:18

Select Control Set Initial Value

We know that with `InputSelect` we cannot use both @bind-value and @onchange... But if we use the latter (with `select` instead `InputSelect`), how can we set a initial value different from the fir...

2 May at 11:1

Create empty IAsyncEnumerable

I have an interface which is written like this: ``` public interface IItemRetriever { public IAsyncEnumerable<string> GetItemsAsync(); } ``` I want to write an empty implementation that returns...

23 Dec at 06:20

ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly

I get an error when pip builds wheels for the cryptography package. Error: [](https://i.stack.imgur.com/2F20z.png) ``` LINK : fatal error LNK1181: cannot open input file 'libssl.lib' error: comma...

ServiceStack Http Utils Set Cookie

I am trying to use ServiceStacks Http Utils, but for some reason I can't seem to be able to set the JSession cookie I received from logging in via basic auth. This is what I've tried so far... respo...

22 Dec at 00:3