You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Visual Studio for Mac中Xamarin Cocoa App无法连接调试器且运行时崩溃求助

Fix for "could not connect to the debugger" & "System.Reflection.CustomAttributeData not found" in Xamarin Cocoa App on VS for Mac

Let's break down how to resolve this issue based on your crash log and the steps you've already tried. The core problem here is that the Mono runtime can't find a critical system type (System.Reflection.CustomAttributeData) during initialization, which is causing the app to crash before the debugger can attach.

Quick Fix Steps

First, try these straightforward steps to rule out common configuration issues:

  • Clean and rebuild your project: Delete the bin and obj folders in your project directory, then go to Build > Clean Solution followed by Build > Rebuild Solution in VS for Mac.
  • Set linker behavior to "Don't Link": For debugging, the linker can sometimes strip out critical system types. Go to your project options → Build > Mac > Linker Behavior and select Don't Link.
  • Verify target framework: Ensure you're targeting a stable, compatible framework (e.g., .NET 6+ or the latest Xamarin.Mac SDK version). Check this in Project Options > General > Target Framework.

Detailed Troubleshooting

If the quick fixes don't work, dive into these specific configurations:

1. Adjust Debugger Configuration

  • Right-click your project → Options > Run > Debug
  • Set Debugger Type to Mono (this ensures the correct debugger attaches to the Mono runtime)
  • Uncheck any "Optimize code" options in the debug configuration—optimizations can interfere with debugger attachment.

2. Fix Assembly References

The missing CustomAttributeData type is part of the core System.Reflection assembly. Ensure your project has the correct references:

  • Right-click your project → References
  • Confirm that System.Reflection and System.Reflection.Extensions are listed. If not, add them via Add > Reference > Assemblies > Framework.

3. Reset Xamarin/Mono Runtime Cache

Sometimes cached runtime files can become corrupted:

  • Close VS for Mac
  • Open Terminal and run:
    rm -rf ~/Library/Caches/Xamarin/
    rm -rf ~/Library/VisualStudio/<your_VS_version>/ComponentModelCache/
    
  • Restart VS for Mac and try launching your app again.

Crash Log Analysis

Your crash log clearly points to the root cause:

Runtime critical type System.Reflection.CustomAttributeData not found

This happens when either:

  • The linker has removed this type (thinking it's unused), which is why setting linker behavior to "Don't Link" often fixes it.
  • Your target framework version is incompatible with the Xamarin.Mac SDK you're using, leading to missing system types.

Original Crash Log

Runtime critical type System.Reflection.CustomAttributeData not found
=================================================================
Native Crash Reporting
=================================================================
Got a SIGABRT while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application.
=================================================================

=================================================================
Basic Fault Adddress Reporting
=================================================================
Memory around native instruction pointer (0x7fff74a15b66):0x7fff74a15b56 ff ff c3 90 90 90 b8 48 01 00 02 49 89 ca 0f 05 .......H...I....
0x7fff74a15b66 73 08 48 89 c7 e9 75 6f ff ff c3 90 90 90 b8 4c s.H...uo.......L
0x7fff74a15b76 01 00 02 49 89 ca 0f 05 73 08 48 89 c7 e9 5d 6f ...I....s.H...]o
0x7fff74a15b86 ff ff c3 90 90 90 b8 49 01 00 02 49 89 ca 0f 05 .......I...I....
===================== Debug info from gdb:
=================================================================
External Debugger Dump:
=================================================================
============================================
Native stacktrace:
=================================================================
0x1029fd078 - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : mono_dump_native_crash_info
0x1029f0c15 - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : mono_handle_native_crash
0x7fff74bd3f5a - /usr/lib/system/libsystem_platform.dylib : _sigtramp
0x1118eb768 - Unknown
0x7fff749711ae - /usr/lib/system/libsystem_c.dylib : abort
0x102c22577 - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : monoeg_assert_abort
0x102c077bf - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : mono_log_write_logfile
0x102c228fe - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : monoeg_g_logv_nofree
0x102c229b2 - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : monoeg_g_log
0x102aa44a5 - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : mono_class_load_from_name
0x102ac14dc - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : mono_init_internal
0x102a05326 - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : mini_init
0x10295ee63 - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : mono_main
0x10291b2bc - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : xamarin_main
0x10291c0e4 - /Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj : main
0x7fff748c5015 - /usr/lib/system/libdyld.dylib : start
0x2 - Unknown
=================================================================
Telemetry Dumper:
=================================================================
(lldb) command source -s 0 '/tmp/mono-gdb-commands.8523'
Executing commands in '/tmp/mono-gdb-commands.8523'.
(lldb) process attach --pid 8523
Process 8523 stopped
* thread #1, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
frame #0: 0x00007fff74a1622a libsystem_kernel.dylib`__wait4 + 10
libsystem_kernel.dylib`__wait4:
-> 0x7fff74a1622a <+10>: jae 0x7fff74a16234 ; <+20>
0x7fff74a1622c <+12>: movq %rax, %rdi
0x7fff74a1622f <+15>: jmp 0x7fff74a0cb0a ; cerror
0x7fff74a16234 <+20>: retq
Target 0: (abcproj) stopped.
Executable module set to "/Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MacOS/abcproj".
Architecture set to: x86_64-apple-macosx.
(lldb) thread list
Process 8523 stopped
* thread #1: tid = 0x5ca84, 0x00007fff74a1622a libsystem_kernel.dylib`__wait4 + 10, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
thread #2: tid = 0x5ca9b, 0x00007fff74a1628a libsystem_kernel.dylib`__workq_kernreturn + 10
thread #3: tid = 0x5ca9c, 0x00007fff74a1628a libsystem_kernel.dylib`__workq_kernreturn + 10
thread #4: tid = 0x5caa1, 0x00007fff74a15a16 libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker'
(lldb) thread backtrace all
* thread #1, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
* frame #0: 0x00007fff74a1622a libsystem_kernel.dylib`__wait4 + 10
frame #1: 0x00000001029fd2d0 abcproj`mono_dump_native_crash_info at mini-posix.c:1112 [opt]
frame #2: 0x00000001029fd014 abcproj`mono_dump_native_crash_info(signal=<unavailable>, ctx=<unavailable>, info=<unavailable>) at mini-posix.c:1149 [opt]
frame #3: 0x00000001029f0c15 abcproj`mono_handle_native_crash(signal="SIGABRT", ctx=0x00007ffeed2f4940, info=0x00007ffeed2f48d8) at mini-exceptions.c:3290 [opt]
frame #4: 0x00007fff74bd3f5a libsystem_platform.dylib`_sigtramp + 26
frame #5: 0x00007fff74a15b67 libsystem_kernel.dylib`__pthread_kill + 11
frame #6: 0x00007fff74be0080 libsystem_pthread.dylib`pthread_kill + 333
frame #7: 0x00007fff749711ae libsystem_c.dylib`abort + 127
frame #8: 0x0000000102c22577 abcproj`monoeg_assert_abort at goutput.c:57 [opt]
frame #9: 0x0000000102c077bf abcproj`mono_log_write_logfile(log_domain=<unavailable>, level=<unavailable>, hdr=<unavailable>, message="Runtime critical type System.Reflection.CustomAttributeData not found") at mono-log-common.c:135 [opt]
frame #10: 0x0000000102c228fe abcproj`monoeg_g_logv_nofree [inlined] monoeg_g_logstr(log_domain=0x0000000000000000, log_level=G_LOG_LEVEL_ERROR, msg=<unavailable>) at goutput.c:134 [opt]
frame #11: 0x0000000102c228d5 abcproj`monoeg_g_logv_nofree(log_domain=0x0000000000000000, log_level=G_LOG_LEVEL_ERROR, format="Runtime critical type %s.%s not found", args=<unavailable>) at goutput.c:149 [opt]
frame #12: 0x0000000102c229b2 abcproj`monoeg_g_log [inlined] monoeg_g_logv(log_domain=<unavailable>, log_level=<unavailable>, format=<unavailable>, args=<unavailable>) at goutput.c:156 [opt]
frame #13: 0x0000000102c229ad abcproj`monoeg_g_log(log_domain=<unavailable>, log_level=<unavailable>, format=<unavailable>) at goutput.c:165 [opt]
frame #14: 0x0000000102aa44a5 abcproj`mono_class_load_from_name(image=<unavailable>, name_space="System.Reflection", name="CustomAttributeData") at class.c:3157 [opt]
frame #15: 0x0000000102ac14dc abcproj`mono_init_internal(filename=<unavailable>, exe_filename=<unavailable>, runtime_version=<unavailable>) at domain.c:764 [opt]
frame #16: 0x0000000102a05326 abcproj`mini_init(filename="/Users/macbookpro/Projects/abcproj/abcproj/bin/Debug/abcproj.app/Contents/MonoBundle/abcproj.exe", runtime_version="mobile") at mini-runtime.c:4426 [opt]
frame #17: 0x000000010295ee63 abcproj`mono_main(argc=6, argv=0x0000604000068180) at driver.g.c:2324 [opt]
frame #18: 0x000000010291b2bc abcproj`::xamarin_main(argc=2, argv=0x00007ffeed2f5650, launch_mode=XamarinLaunchModeApp) at launcher.m:647
frame #19: 0x000000010291c0e4 abcproj`main(argc=2, argv=0x00007ffeed2f5650) at launcher.m:666
frame #20: 0x00007fff748c5015 libdyld.dylib`start + 1
thread #2
frame #0: 0x00007fff74a1628a libsystem_kernel.dylib`__workq_kernreturn + 10
frame #1: 0x00007fff74bdd009 libsystem_pthread.dylib`_pthread_wqthread + 1035
frame #2: 0x00007fff74bdcbe9 libsystem_pthread.dylib`start_wqthread + 13
thread #3
frame #0: 0x00007fff74a1628a libsystem_kernel.dylib`__workq_kernreturn + 10
frame #1: 0x00007fff74bdd20e libsystem_pthread.dylib`_pthread_wqthread + 1552
frame #2: 0x00007fff74bdcbe9 libsystem_pthread.dylib`start_wqthread + 13
thread #4, name = 'SGen worker'
frame #0: 0x00007fff74a15a16 libsystem_kernel.dylib`__psynch_cvwait + 10
frame #1: 0x00007fff74bde589 libsystem_pthread.dylib`_pthread_cond_wait + 732
frame #2: 0x0000000102bf878e abcproj`thread_func [inlined] mono_os_cond_wait(mutex=<unavailable>) at mono-os-mutex.h:173 [opt]
frame #3: 0x0000000102bf877b abcproj`thread_func at sgen-thread-pool.c:165 [opt]
frame #4: 0x0000000102bf876d abcproj`thread_func(data=0x0000000000000000) at sgen-thread-pool.c:196 [opt]
frame #5: 0x00007fff74bdd661 libsystem_pthread.dylib`_pthread_body + 340
frame #6: 0x00007fff74bdd50d libsystem_pthread.dylib`_pthread_start + 377

火山引擎 最新活动