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

Nivedita Parihar 21 Reputation points

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.

System.TypeLoadException: Could not load type 'Microsoft.Extensions.Primitives.InplaceStringBuilder' from assembly 'Microsoft.Extensions.Primitives, Version=, 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.

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

Accepted answer
  1. Rena Ni - MSFT 2,061 Reputation points

    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