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.
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.
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.