Messagepack-csharp: Quickstart example is not working

Created on 1 Jul 2019  路  20Comments  路  Source: neuecc/MessagePack-CSharp

The example in quickstart generates a runtime error:

FormatterNotRegisteredException: MyClass is not registered in this resolver. resolver:StandardResolver
mpc no-issue-activity unity

Most helpful comment

@DataGreed Are you using Unity?
Sadly the library seems to be broken with the API setting ".Net Standard 2.0". Unfortunately this is now the default setting.
Workaround: You can get it running by changing the option to ".NET 4.x" (under "Player Settings" -> "Other Settings" -> "Api Compatibility Level".

All 20 comments

Does MyClass have MessagePackObject attribute?
It is required for use StandardResolver.

@DataGreed Are you using Unity?
Sadly the library seems to be broken with the API setting ".Net Standard 2.0". Unfortunately this is now the default setting.
Workaround: You can get it running by changing the option to ".NET 4.x" (under "Player Settings" -> "Other Settings" -> "Api Compatibility Level".

After struggling with this library for several hours I've switched to https://github.com/msgpack/msgpack-cli which worked for me out-of-the-box.

Not sure if I will return to trying this one unless serialization becomes a bottleneck.

@brookman yes, I am using Unity. Thank you for the workaround! If I'll have some free time I'll probably try it.

@nogic1008 yes it does. I've implemented everything like the readme suggested.

I am using Unity with .NET Standard 2.0 and this library (v1.7.3.5) without any issues,

@odysoftware Which Unity version and platform do you use. (I have 2019.1.5f1 and target Android)

I have been using this library from 2018.1 till latest version 2019.1

So currently I am on 2019.1.8.f1 and targeting iOS, Android and MacOS. I am using IL2CPP mode and .NET Standard 2.0. And for MessagePack I have the v.1.7.3.5 unity package installed. I don't get any errors and afaik the v.1.7.3.5 was specially made for .net standard 2.0 compatibility.

@odysoftware are you using code generation (mpc.exe)? If yes, which version? I have spent a few hours but could not get it running...

Yeah getting mpc.exe working on mac was sometimes a bit of a pain. But since using a .NET Core Server Project it was working fine - not sure anymore if I had to use something special - but I was thinking it just worked once I switched to .NET Core and latest Messagepack from neuecc via nuget?

Encountering the same issue.
MessagePack.Unity.1.7.3.5.unitypackage
Unity 2019.2.8f1

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.

I think I have this issue in IL2CPP and .NET 4.x Unity 2019.2.16f

@leonidax The original issue of "MyClass is not registered in this resolver" is simply a failure to configure the serializer per the README instructions. Please review those and if there's an issue open a new issue with details including the messagepack version you're using.

@AArnott still I believe the quickstart be formulated s.t. it works out of the box and it does on .NET 4 Framework and fails as @DataGreed posted if you switch to .NET 2.0 as you can see in this example project by switching the framework and simply entering play mode (platform: PC)
ThisTookMe10Minutes.zip

Yes it does work when using mpc and a GeneratedResolver and registering it - but the quickstart example is the place to tell someone new to this repository that :)

What do you mean by "switch to .NET 2.0"? .NET 2.0 isn't a thing. Do you mean .NET Framework 2.0 (which is so old we don't support that) or .NET Core 2.0 (which is also out of support, but 2.1 is supported).

It sounds like your questions are Unity and/or mpc-specific, so I can't comment much as I don't know much about either -- @neuecc is the expert there.

Unity's platform matrix is...

  • .NET Standard 2.0
  • .NET Framework 4.x

and

  • Mono 2.x
  • IL2CPP

and

  • Windows
  • Mac
  • iOS
  • WebGL
  • etc...

Code generation and Register are required except for .NET 4.x + mono.
If you have title problems with IL2CPP, please generate code.

@neuecc Thanks. That is actually super helpful and while now clear it might be good to put that into the first sentence of the Unity Code Generation section in the readme :)

Is there anything beside Reflect.Emit that is missing in .NET Standard 2.0 for MessagePack to get rid of mpc?

I always thought Reflect.Emit would be available in .net Standard 2.0 but just realized/learned that this is not the case:

@DataGreed can this ticket be closed?

@AArnott yes that was a Unity specific example related to the possibility to switch the scripting backend used there and show casing how the quick start breaks (as expected according to the answer of @neuecc )

Reflection.Emit _is_ available in netstandard2.0. In fact it was available in netstandard1.6, as you can see with here: https://apisof.net/catalog/System.Reflection.Emit.TypeBuilder. It's just that it requires one extra package reference, but it works fine on .NET Framework and .NET Core 2.x when doing so.

MessagePack's netstandard2.0 build has all the Ref.Emit code in it.

But in Unity when compiling MessagePack from source (which is the only way we support it), the relevant defines is _not_ NETSTANDARD2_0 but rather NET_STANDARD_2_0 (along with some others). So Ref.Emit is left out of some Unity compilations, I believe. Although there have been multiple attempts to get it more thoroughly removed from platforms that don't support it so that things tend to work more. #890 is one currently active PR, that I and @neuecc need to review.

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Was this page helpful?
0 / 5 - 0 ratings