Adding reference to "Microsoft.Extensions.Hosting" Version="5.0.0" kills the service
See original GitHub issueIf a project references both CoreWCF
and "Microsoft.Extensions.Hosting" Version="5.0.0"
(which is a substantial part of NET5), then WCF service fails to start with the error like this one:
fail: Microsoft.AspNetCore.Server.Kestrel[0]
Heartbeat.OnHeartbeat
System.TypeLoadException: Could not load type 'Microsoft.Extensions.Primitives.InplaceStringBuilder' from assembly 'Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at Microsoft.Net.Http.Headers.DateTimeFormatter.ToRfc1123String(DateTimeOffset dateTime, Boolean quoted)
at Microsoft.Net.Http.Headers.HeaderUtilities.FormatDate(DateTimeOffset dateTime, Boolean quoted)
at Microsoft.Net.Http.Headers.HeaderUtilities.FormatDate(DateTimeOffset dateTime)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.DateHeaderValueManager.SetDateValues(DateTimeOffset value)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.DateHeaderValueManager.OnHeartbeat(DateTimeOffset now)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.Heartbeat.OnHeartbeat()
This is sort of a known issue because CoreWCF
references an obsolete package "Microsoft.AspNetCore" Version="2.2.0"
, which, in turn, results in this error when "Microsoft.Extensions.Hosting" Version="5.0.0"
is also used: https://github.com/dotnet/aspnetcore/issues/27986
Known workarounds:
As advised in the reference above, add
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
into any project that references "Microsoft.Extensions.Hosting" Version="5.0.0"
. It appears that even a single reference in some lower level project is enough. So, perhaps adding this reference into CoreWCF
itself will do the trick.
Repro steps:
- Build
CoreWCFWithSamples.sln
. - Navigate to e.g.
C:\GitHub\CoreWCF\bin\Debug\NetCoreServer\netcoreapp3.1
(adjusted to point to a proper local folder), then runNetCoreServer.exe
. - Observe that it runs without errors.
- Add a reference to
"Microsoft.Extensions.Hosting" Version="5.0.0"
to the projectNetCoreServer
. - Clean / rebuild the solution, then try running
NetCoreServer.exe
. - Observer that now it starts producing the exception above.
This is fairly severe as reference to "Microsoft.Extensions.Hosting" Version="5.0.0"
is pretty much a must in almost any NET5 web related app. Attached is the full log of running NetCoreServer.exe
with Microsoft.Extensions.Hosting
added.
I would suggest re-targeting CoreWCF to NET5 instead of NetCore 3.1, then fix what’s broken.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:12 (6 by maintainers)
Top GitHub Comments
Work to support the latest version of .NET Core will happen after the initial GA release happening later this month.
If you specify using the 2.1 version as a direct dependency in your app it will override whatever any over dependency is trying to pull it. As long as they aren’t using api’s which only exist in the newest version of the package, that has a good chance of working.