yasirkula / UnityIngameDebugConsole

A uGUI based console to see debug messages and execute commands during gameplay in Unity
MIT License
2.11k stars 221 forks source link

GetExportedTypes not supported in dynamic modules #40

Closed salyu9 closed 3 years ago

salyu9 commented 3 years ago

Description of the bug

Some unity projects may use dynamic generated assemblies. In this case when enter playing mode, a NotSupportedException will be thrown from the static constructor of DebugLogConsole with these logs:

NotSupportedException: The invoked member is not supported in a dynamic module.
System.Reflection.Emit.AssemblyBuilder.GetExportedTypes () (at <9577ac7a62ef43179789031239ba8798>:0)
IngameDebugConsole.DebugLogConsole..cctor () (at Library/PackageCache/com.yasirkula.ingamedebugconsole@1.4.1/Plugins/IngameDebugConsole/Scripts/DebugLogConsole.cs:160)
Rethrow as TypeInitializationException: The type initializer for 'IngameDebugConsole.DebugLogConsole' threw an exception.
IngameDebugConsole.DebugLogManager.OnDisable () (at Library/PackageCache/com.yasirkula.ingamedebugconsole@1.4.1/Plugins/IngameDebugConsole/Scripts/DebugLogManager.cs:425)

Reproduction steps

URP and HDRP are using dynamic generated assemblies in editor. Projects with these pipelines may run into this issue. Here's a simple reproduction:

  1. Create a new Unity project with template Universal Render Pipeline.
  2. Install In-game debug console and drag the prefab to the scene.
  3. Enter play mode.

Platform specs

Please provide the following info if this is a Unity 3D repository.

Additional info

Maybe just check Assembly.IsDynamic and bypass dynamic assemblies in the static constructor of DebugLogConsole.

yasirkula commented 3 years ago

Thank you for the detailed Issue, it was really helpful!