Cysharp / MagicOnion

Unified Realtime/API framework for .NET platform and Unity.
MIT License
3.9k stars 433 forks source link

Question: Cannot get SourceGenerator to work on Unity. What am I doing wrong? #857

Closed gegogi closed 1 month ago

gegogi commented 1 month ago

I could run ChatApp.Unity project from the released zip file successfully. ( Version 6.1.4 ) I could create my own server app based on MagicOnion.Server. But I cannot get my own Unity project working. It is a compilation failure.

From the code below, the compiler cannot find the generated code of MagicOnionGeneratedClientInitializer.Resolver. The only difference of my project from the sample project seems that MagicOnion.Client is installed from the git repo not from the local dir. Everything else looks same.

Is there a way to debug whether the source generator is working well? What am I possibly doing wrong?

#if UNITY_2019_4_OR_NEWER
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.BeforeSceneLoad)]
#elif NET5_0_OR_GREATER
[System.Runtime.CompilerServices.ModuleInitializer]
#endif
static void RegisterResolvers()
{
    StaticCompositeResolver.Instance.Register(
        // Add: Use MessagePack formatter resolver generated by the source generator.
        MagicOnionGeneratedClientInitializer.Resolver,
        MessagePack.Resolvers.GeneratedResolver.Instance,
        BuiltinResolver.Instance,
        PrimitiveObjectResolver.Instance
    );

    MessagePackSerializer.DefaultOptions = MessagePackSerializer.DefaultOptions
        .WithResolver(StaticCompositeResolver.Instance);
}