Unable to start websocket server from Windows service in .net core

Nivedita Parihar 21 Reputation points
2021-05-24T04:56:51.823+00:00

I have created windows service in .net core using microsoft.extensions.hosting.windowsservices.5.0.1 package .
Also i have created websocket server using microsoft.aspnetcore.websockets.2.2.1 package . in different library

When i am trying to start websocket server from windows service , it is causing runtime exception.

Microsoft.AspNetCore.Server.Kestrel[0]
Heartbeat.OnHeartbeat
System.TypeLoadException: Could not load type 'Microsoft.Extensions.Primitives.InplaceStringBuilder' from assembly 'Microsoft.Extensions.Primitives, Version=6.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()

Rootcause: Both the packages are having Microsoft.Extensions.Primitives.dll which is giving conflict so while compiling in bin directory only higher version is retained so websocket server is giving the above mentioned error.

Note :
Microsoft.Extensions.Primitives.dll 5.0 version in windows service
Microsoft.Extensions.Primitives.dll 2.21 version in websocket server .

Can someone help me in this , Not sure how to resolve this issue.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,400 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rena Ni - MSFT 2,066 Reputation points
    2021-05-25T05:39:05.607+00:00

    Hi @Nivedita Parihar ,

    I think you could read this github issue. It explains why causes such issue and you could choose to downgrade to Microsoft.Extensions.Primitives v3.1.10 or change <Project Sdk="Microsoft.NET.Sdk.Web">" to <Project Sdk="Microsoft.NET.Sdk"> as the solution here did.


0 additional answers

Sort by: Most helpful