Skip to content

Unity IL2CPP generic object wrapper code gen #964

@CornLizard

Description

@CornLizard

Bug description

Hello, I'm trying to use a generic object wrapper it works in the editor but during runtime it throws an error. I'm unsure if the code gen is supposed to work with generics. If not I'll have to figure out a workaround :( Thanks in advance for any help!

Error Message
MessagePack.MessagePackSerializationException: Failed to deserialize MyAssembly.MyDataModel value. ---> MessagePack.FormatterNotRegisteredException: MyAssembly.Wrapper"1[[System.Int32, System, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]] is not registered in resolver: MessagePack.Resolvers.StaticCompositeResolver

Repro steps

[MessagePackObject]
[Union(0, typeof(WrapperGeneric<int>))]
public abstract class Wrapper
{
    public static WrapperGeneric<T> Create<T>(T value)
    {
        return new WrapperGeneric<T>(value);
    }
    [IgnoreMember]
    public object Value
    {
        get { return ValueImpl; }
        set { ValueImpl = value; }
    }
    protected abstract object ValueImpl { get; set; }
    protected Wrapper() { }
}
[MessagePackObject]
public sealed class WrapperGeneric<T> : Wrapper
{
    public WrapperGeneric() { }
    public WrapperGeneric(T value) { Value = value; }
    [Key(0)]
    public new T Value { get; set; }
    protected override object ValueImpl
    {
        get { return Value; }
        set { Value = (T)value; }
    }
}

Called during edit mode and runtime returns null
GeneratedResolver.Instance.GetFormatter<WrapperGeneric<int>>()

  • Version used:
  • Unity 2019.4.1f1 LTS IL2CPP .NET 4.x
  • MessagePack.Unity.2.1.143

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions