Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity IL2CPP generic object wrapper code gen #964

Closed
CornLizard opened this issue Jun 25, 2020 · 3 comments
Closed

Unity IL2CPP generic object wrapper code gen #964

CornLizard opened this issue Jun 25, 2020 · 3 comments

Comments

@CornLizard
Copy link

CornLizard commented Jun 25, 2020

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
@thorgeirk11
Copy link
Contributor

thorgeirk11 commented Jul 15, 2020

I have the exact same issue...

@AArnott Is there no way to tell mpc to generate formatters for 'known' generic wrapper types?

Or just in general how can I create a formatter for such a generic wrapper?

@AArnott
Copy link
Collaborator

AArnott commented Jul 16, 2020

I don't maintain mpc. @neuecc would have to answer that question.

thorgeirk11 added a commit to thorgeirk11/MessagePack-CSharp that referenced this issue Aug 4, 2020
- Added CollectGenericUnion method, which reads the union attributes on generic class definitions.
- Formatter names are now created by using the MinimallyQualifiedFormat to support generic classes. e.g. AWrapper<IEnumerable<string>> would be called AWrapper_IEnumerable_string__Formatter
This enables MessagePack-CSharp#964
@thorgeirk11
Copy link
Contributor

thorgeirk11 commented Aug 13, 2020

This issue should now be fixed. @MetaCitizenOffical

@AArnott AArnott closed this as completed Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants