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

Internal enums trip up StandardResolverAllowPrivate #1025

Closed
AArnott opened this issue Sep 4, 2020 · 3 comments · Fixed by #1031
Closed

Internal enums trip up StandardResolverAllowPrivate #1025

AArnott opened this issue Sep 4, 2020 · 3 comments · Fixed by #1031
Assignees
Labels
Milestone

Comments

@AArnott
Copy link
Collaborator

AArnott commented Sep 4, 2020

The StandardResolverAllowPrivate resolver fails on non-public enum types:

        internal enum InternalEnum
        {
            One,
            Two,
        }

        [MessagePackObject]
        internal class InternalClass
        {
            [Key(0)]
            internal InternalEnum EnumProperty { get; set; }
        }


        [Fact]
        public void InternalClassWithInternalEnum()
        {
            InternalClass expected = new InternalClass
            {
                EnumProperty = InternalEnum.Two,
            };

            byte[] bytes = MessagePackSerializer.Serialize(expected, StandardResolverAllowPrivate.Options);
            InternalClass actual = MessagePackSerializer.Deserialize<InternalClass>(bytes, StandardResolverAllowPrivate.Options);
            Assert.Equal(expected.EnumProperty, actual.EnumProperty);
        }
Message: 
    MessagePack.MessagePackSerializationException : Failed to serialize MessagePack.Tests.AllowPrivateTest+InternalClass value.
    ---- System.TypeInitializationException : The type initializer for 'FormatterCache`1' threw an exception.
    -------- System.TypeLoadException : Type 'MessagePack.Formatters.MessagePack_Tests_AllowPrivateTest\+InternalEnumFormatter1' from assembly 'MessagePack.Resolvers.Dynamicp a mesEnumResolver, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is attempting to implement an inaccessible interface.
@AArnott AArnott added the bug label Sep 4, 2020
@AArnott AArnott added this to the v2.1 milestone Sep 4, 2020
@AArnott AArnott self-assigned this Sep 4, 2020
AArnott added a commit to AArnott/MessagePack-CSharp that referenced this issue Sep 4, 2020
@AArnott
Copy link
Collaborator Author

AArnott commented Sep 9, 2020

@neuecc Do you have any thoughts on this? Do we need to create another dynamic method system to handle this like we have for non-public classes/structs?

@neuecc
Copy link
Member

neuecc commented Sep 9, 2020

@AArnott

The implementation is already in GenericEnumFormatter,
and besides, this is included in the DynamicGenericResolver, so remove DynamicEnumResolver from StandardResolverHelper, it will work.

  • Erase DynamicEnumResolver only AllowPrivate
  • Erase in both cases

There was no Unsafe before.
We also thought it would be advantageous in terms of performance because it would not pass through delegates.
However, I think it's a good to use only GenericEnumFormatter.

AArnott added a commit to AArnott/MessagePack-CSharp that referenced this issue Sep 9, 2020
@AArnott
Copy link
Collaborator Author

AArnott commented Sep 9, 2020

Awesome. I'm so glad I asked because I was about to go to great lengths to fix it in the wrong way. Your way was deleting one line. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants