This error popped up randomly for me when I created a new ASP.NET with our standard framework.
Why this happens, even though this project is 100% identical to our other ASP.NET web projects is not quite clear; the SDK for ASP.NET is 2.1 and all packages are pinned to specific versions for our framework. However, Kestrel will pop an error saying it cannot load CompilerServices.Unsafe because it does not match the assembly reference.
One workaround, which is not very nice, is to remove the conflicting reference from *.deps.json in our bin directory; of course we are not supposed to touch that file, but studying it can give insight which package tries to load the wrong version.
A better approach is to just pin the version you require:
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.1" ExcludeAssets="all" />
This seems to be caused by an issue with the Manifest file from a particular version of ASP.NET in a particular .NET Core install (2.1.503 in my case); it somehow sets the version of the assembly to 18.104.22.168 while it means to use 4.5.1.