Cysharp / MemoryPack

Zero encoding extreme performance binary serializer for C# and Unity.
MIT License
3.29k stars 193 forks source link

Bug: failed System.TypeLoadException #54

Closed mirbeta closed 1 year ago

mirbeta commented 1 year ago

The HostOptions.BackgroundServiceExceptionBehavior is configured to StopHost. A BackgroundService has thrown an unhandled exception, and the IHost instance is stopping. To avoid this behavior, configure this to Ignore; however the BackgroundService will not be restarted. System.TypeLoadException: Virtual static method 'Serialize' is not implemented on type 'SystemModule.Packets.ServerPackets.ServerDataMessage' from assembly 'SystemModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

neuecc commented 1 year ago

please provide more details and reproduce code?

mirbeta commented 1 year ago

here

ConsoleApp2.zip

neuecc commented 1 year ago

Thank you. I've understand issue. NetStandard 2.1 class library can not use from Net7 application. This is because the .NET 7 version uses static abstract members that require runtime updates. You need to update library to Net7(or use TargetFrameworks netstandard2.1;net7.0).

This will be noted in the ReadMe, as the error is not easy to understand. Thanks.

mirbeta commented 1 year ago

Maybe this needs to be fixed by the .Net team? it is very common to use netstandard2.1 in shared libraries, maybe we will see netstandard2.2 in the near future? Not all teams or developers will use net7 or higher to solve problems usually use libraries.

mirbeta commented 1 year ago

Thank you again, the error has been fix using net7 as you said.

neuecc commented 1 year ago

Library developer, configure dual target framework. <TargetFrameworks>netstandard2.1;net7.0</TargetFrameworks> Applicatoin developer, only to use net7.0. <TargetFramework>net7.0</TargetFramework>

NicoIer commented 3 months ago

Library developer, configure dual target framework. <TargetFrameworks>netstandard2.1;net7.0</TargetFrameworks> Applicatoin developer, only to use net7.0. <TargetFramework>net7.0</TargetFramework>

It works !

NicoIer commented 1 month ago

https://github.com/Cysharp/MemoryPack/blob/main/src/MemoryPack.UnityShims/Shims.cs When the server uses Vector3 in Shim and the Unity client uses UnityEngine.Vector3, the value of the Vector3 uploaded by the client is not parsed correctly on the server side, is this the correct behavior, because UnityEngine.Vector3 is really not tagged in Unity as [ MemoryPackable]