0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Unity] MasterMemory で FormatterNotRegisteredException が出たときの対応

Posted at

Unity で Master Memory を使用したときに以下のエラーが発生

FormatterNotRegisteredException: 名前空間.XxxData is not registered in resolver:
MessagePack.Resolvers.StandardResolver
MessagePack.FormatterResolverExtensions.Throw (System.Type t, MessagePack.IFormatterResolver resolver) (at Assets/Scripts/MessagePack/IFormatterResolver.cs:73)

結論

以下のコード追加が必要だった

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static async UniTask Initialize()
{
    var messagePackResolvers = CompositeResolver.Create(
        MasterMemoryResolver.Instance,
        GeneratedResolver.Instance,
        StandardResolver.Instance
    );
    var options = MessagePackSerializerOptions.Standard.WithResolver(messagePackResolvers);
    MessagePackSerializer.DefaultOptions = options;

しかし GeneratedResolver.Instance, の行でエラーになる
この Resolver を作成するのに以下の実行も

mpc -i Assembly-CSharp.csproj -o [出力先フォルダパス]

これで GeneratedResolver.Instance, が通るようになる

補足

mpc が実行できるのは MessagePack.Generator をインストールしているため

dotnet tool install --global MessagePack.Generator

dotnet tool list -g
パッケージ ID                    バージョン        コマンド
-----------------------------------------------------
mastermemory.generator      2.4.4        dotnet-mmgen
messagepack.generator       2.5.192      mpc

この辺りの手順は Master Memory に書かれている

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?