Mirror: Assembly Sharing Violations Occuring with Mirror & Burst

When using Mirror in combination with Burst compilation, the compiler will crash from time to time (in my case roughly 10% of compiles).

The error message in this case is either something along the lines of Microsoft (R) Visual C# Compiler error CSXXX or a sharing violation originating from Library/ScriptAssemblies, with a different assembly file each time.

Note that I have not 100% narrowed it down to the combination of Mirror and Burst since I cannot easily reproduce this behavior (except continually compiling until it eventually fails).

However, this issue is not present without Mirror in the project, and I have turned off burst compile for the time being, and have yet to see the issue appear, so I’m fairly certain both Mirror and Burst are trying to write the same assemblies.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 35 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I’m still having this happen and I’m willing to invite @vis2k to my repo, join a Discord call, whatever it takes.

I noticed that a real callstack hasn’t been provided here yet:

Weave behaviours and messages took292 milliseconds
  ProcessSitesModule Assembly-CSharp.dll elapsed time:00:00:00.0143827
- Finished compile Library/ScriptAssemblies/Assembly-CSharp.dll in 1.903921 seconds
- Starting compile Library/ScriptAssemblies/Assembly-CSharp-Editor.dll

-----Compiler Commandline Arguments:
Filename: C:\Program Files\Unity\Hub\Editor\2020.3.9f1\Editor\Data\Tools\RoslynScripts\unity_csc.bat
Arguments: /noconfig @Temp/UnityTempFile-55e5832697d56e3409cd8035b70b4fcf
Responsefile: Temp/UnityTempFile-55e5832697d56e3409cd8035b70b4fcf Contents: 
/target:library
/out:Temp/Assembly-CSharp-Editor.dll
/nowarn:0169
/nowarn:0649
/refout:Temp/Assembly-CSharp-Editor.dll.ref
/deterministic
/debug:portable
/optimize-
/nostdlib+
/preferreduilang:en-US
/langversion:8.0
... (Skipped for brevity)

-----CompilerOutput:-stdout--exitcode: 1--compilationhadfailure: True--outfile: Temp/Assembly-CSharp-Editor.dll
Microsoft (R) Visual C# Compiler version 3.5.0-dev-20359-01 (8da8ba0c)
Copyright (C) Microsoft Corporation. All rights reserved.

error CS0009: Metadata file 'D:\Projects\zombie-quest\UnityProject-ZombieQuest\Library\ScriptAssemblies\UnityEditor.TestRunner.dll' could not be opened -- The process cannot access the file 'D:\Projects\zombie-quest\UnityProject-ZombieQuest\Library\ScriptAssemblies\UnityEditor.TestRunner.dll' because it is being used by another process.
-----EndCompilerOutput---------------

Weaver: stop because compile errors on target
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:Log (object)
Mirror.Weaver.CompilationFinishedHook:OnCompilationFinished (string,UnityEditor.Compilation.CompilerMessage[]) (at Assets/Plugins/Mirror/Editor/Weaver/CompilationFinishedHook.cs:95)
UnityEditor.Compilation.CompilationPipeline/<>c:<SubscribeToEvents>b__23_3 (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly,UnityEditor.Compilation.CompilerMessage[],UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions)
UnityEditor.Scripting.ScriptCompilation.EditorCompilation:InvokeAssemblyCompilationFinished (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly,System.Collections.Generic.List`1<UnityEditor.Scripting.Compilers.CompilerMessage>,UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions)
UnityEditor.Scripting.ScriptCompilation.EditorCompilation/<>c__DisplayClass151_0:<CompileScriptAssemblies>b__5 (UnityEditor.Scripting.ScriptCompilation.ScriptAssembly,System.Collections.Generic.List`1<UnityEditor.Scripting.Compilers.CompilerMessage>)
UnityEditor.Scripting.ScriptCompilation.CompilationTask:Poll ()
UnityEditor.Scripting.ScriptCompilation.EditorCompilation:PollCompilation ()
UnityEditor.Scripting.ScriptCompilation.EditorCompilation:TickCompilationPipeline (UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,string[])
UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:TickCompilationPipeline (UnityEditor.Scripting.ScriptCompilation.EditorScriptCompilationOptions,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,string[])

(Filename: Assets/Plugins/Mirror/Editor/Weaver/CompilationFinishedHook.cs Line: 95)

Weaving via ILPostProcessor should fix this: https://github.com/vis2k/Mirror/pull/2891 PR is almost finished. please test if you get a chance and report back.