Messagepack-csharp: AspNetCore.SignalR.Protocols.MessagePack broken under latest MessagePack 2.0.323

Created on 28 Dec 2019  路  8Comments  路  Source: neuecc/MessagePack-CSharp

Bug description

I'm running the latest version of MessagePack 2.0.323 which I use throughout my ASP.NET Core 3.1 application, I also have SignalR Core working in this application w/JSON.

I added the package Microsoft.AspNetCore.SignalR.Protocols.MessagePack v3.1.0 which has a dependency on MessagePack >= 1.7.3.7. But after adding the MessagePack protocol option (AddMessagePackProtocol) the application fails to launch with the following error;

System.TypeInitializationException: 'The type initializer for 'SignalRResolver' threw an exception.'
Inner Exception
MissingFieldException: Field not found: 'MessagePack.Resolvers.DynamicEnumAsStringResolver.Instance'.

The current version of Microsoft.AspNetCore.SignalR.Protocols.MessagePack is not compatible with MessagePack 2.0.323, so I guess the latest MessagePack has introduced a breaking change.

I have tried to work around the exception using the following Resolvers, however this didn't work;

services.AddSignalR()
    .AddMessagePackProtocol(options =>
    {
        options.FormatterResolvers = new List<MessagePack.IFormatterResolver>()
        {
            MessagePack.Resolvers.DynamicEnumAsStringResolver.Instance,
            MessagePack.Resolvers.StandardResolver.Instance,
        };
    });

Repro steps

To replicate the issue clone and run the demo repo, it will throw the exception.
To demonstrate the dependency clash, edit SignalRCoreMessagePack.csproj and simply comment out the PackageReference to MessagePack 2.0.323 - see below;

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <!--older working versions;-->
    <!--<PackageReference Include="MessagePack" Version="1.7.3.7" />-->
    <!--<PackageReference Include="MessagePack" Version="1.8.80" />-->
    <!--newest version failing;-->
    <PackageReference Include="MessagePack" Version="2.0.323" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.0" />
  </ItemGroup>

</Project>

Expected behavior

The web application should load without errors.

Actual behavior

What happened instead of what you expected.
image

Version used:

  • Runtime: ASP.NET Core 3.1
  • Microsoft.AspNetCore.SignalR.Protocols.MessagePack 3.1.0
  • MessagePack 2.0.323

Additional context

I would welcome some feedback about how to correctly mitigate this error :)

Most helpful comment

Yes, MessagePack v2 has a great many breaking changes. Please reach out to ASP.NET for a way to resolve this since they own the 1.x consuming package. You may also check out our migration doc linked from our Readme file.

All 8 comments

Yes, MessagePack v2 has a great many breaking changes. Please reach out to ASP.NET for a way to resolve this since they own the 1.x consuming package. You may also check out our migration doc linked from our Readme file.

Is there a resolution to this problem? It looks like there should be, if I follow it down the rabbit hole, but I'm experiencing the same issue.

I answered my own question - I had to switch to using the .NET 5.0 pre-release and update my packages accordingly.

Hello @Codespeare , I'm using asp.net core 3.1.1. Could you tell me how to switch to .net 5.0 pre-relase on .net core?

@blizzardsolution

Project->Properties->Target Framework->"Install other frameworks"

Grab the .NET 5.0 SDK, install, restart VS. Then go to Project->Properties->Target Framework again and it will be available as an option.

I also had to go into my nuget package manager and update my frameworks with the "include prerelease" option checked.

@Codespeare awesome, thanks for helping me out!

Unfortunately, after installing .NET 5.0 SDK, .NET 5.0 option was not appearing on my Target Framework list. So i did it manually following migration guide

After setting up manually, i tried to build the project but got a build error saying that can't recognize 5.0 sdk 馃槀 ( i confirmed .NET 5.0 SDK has been installed from the command line)

It might be because I haven't upgraded my VS 2019 to the latest version (16.5.5).

Will upgrade VS and try again! By the way, should I upgrade all packages with "include prerelease" option or just MessagePack package?

@blizzardsolution I upgrade all my packages - I couldn't tell you if that's absolutely necessary or not.

Was this page helpful?
0 / 5 - 0 ratings