question

NiveditaParihar-3531 avatar image
0 Votes"
NiveditaParihar-3531 asked NiveditaParihar-3531 edited

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

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.

dotnet-aspnet-core-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RenaNi-MSFT avatar image
0 Votes"
RenaNi-MSFT answered NiveditaParihar-3531 edited

Hi @NiveditaParihar-3531,

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.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@RenaNi-MSFT Thanks for references , it helped.

When i just added this line in .csproj file and SDK was <Project Sdk="Microsoft.NET.Sdk">
It started working.

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

0 Votes 0 ·