UnityLinker fails with a NullReferenceException in SweepDebugInfo every time I enable “Script Debugging”, which seems to be a bug in UnityLinker. Here’s how I was able to find a workaround:
Script debugging was working recently, so I did a binary search through commits in our git repo, building them until I found the bad commit. I enabled diagnostic reporting in UnityLinker (set UNITYLINKER_ADDITIONAL_ARGS=--enable-report --enable-snapshot), and then compared input args between the bad commit and the previous good commit. This revealed that a DLL was not being passed to UnityLinker in the bad commit:
Note that classes from this DLL are definitely referenced by multiple scripts and prefabs that are navigable from the “roots” as described in the docs about C# code stripping. The guilty commit had purged a bunch of stale SpawnerData .asset files, a ScriptableObject class implemented in this DLL.
I was able to work around the bug by adding a dummy SpawnerData .asset file to the Resources folder, which convinced Unity to pass the DLL argument to UnityLinker, and fixed the build.
I pulled the source for mono linker from github to investigate what happens in SweepDebugInfo. SweepDebugInfo has an early exit when debugging is disabled, which explains why builds only fail when script debugging is enabled. Squinting at the code didn’t provide much insight. It’s checking for null in the obvious places. I’m guessing one of the property getters inside of MethodDebugInformation is stepping on a null because of that missing DLL input argument.
FWIW, the DLL in question is implemented in F#. What info can I provide to Unity to help track down the issue and get a permanent fix?
For reference, this is the error message from UnityLinker when it fails to sweep debug info:
Fatal error in Unity CIL Linker
System.NullReferenceException: Object reference not set to an instance of an object
at Mono.Linker.Steps.SweepStep.SweepDebugInfo (Mono.Collections.Generic.Collection`1[T] methods) [0x00098] in <fdb4fc84d9e048eaa2de2ebaa14c8a30>:0
at Mono.Linker.Steps.SweepStep.SweepMethods (Mono.Collections.Generic.Collection`1[T] methods) [0x00013] in <fdb4fc84d9e048eaa2de2ebaa14c8a30>:0
at Unity.Linker.Steps.UnitySweepStep.SweepMethods (Mono.Collections.Generic.Collection`1[T] methods) [0x00036] in <04c78ac134f947649b7ee6e8097dfdc1>:0
at Mono.Linker.Steps.SweepStep.SweepType (Mono.Cecil.TypeDefinition type) [0x0002a] in <fdb4fc84d9e048eaa2de2ebaa14c8a30>:0
at Mono.Linker.Steps.SweepStep.SweepAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x000ea] in <fdb4fc84d9e048eaa2de2ebaa14c8a30>:0
at Mono.Linker.Steps.SweepStep.Process () [0x00030] in <fdb4fc84d9e048eaa2de2ebaa14c8a30>:0
at Unity.Linker.Steps.UnitySweepStep.Process () [0x00007] in <04c78ac134f947649b7ee6e8097dfdc1>:0
at Mono.Linker.Steps.BaseStep.Process (Mono.Linker.LinkContext context) [0x00018] in <fdb4fc84d9e048eaa2de2ebaa14c8a30>:0
at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00021] in <fdb4fc84d9e048eaa2de2ebaa14c8a30>:0
at Unity.Linker.UnityDriver.Run () [0x00087] in <04c78ac134f947649b7ee6e8097dfdc1>:0
at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling () [0x00007] in <04c78ac134f947649b7ee6e8097dfdc1>:0
at Unity.Linker.UnityDriver.RunDriver () [0x00002] in <04c78ac134f947649b7ee6e8097dfdc1>:0
