question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding reference to "Microsoft.Extensions.Hosting" Version="5.0.0" kills the service

See original GitHub issue

If 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:

  1. Build CoreWCFWithSamples.sln.
  2. Navigate to e.g. C:\GitHub\CoreWCF\bin\Debug\NetCoreServer\netcoreapp3.1 (adjusted to point to a proper local folder), then run NetCoreServer.exe.
  3. Observe that it runs without errors.
  4. Add a reference to "Microsoft.Extensions.Hosting" Version="5.0.0" to the project NetCoreServer.
  5. Clean / rebuild the solution, then try running NetCoreServer.exe.
  6. 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.

ErrLog.txt

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mconnewcommented, Jan 14, 2021

Work to support the latest version of .NET Core will happen after the initial GA release happening later this month.

0reactions
mconnewcommented, Feb 28, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding reference to "Microsoft.Extensions.Hosting" Version ...
Adding reference to "Microsoft.Extensions.Hosting" Version="5.0.0" kills the service.
Read more >
c# - Could not load file or assembly 'Microsoft.Extensions. ...
I encountered the same issue and I resolved it by downgrading "Microsoft.Extensions.Http" to 6.0.0.0 to match my TargetFramework net6.0.
Read more >
Extensions: Package reference changes affecting some ...
Learn about the breaking change in ASP.NET Core 5.0 titled Extensions: Package reference changes affecting some NuGet packages.
Read more >
Microsoft.Extensions.Hosting Namespace
A builder for hosted applications and services that helps manage configuration, logging, lifetime, and more. HostApplicationBuilderSettings. Contains the ...
Read more >
Error while downgrading project from .net 5 to .net core 3.1
Team, I need to upload my .net core app service on azure stack which only support .net core 3.1. I've made whole project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found