Questions

.NET core 3: Order of serialization for JsonPropertyName (System.Text.Json.Serialization)

While migrating to .NET Core 3 I've switched from Newtonsoft.Json serialization to System.Text.Json.Serialization. Of all the features I want to continue using JsonPropertyName attribute. Newtonsoft...

Unable to track an entity of type because primary key property 'id' is null

After I upgraded to Asp.Net Core 3.0 I am getting the following error for my Identity class when attempting to create a user: > Unable to track an entity 'User' of type because primary key property ...

Does Servicestack.Redis support cluster enabled redis?

Can anybody give the information whether ServiceStack.Redis support cluster enabled redis or not? Thanks in advance

How to avoid "CUDA out of memory" in PyTorch

I think it's a pretty common message for PyTorch users with low GPU memory: ``` RuntimeError: CUDA out of memory. Tried to allocate MiB (GPU ; GiB total capacity; GiB already allocated; MiB free; ...

How to change activity of a discord.py bot?

I want to change the bot status from playing to watching. I've tried this but it's still playing status: ``` import discord from discord.ext.commands import Bot from discord.ext import commands import...

16 Jun at 01:43

React Typescript - Argument of type is not assignable to parameter of type

I have a demo [here](https://stackblitz.com/edit/react-ts-xoktyd?file=Form.tsx) It's a React app using Typescript and hooks to capture entries into form that are simple displayed below. Here in Stac...

1 Dec at 13:29

How to Watch Props Change with Vue Composition API / Vue 3?

While [Vue Composition API RFC Reference site](https://vue-composition-api-rfc.netlify.com/api.html#watch) has many advanced use scenarios with the `watch` module, there is no examples on ? Neither is...

Servicestack converting timezone from UTC to any timezone

I have read you don't have support for this. But I want to make sure I am not missing something. We have several cases where we need to convert the saved UTC dates into other timezones. During a quer...

Process terminated. Couldn't find a valid ICU package installed on the system in Asp.Net Core 3 - ubuntu

I am trying to run a Asp.Net Core 3 application in Ubuntu 19.10 thru terminal using `dotnet run` command but it does not seem to work. I get this error. > ``` Process terminated. Couldn't find a valid...

9 Mar at 14:9

How to get a Shared Access Signature on a Blob using the latest Azure SDK .NET API v12?

I used to be able to create a shared access signature on a Blob using the v11 Azure SDK API, like this: ``` var containerName = "mycontainer"; var blobName = "myblob"; CloudStorageAccount storageAcc...

Nullable reference type in C#8 when using DTO classes with an ORM

I activated this feature in a project having data transfer object (DTO) classes, as given below: ``` public class Connection { public string ServiceUrl { get; set; } public string...

Solutions to communicate with spring boot sseemitter from wpf client

I have one wpf application and a spring boot application, and want to use server sent events to notify the wpf application when something occurs. I googled "c# sse client" or ".net sse client" and so...

System.Text.Json: Deserialize JSON with automatic casting

Using .Net Core 3's new System.Text.Json JsonSerializer, how do you automatically cast types (e.g. int to string and string to int)? For example, this throws an exception because `id` in JSON is numer...

ASP.NET MVC Core API Serialize Enums to String

How to serialize Enum fields to String instead of an Int in ASP.NET MVC Core 3.0? I'm not able to do it the old way. ``` services.AddMvc().AddJsonOptions(opts => { opts.JsonSerializerOptions.Con...

Simulating CancellationToken.IsCancellationRequested when unit testing

I would like to test a task that is supposed to run continuously until killed. Suppose the following method is being tested: ``` public class Worker { public async Task Run(CancellationToken cancel...

JsonOutputFormatter in ASP.NET Core 3.0

In asp.net core 2.2 I used to have the following, ``` var jsonSettings = new JsonSerializerSettings { ContractResolver = new SubstituteNullWithEmptyStringContractResolver() }; services.AddMv...

28 Nov at 05:36

Call method x times using linq

I would like to call one method 3 times Using **LINQ**, the method returns an object, with that object I want to add it into a List, How do i do it? ```csharp List lstNews = new List(); lstNews.Add(Co...

6 May at 10:34

How to catch all variants of a generic exception in C#

I would like to catch all variants of a generic exception class and I was wondering if there is a way to do it without multiple catch blocks. For example say I have an exception class: ``` public cla...

27 Nov at 16:40

ServiceStack - How to Deserialize DateTime which could be in multiple formats per each request without overriding global defaults

I have some global defaults ``` JsConfig.DateHandler = DateHandler.ISO8601; JsConfig.AlwaysUseUtc = true; JsConfig.AssumeUtc = true; ``` I am reading CsvFiles which have date fields that are in mul...

28 Nov at 10:29

How do you mock an IAsyncEnumerable?

I want to unit test a method that calls another method of a service returning an `IAsyncEnumerable<T>`. I have created a a mock of my service `Mock<MyService>` and I want to setUp this mock but I don'...

What is the correct way to use linq type methods with IAsyncEnumerable?

There does not seem to be any included linq support for IAsyncEnumerable packaged with .NET Core. What is the correct way to be able to do simple things such as ToList and Count?

27 Nov at 05:47

System.Text.Json: How do I specify a custom name for an enum value?

Using the serializer capabilities in .NET Core, how can I specify a custom value for an enum value, similar to `JsonPropertyName`? For example: ``` public enum Example { Trick, Treat, [JsonP...

Should this unsafe code work also in .NET Core 3?

I'm refactoring my libraries to use `Span<T>` for avoiding heap allocations if possible but as I target also older frameworks I'm implementing some general fallback solutions as well. But now I found ...

26 Nov at 13:48

C# Fire and Forget Task and discard

I need to do a fire and forget call to some async method. I realised VS is suggesting that I can set the call to a _discard and the IDE warning goes away. But I'm not sure if that call is still not aw...

HttpContext.RequestServices.GetService<T>() vs services.AddScope<T>()?

In the following code (from [https://github.com/JasonGT/NorthwindTraders/blob/master/Src/WebUI/Controllers/BaseController.cs](https://github.com/JasonGT/NorthwindTraders/blob/master/Src/WebUI/Controll...