Error with AppSelfHostBase with .NET 5

I have an existing project, still referencing ServiceStack.Kestrel.Core v5.8.0, and Microsoft.AspNetCore.Server.Kestrel.Core v2.1.2, after installing .NET 5 I am getting the following Loader Exception when trrying to start an AppSelfHostBase:

Could not load type ‘Microsoft.Extensions.Primitives.InplaceStringBuilder’ from assembly 'Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

I have tried uninstalling .NET 5 SDK but this issue remains, the application can continue to run if you ignore this error, but it is not able to return a Http Response, and so it looks like the application runs but all responses are invalid HTTP, and nothing can parse them.

Please could you look into this? Apart from moving to another dev environment I’m stuck here.

ServiceStack.AppSelfHostBase.Start

loader

Calling into the application works, ok, but on returning the following response is returned:

[Fiddler] Response Header parsing failed.
Response Data:

38 37 0D 0A 7B 22 72 65 73 70 6F 6E 73 65 53 74 61 74 75 73 22 3A 7B 22 87…{“responseStatus”:{"
65 72 72 6F 72 43 6F 64 65 22 3A 22 4E 75 6C 6C 52 65 66 65 72 65 6E 63 errorCode":“NullReferenc
65 45 78 63 65 70 74 69 6F 6E 22 2C 22 6D 65 73 73 61 67 65 22 3A 22 4F eException”,“message”:“O
62 6A 65 63 74 20 72 65 66 65 72 65 6E 63 65 20 6E 6F 74 20 73 65 74 20 bject reference not set
74 6F 20 61 6E 20 69 6E 73 74 61 6E 63 65 20 6F 66 20 61 6E 20 6F 62 6A to an instance of an obj
65 63 74 2E 22 2C 22 65 72 72 6F 72 73 22 3A 5B 5D 7D 7D 0D 0A 30 0D 0A ect.”,“errors”:[]}}…0…
0D 0A …

If this worked before installing .NET 5.0 I’d recommend pinning and running it against your previous .NET Core version by adding a global.json in the root directory of your solution.

You can find out the currently installed versions with:

$ dotnet --list-sdks

Grab the latest 3.x version and add it to a plain text global.json file, e.g:

global.json

{
  "sdk": {
    "version": "3.1.401"
  }
}

The next time the App is run it will use the previous .NET Core 3.x runtime.

If you want to upgrade to .NET 5.0 make sure you’re using the latest ServiceStack v5.10.2 release then I’d perform a clean restore and build by removing the bin/ and obj/ folders of all projects.

If it’s still an issue can you put together a small stand-alone repro on GitHub and post the link here.

This fixed the issue for us:

Use
<Project Sdk="Microsoft.NET.Sdk.Web">

Instead of:
<Project Sdk="Microsoft.NET.Sdk">

2 Likes