Description
Some ASP.NET Core 2.1 users have been affected by a bug in the .NET Core host (see https://github.com/dotnet/core-setup/issues/4512) which can cause apps to fail with System.IO.FileLoadException. The issue may also be present in your app, even if the app does not fail with System.IO.FileLoadException.
Affected versions
.NET Core, 2.1.1 through 2.1.4 (all OSes), 2.1.7 (Windows only), 2.2.1 (Windows only)
Symptom 1
ASP.NET Core apps running on the Microsoft.AspNetCore.App shared framework may fail to run after the machine-wide version of .NET Core is updated. Apps fail with an error such as:
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Identity.Core, Version=2.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Diary.Api.Startup.ConfigureServices(IServiceCollection services)
Symptom 2
When publishing an ASP.NET Core application which references Microsoft.AspNetCore.App, additional Microsoft assemblies are in the publish output.
For example, if you run dotnet publish --output PublishDir/
and you see Microsoft.Extensions.*.dll
or Microsoft.AspNetCore.*.dll
files in PublishDir/
, you may be running into this issue.
Cause
This issue is typically caused by .csproj files which have a PackageReference to a package which is already part of Microsoft.AspNetCore.App.
For example,
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.0.3" />
</ItemGroup>
The Microsoft.AspNetCore.SignalR package is already pulled in as a part of Microsoft.AspNetCore.App, so does not normally need to be referenced. The presence of this reference causes a mismatch of versions, which in turn causes a problem with the .NET Core host, as described in https://github.com/dotnet/core-setup/issues/4376.
More technical details here: Azure/app-service-announcements-discussions#65 (comment)
Workaround 1
Remove PackageReference's which are already part of Microsoft.AspNetCore.App. You can find a list of what this package pulls in by looking at https://www.nuget.org/packages/microsoft.aspnetcore.app#show-dependency-groups. This will avoid the version mismatch.
Workaround 2
Upgrade the Microsoft.AspNetCore.App PackageReference to the latest 2.1.x version by adding the Version
attribute.
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.3" />