dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
34.81k stars 9.84k forks source link

HubException when using MessagePack in .NET 8 #56502

Open martinvaner opened 1 week ago

martinvaner commented 1 week ago

Is there an existing issue for this?

Describe the bug

Hi all, after upgrading to .NET 8 I am experiencing issue with SignalR when using MessagePack. I get Microsoft.AspNetCore.SignalR.HubException : The server closed the connection with the following error: Connection closed with an error. when connecting to server. Everything works fine without MessagePack.

Used nugets:

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

Microsoft.AspNetCore.SignalR.HubException : The server closed the connection with the following error: Connection closed with an error.

.NET Version

8.0.204

Anything else?

No response

BrennanConroy commented 3 days ago

https://learn.microsoft.com/aspnet/core/signalr/diagnostics?view=aspnetcore-8.0#server-side-logging

Please look at server logs.

martinvaner commented 2 days ago

@BrennanConroy Thank you for your reply. I am posting full exception on my server side.

Failed writing message. Aborting connection. <s:Microsoft.AspNetCore.SignalR.HubConnectionContext>
MessagePack.MessagePackSerializationException: Failed to serialize System.Collections.Generic.List`1[[XXX.RevisionedValue`1[[XXX.DTO, XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] value.
 ---> System.TypeInitializationException: The type initializer for 'FormatterCache`1' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'FormatterCache`1' threw an exception.
 ---> MessagePack.Internal.InitAccessorInGenericClassNotSupportedException: `init` property accessor XXX.RevisionedValue`1[[XXX.DTO, XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Value found in generic type, which is not supported with the DynamicObjectResolver. Use the AllowPrivate variety of the resolver instead. See https://github.com/neuecc/MessagePack-CSharp/issues/1134 for details.
   at MessagePack.Internal.ObjectSerializationInfo.EmittableMember.ThrowIfNotWritable()
   at MessagePack.Internal.ObjectSerializationInfo.CreateOrNull(Type type, Boolean forceStringKey, Boolean contractless, Boolean allowPrivate, Boolean dynamicMethod)
   at MessagePack.Internal.DynamicObjectTypeBuilder.BuildType(DynamicAssembly assembly, Type type, Boolean forceStringKey, Boolean contractless)
   at MessagePack.Resolvers.DynamicContractlessObjectResolver.FormatterCache`1..cctor()
   --- End of inner exception stack trace ---
   at MessagePack.Resolvers.DynamicContractlessObjectResolver.GetFormatter[T]()
   at MessagePack.Resolvers.ContractlessStandardResolver.FormatterCache`1..cctor()
   --- End of inner exception stack trace ---
   at MessagePack.Resolvers.ContractlessStandardResolver.GetFormatter[T]()
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocol.SignalRResolver.Cache`1.ResolveFormatter()
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocol.SignalRResolver.Cache`1..cctor()
--- End of stack trace from previous location ---
   at MessagePack.FormatterResolverExtensions.Throw(TypeInitializationException ex)
   at MessagePack.Formatters.ListFormatter`1.Serialize(MessagePackWriter& writer, List`1 value, MessagePackSerializerOptions options)
   at MessagePack.MessagePackSerializer.Serialize[T](MessagePackWriter& writer, T value, MessagePackSerializerOptions options)
   --- End of inner exception stack trace ---
   at MessagePack.MessagePackSerializer.Serialize[T](MessagePackWriter& writer, T value, MessagePackSerializerOptions options)
   at MessagePack.MessagePackSerializer.SerializeSemiGeneric[T](MessagePackWriter& writer, Object valueObject, MessagePackSerializerOptions options)
   at MessagePack.MessagePackSerializer.Serialize(Type type, MessagePackWriter& writer, Object obj, MessagePackSerializerOptions options)
   at Microsoft.AspNetCore.SignalR.Protocol.DefaultMessagePackHubProtocolWorker.Serialize(MessagePackWriter& writer, Type type, Object value)
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.WriteArgument(Object argument, MessagePackWriter& writer)
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.WriteCompletionMessage(CompletionMessage message, MessagePackWriter& writer)
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.WriteMessageCore(HubMessage message, MessagePackWriter& writer)
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.WriteMessage(HubMessage message, IBufferWriter`1 output)
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocol.WriteMessage(HubMessage message, IBufferWriter`1 output)
   at Microsoft.AspNetCore.SignalR.HubConnectionContext.WriteCore(HubMessage message, CancellationToken cancellationToken)
BrennanConroy commented 1 day ago

The exception says

MessagePack.Internal.InitAccessorInGenericClassNotSupportedException: init property accessor XXX.RevisionedValue`1[[XXX.DTO, XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Value found in generic type, which is not supported with the DynamicObjectResolver. Use the AllowPrivate variety of the resolver instead. See https://github.com/neuecc/MessagePack-CSharp/issues/1134 for details.