Skip to content

AssetImportWorker crash in CommandRegistry.AutoDiscoverCommands during domain reload #1134

@jonlepage

Description

@jonlepage

The AssetImportWorker crashes during domain reload when CommandRegistry
scans assemblies via reflection in its [InitializeOnLoad] static constructor.

The crash occurs at CommandRegistry.cs:72 inside AutoDiscoverCommands(),
when calling GetCustomAttribute() on a type that is not fully loaded
in the worker process context. This triggers a native crash in
mono_class_from_mono_type_internal (access violation).

This happens intermittently during script recompilation and can destabilize
the main Editor process (freezes, force-kill required).

Actual result:

  • Editor freezes (stops responding to Windows) or crashes with access violation
  • Windows Event Viewer shows:
    Application Error: Unity.exe 6000.4.1.13702
    Faulting module: unknown (0.0.0.0)
    Exception code: 0xc0000005 (STATUS_ACCESS_VIOLATION)
    Fault offset: 0x0000028e84cdf218
  • No crash stack trace in Editor.log (log ends with normal scene unload)
  • "Saving Failed" dialog sometimes appears: "You are trying to save a Prefab with a missing script"
  • After force-kill: "Prefab Has Been Changed on Disk" dialog on relaunch
  • 3 incidents in single session confirmed via Windows Application Event Log:
    17:53 - Application Error (crash 0xc0000005)
    15:25 - Application Hang (freeze, force-killed)
    14:48 - Application Hang (freeze, force-killed)

Stack trace origin: Logs/AssetImportWorker2.log
Unity version: 6000.4.1f1
Plugin version: com.coplaydev.unity-mcp@13fb3ee12774

The AssetImportWorker2 has crashed. Please report a bug with the following Stack Trace:
========== OUTPUTTING STACK TRACE ==================

0x00007FF94394AA4E (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\class.c:2169] mono_class_from_mono_type_internal 
0x00007FF9439C7C9A (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\icall-def.h:921] ves_icall_RuntimeTypeHandle_GetAttributes_raw 
0x000001CC4084E096 (Mono JIT Code) (wrapper managed-to-native) System.RuntimeTypeHandle:GetAttributes (System.RuntimeType)
0x000001CC4084DFDB (Mono JIT Code) System.RuntimeType:GetAttributeFlagsImpl ()
0x000001CC41D497D8 (Mono JIT Code) System.Type:get_IsPublic ()
0x000001CC41D49723 (Mono JIT Code) System.RuntimeType:get_MemberType ()
0x000001CC41D48F97 (Mono JIT Code) System.Attribute:GetCustomAttributes (System.Reflection.MemberInfo,System.Type,bool)
0x000001CC41D48E1B (Mono JIT Code) System.Attribute:GetCustomAttribute (System.Reflection.MemberInfo,System.Type,bool)
0x000001CC41D48DA3 (Mono JIT Code) System.Attribute:GetCustomAttribute (System.Reflection.MemberInfo,System.Type)
0x000001CC421AC993 (Mono JIT Code) System.Reflection.CustomAttributeExtensions:GetCustomAttribute (System.Reflection.MemberInfo,System.Type)
0x000001CC421AC8FB (Mono JIT Code) System.Reflection.CustomAttributeExtensions:GetCustomAttribute<T_REF> (System.Reflection.MemberInfo)
0x000001CC72776A5B (Mono JIT Code) [.\Library\PackageCache\com.coplaydev.unity-mcp@13fb3ee12774\Editor\Tools\CommandRegistry.cs:72] MCPForUnity.Editor.Tools.CommandRegistry/<>c:<AutoDiscoverCommands>b__4_2 (System.Type) 
0x000001CC727506D2 (Mono JIT Code) System.Linq.Enumerable/WhereListIterator`1<TSource_REF>:MoveNext ()
0x000001CC72775A03 (Mono JIT Code) [.\Library\PackageCache\com.coplaydev.unity-mcp@13fb3ee12774\Editor\Tools\CommandRegistry.cs:74] MCPForUnity.Editor.Tools.CommandRegistry:AutoDiscoverCommands () 
0x000001CC7277533B (Mono JIT Code) [.\Library\PackageCache\com.coplaydev.unity-mcp@13fb3ee12774\Editor\Tools\CommandRegistry.cs:50] MCPForUnity.Editor.Tools.CommandRegistry:Initialize () 
0x000001CC7277518B (Mono JIT Code) [.\Library\PackageCache\com.coplaydev.unity-mcp@13fb3ee12774\Editor\Services\Transport\TransportCommandDispatcher.cs:204] MCPForUnity.Editor.Services.Transport.TransportCommandDispatcher:EnsureInitialised () 
0x000001CC72774E43 (Mono JIT Code) [.\Library\PackageCache\com.coplaydev.unity-mcp@13fb3ee12774\Editor\Services\Transport\TransportCommandDispatcher.cs:80] MCPForUnity.Editor.Services.Transport.TransportCommandDispatcher:.cctor () 
0x000001CC726FF085 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
0x00007FF943B16C0E (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\mini\mini-runtime.c:3445] mono_jit_runtime_invoke 
0x00007FF943A58984 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:3068] do_runtime_invoke 
0x00007FF943A53965 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:563] mono_runtime_class_init_full 
0x00007FF943989FB7 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\icall.c:1292] ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor 
0x00007FF9439BCBDC (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\icall-def.h:756] ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor_raw 
0x000001CC7264A64A (Mono JIT Code) (wrapper managed-to-native) System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor (intptr)
0x000001CC7264A53B (Mono JIT Code) System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor (System.RuntimeTypeHandle)
0x000001CC726484E3 (Mono JIT Code) UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])
0x000001CC40834FF8 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_object (object,intptr,intptr,intptr)
0x00007FF943B16C0E (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\mini\mini-runtime.c:3445] mono_jit_runtime_invoke 
0x00007FF943A58984 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:3068] do_runtime_invoke 
0x00007FF943A58A70 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:3115] mono_runtime_invoke 
0x00007FF92A5ECDE5 (Unity) scripting_method_invoke
0x00007FF92A61558E (Unity) ScriptingInvocation::Invoke
0x00007FF92A610DE5 (Unity) ScriptingInvocation::Invoke<void>
0x00007FF928578B39 (Unity) Scripting::UnityEditor::EditorAssembliesProxy::ProcessInitializeOnLoadAttributes
0x00007FF92A636D2F (Unity) ProcessInitializeOnLoadAttributes
0x00007FF92A621F3B (Unity) SerializationScopeTriggers::AfterManagedObjectsRestored
0x00007FF92A648573 (Unity) CodeReloadSerialization::RestoreAndAwakeManagedObjects
0x00007FF92A632387 (Unity) MonoManager::FinalizeReload
0x00007FF9282527B4 (Unity) ScriptingInitializer::FinalizeReload
0x00007FF92822A817 (Unity) AssetImportWorkerClient::ReloadScriptingDomain
0x00007FF928206A79 (Unity) <lambda_f55cddbce21fc3bda72fa6c8798fa7fa>::operator()
0x00007FF9281451CC (Unity) asio::detail::executor_op<asio::detail::binder0<core::mutable_function<void __cdecl(void)> >,std::allocator<void>,asio::detail::win_iocp_operation>::do_complete
0x00007FF928148061 (Unity) asio::detail::win_iocp_io_context::do_one
0x00007FF92814D266 (Unity) asio::detail::win_iocp_io_context::run
0x00007FF928142F66 (Unity) IOService::Run
0x00007FF92822E6AC (Unity) RunAssetImportWorkerClientV2
0x00007FF92822E76B (Unity) RunAssetImporterV2
0x00007FF928E8D7B3 (Unity) Application::InitializeProject
0x00007FF928895503 (Unity) UnityMain
0x00007FF68EDB2F2A (Unity) __scrt_common_main_seh
0x00007FF9E37A7374 (KERNEL32) BaseThreadInitThunk
0x00007FF9E57DCC91 (ntdll) RtlUserThreadStart

========== END OF STACKTRACE ===========
 -- for more information, check Logs/AssetImportWorker2.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions