Messagepack-csharp: FormatterNotRegisteredException

Created on 12 Jun 2018  路  7Comments  路  Source: neuecc/MessagePack-CSharp

We are currently trying to use your MessagePack plugin. It works perfectly fine on Android, on Mac and windows. But, on ios, we are stuck at the start of the game with those following errors. Do you have any idea of what is going on?

FormatterNotRegisteredException: projectName.Properties.RoomStaticInfo is not registered in this resolver. resolver:StandardResolver at MessagePack.FormatterResolverExtensions.GetFormatterWithVerify[T] (MessagePack.IFormatterResolver resolver) [0x00000] in <00000000000000000000000000000000>:0

We checked other issues and found that this lines could fix the error:

MessagePack.Resolvers.CompositeResolver.RegisterAndSetAsDefault( MessagePack.Resolvers.GeneratedResolver.Instance, MessagePack.Resolvers.BuiltinResolver.Instance, AttributeFormatterResolver.Instance, MessagePack.Resolvers.PrimitiveObjectResolver.Instance );

But, in my project Resolvers does not contain GeneratedResolver.

Most helpful comment

@elsmart iOS does not support generating object formatters in runtime (AOT environment).
You have to generate your resolvers (GeneratedResolvers) by using mpc.exe.
https://github.com/neuecc/MessagePack-CSharp#pre-code-generationunityxamarin-supports

Also if mpc.exe generates a empty file, see https://github.com/neuecc/MessagePack-CSharp/issues/260 for workaround

All 7 comments

@elsmart iOS does not support generating object formatters in runtime (AOT environment).
You have to generate your resolvers (GeneratedResolvers) by using mpc.exe.
https://github.com/neuecc/MessagePack-CSharp#pre-code-generationunityxamarin-supports

Also if mpc.exe generates a empty file, see https://github.com/neuecc/MessagePack-CSharp/issues/260 for workaround

@zelsius i gen MessagePackGenerated , and add it,but it still not work for me

@1425275573 have you verified the content of the generated .cs file? If contains a 0 sized lookup it is likely the error solved in #260.

lookup = new global::System.Collections.Generic.Dictionary<Type, int>(0);

Actually it should look something like this:

lookup = new global::System.Collections.Generic.Dictionary<Type, int>(10)
            {
                {typeof(global::TestMessagePack.SimpleTypesAndFloat[]), 0 },
                {typeof(global::System.Collections.Generic.List<global::TestMessagePack.SimpleTypesAndFloat>), 1 },
                {typeof(global::System.Collections.Generic.LinkedList<global::TestMessagePack.SimpleTypesAndFloat>), 2 },
                {typeof(global::System.Collections.Generic.HashSet<global::TestMessagePack.SimpleTypesAndFloat>), 3 },
                {typeof(global::System.Collections.Generic.Dictionary<int, global::TestMessagePack.SimpleTypesAndFloat>), 4 },
                {typeof(global::System.Collections.Generic.Queue<global::TestMessagePack.SimpleTypesAndFloat>), 5 },
                {typeof(global::System.Collections.Generic.Stack<global::TestMessagePack.SimpleTypesAndFloat>), 6 },
                {typeof(global::TestMessagePack.SimpleTypes), 7 },
                {typeof(global::TestMessagePack.SimpleTypesAndFloat), 8 },
                {typeof(global::TestMessagePack.SimpleTypesCollection), 9 },
            };

And application launch, you need to set Resolver at first.

// CompositeResolver is singleton helper for use custom resolver.
// Ofcourse you can also make custom resolver.
MessagePack.Resolvers.CompositeResolver.RegisterAndSetAsDefault(
    // use generated resolver first, and combine many other generated/custom resolvers
    MessagePack.Resolvers.GeneratedResolver.Instance,

    // finally, use builtin/primitive resolver(don't use StandardResolver, it includes dynamic generation)
    MessagePack.Resolvers.BuiltinResolver.Instance,
    AttributeFormatterResolver.Instance,
    MessagePack.Resolvers.PrimitiveObjectResolver.Instance
);

I suggest adding this information to readme quickstart section since it very confusing. I have the same problem on windows

Also it's unclear where to get mpc.exe , the unitypackages does not contain it

This issue was filed against a 1.x version of the library. A lot of changes have been made to this area in 2.0 and I suspect this is fixed or no longer applies. Please retry your scenario on 2.0 and comment here if you think the issue should be re-opened.

Was this page helpful?
0 / 5 - 0 ratings