Messagepack-csharp: Xamarin.Forms Android app crashes with "Register must call on startup(before use GetFormatter<T>)."

Created on 14 Mar 2018  路  2Comments  路  Source: neuecc/MessagePack-CSharp

Our Xamarin.Forms Android app crashes with the following error: "Register must call on startup(before use GetFormatter)."

In the App.xaml.cs OnStart() method we call:
MessagePack.Resolvers.CompositeResolver.RegisterAndSetAsDefault( MessagePack.Resolvers.GeneratedResolver.Instance, MessagePack.Resolvers.BuiltinResolver.Instance, AttributeFormatterResolver.Instance, MessagePack.Resolvers.PrimitiveObjectResolver.Instance );

Steps to Reproduce:

1) Start app via app icon => everything works fine
2) Send app to background by pressing home button
3) Open app again via app icon => App crashes with an InvalidOperationException "Register must call on startup(before use GetFormatter)."

We are using MessagePack 1.7.3.4.

question

Most helpful comment

RegisterAndSetAsDefault can only call once.
Maybe it is called twice(on OnStart?).

I don't know Xamarin Forms's lifecycle but you move to initialize call on exactly once method or check calling twice.

All 2 comments

RegisterAndSetAsDefault can only call once.
Maybe it is called twice(on OnStart?).

I don't know Xamarin Forms's lifecycle but you move to initialize call on exactly once method or check calling twice.

Thanks for you reply. Android calls the OnStart again when the app is opened via the app icon while the app is already in the background (and MessagePack is initialized twice in that case). I will add a flag.

Was this page helpful?
0 / 5 - 0 ratings