Cysharp / MemoryPack

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

Problem with using memorypack on a external dll library, problem with polymorphism on c# 8.0 #193

Closed Zogir01 closed 7 months ago

Zogir01 commented 11 months ago

Hi, I need to use MemoryPack on an external dll library that is shared between my projects. When I test that, I am able to compile dll library successfully, however when serializing my class I get an exception:

image

Where NetworkCore is my dll library. And PlayerAttributes is my custom class, from another project, outside NetworkCore.

My class PlayerAttributes:

[MemoryPackable]
    public partial class PlayerAttributes 
    {
        public int CharacterVId { get; set; }
        public string Name { get; set; }
        public float CurrentHealth { get; set; }
        public float MaxHealth { get; set; }
        public float CurrentMana { get; set; }
        public float MaxMana { get; set; }
        public float MoveSpeed { get; set; }
        public float AttackSpeed { get; set; }
    }

Is your library works well with netstandard 2.1 and dll libraries?

Next problem I'm struggling with is using Unions to create polymorphism:

   [MemoryPackable(GenerateType.NoGenerate)]
    [MemoryPackUnion(0, typeof(PlayerTransform))]
    public partial interface IGamePacket
    {
    }

This code causes compiler error, which telling me that I should use c# 9.0 in that line:

static readonly System.Collections.Generic.Dictionary<Type, ushort> __typeToTag = new(2)

which is in automatic generated file by your library in class "IGamePacketFormatter" and "new(2)" causes an error. Description of this error: 'create object from hidden type' feature is not available in C# 8.0.

So can I create polymorphism using your library in c# 8.0?

neuecc commented 11 months ago

about targetframework dependency https://github.com/Cysharp/MemoryPack#target-framework-dependency

No thoughts on C# 8.0 support.

Mo-Rahemi commented 11 months ago

hey i have same problem. i used netstandard2.1;net8.0 but still have error on .net 2.1

hadashiA commented 7 months ago

which is in automatic generated file by your library in class "IGamePacketFormatter" and "new(2)" causes an error.

I think the answer to this issue is that unfortunately C# 8 is not supported.

hey i have the same problem. i used netstandard2.1;net8.0 but still have error on .net 2.1

Please specify 9 or higher for LangVersion. If you still have another problem, please report it.