The WinForms Example found here does not work:
Hello.cs and paste the sourcecsc Hello.cs -r:System.Windows.Forms.dllmono Hello.exemono ./Hello.exe Output
WARNING: The Carbon driver has not been ported to 64bits, and very few parts of Windows.Forms will work properly, or at all
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
=================================================================
Memory around native instruction pointer (0x7fff550d7982):0x7fff550d7972 53 50 48 89 fb 48 8b 05 ba f6 09 3c 48 8b 48 18 SPH..H.....
0x7fff550d7992 8b 40 08 48 89 47 08 48 89 0f 89 f7 48 89 de e8 [email protected]...
0x7fff550d79a2 54 4b fc ff 48 89 d8 48 83 c4 08 5b 5d c3 55 48 TK..H..H...[].UH
=================================================================
(No frames)
=================================================================
Pkilling 0x700009f9f000 from 0x1121855c0
Entering thread summarizer pause from 0x1121855c0
Finished thread summarizer pause from 0x1121855c0.
Waiting for dumping threads to resume
Debug info from gdb:
=================================================================
(lldb) command source -s 0 '/tmp/mono-gdb-commands.24881'
Executing commands in '/tmp/mono-gdb-commands.24881'.
(lldb) process attach --pid 24881
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 52, in
import weakref
File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 14, in
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
warning: (x86_64) /Library/Frameworks/Mono.framework/Versions/5.18.1/lib/mono/4.5/mscorlib.dll.dylib empty dSYM file detected, dSYM was created with an executable with no debug info.
warning: (x86_64) /Library/Frameworks/Mono.framework/Versions/5.18.1/lib/libglib-2.0.0.dylib empty dSYM file detected, dSYM was created with an executable with no debug info.
Process 24881 stopped
__wait4 + 10
libsystem_kernel.dylib__wait4:Executable module set to "/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono".
Architecture set to: x86_64h-apple-macosx-.
(lldb) thread list
Process 24881 stopped
__wait4 + 10, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
thread #2: tid = 0x1434968, 0x00007fff5bdf486a libsystem_kernel.dylib__psynch_cvwait + 10, name = 'SGen worker'semaphore_wait_trap + 10, name = 'Finalizer'
thread #4: tid = 0x143496a, 0x00007fff5bdf2bfe libsystem_kernel.dylib__workq_kernreturn + 10__wait4 + 10
frame #1: 0x000000010ab39d60 monomono_dump_native_crash_info at mini-posix.c:1112:3 [opt]mono_dump_native_crash_info(signal=<unavailable>, ctx=<unavailable>, info=<unavailable>) at mini-posix.c:1149 [opt]
frame #3: 0x000000010aadd215 monomono_handle_native_crash(signal="SIGSEGV", ctx=0x000000010afe7f48, info=0x000000010afe7ee0) at mini-exceptions.c:3290:2 [opt]mono_sigsegv_signal_handler(_dummy=<unavailable>, _info=0x000000010afe7ee0, context=0x000000010afe7f48) at mini-runtime.c:3488:4 [opt]
frame #5: 0x00007fff5bea7b5d libsystem_platform.dylib_sigtramp + 29SLDisplayBounds + 21
frame #7: 0x0000000111f41cde
frame #8: 0x000000010afd1ae6
frame #9: 0x000000010aa35f23 monomono_jit_runtime_invoke(method=do_runtime_invoke(method=0x00007fa4cb84c7d0, obj=0x0000000000000000, params=0x0000000000000000, exc=0x00007ffee51da8d8, error=0x00007ffee51daab8) at object.c:2960:11 [opt]
frame #11: 0x000000010ac303b8 monomono_runtime_class_init_full [inlined] mono_runtime_try_invoke(method=mono_runtime_class_init_full(vtable=0x00007fa4cb87b2b8, error=0x00007ffee51daab8) at object.c:526 [opt]
frame #13: 0x000000010aa2e465 monomono_jit_compile_method_inner(method=0x00007fa4cb84c658, target_domain=0x00007fa4ca1055c0, opt=mono_jit_compile_method_with_opt(method=0x00007fa4cb84c658, opt=<unavailable>, jit_only=0, error=0x00007ffee51daab8) at mini-runtime.c:2411:10 [opt]
frame #15: 0x000000010aae0384 monocommon_call_trampoline(regs=0x00007ffee51dab88, code=mono_magic_trampoline(regs=0x00007ffee51dab88, code="H\x8dt$HH\x8b�8, arg=0x00007fa4cb84c658, tramp=<unavailable>) at mini-trampolines.c:895:8 [opt]
frame #17: 0x000000010aef0393
thread #2, name = 'SGen worker'
frame #0: 0x00007fff5bdf486a libsystem_kernel.dylib__psynch_cvwait + 10_pthread_cond_wait + 722
frame #2: 0x000000010ad0142e monothread_func [inlined] mono_os_cond_wait(mutex=thread_func at sgen-thread-pool.c:165 [opt]
frame #4: 0x000000010ad0140d monothread_func(data=0x0000000000000000) at sgen-thread-pool.c:196 [opt]_pthread_body + 126
frame #6: 0x00007fff5beb3249 libsystem_pthread.dylib_pthread_start + 66thread_start + 13
thread #3, name = 'Finalizer'
frame #0: 0x00007fff5bdf1266 libsystem_kernel.dylibsemaphore_wait_trap + 10finalizer_thread [inlined] mono_os_sem_wait(flags=MONO_SEM_FLAGS_ALERTABLE) at mono-os-semaphore.h:90:8 [opt]
frame #2: 0x000000010acaecdf monofinalizer_thread at mono-coop-semaphore.h:43 [opt]finalizer_thread(unused=<unavailable>) at gc.c:918 [opt]
frame #4: 0x000000010ac5a163 monostart_wrapper [inlined] start_wrapper_internal at threads.c:1155:3 [opt]start_wrapper(data=0x00007fa4c970ee70) at threads.c:1215 [opt]
frame #6: 0x00007fff5beb02eb libsystem_pthread.dylib_pthread_body + 126_pthread_start + 66
frame #8: 0x00007fff5beaf40d libsystem_pthread.dylibthread_start + 13__workq_kernreturn + 10
frame #1: 0x00007fff5beaf6e6 libsystem_pthread.dylib_pthread_wqthread + 634start_wqthread + 13
thread #5
frame #0: 0x00007fff5bdf2bfe libsystem_kernel.dylib__workq_kernreturn + 10_pthread_wqthread + 458
frame #2: 0x00007fff5beaf3fd libsystem_pthread.dylibstart_wqthread + 13=================================================================
at <unknown> <0xffffffff>
at System.Windows.Forms.XplatUICarbon:CGDisplayBounds <0x0006d>
at System.Windows.Forms.XplatUICarbon:get_WorkingArea <0x00052>
at System.Windows.Forms.XplatUICarbon:get_VirtualScreen <0x00020>
at System.Windows.Forms.XplatUI:get_VirtualScreen <0x00025>
at System.Windows.Forms.Screen:.cctor <0x0013a>
at System.Object:runtime_invoke_void <0x00075>
at <unknown> <0xffffffff>
at System.Windows.Forms.Hwnd:GetNextStackedFormLocation <0x0018a>
at System.Windows.Forms.XplatUICarbon:CreateWindow <0x0044a>
at System.Windows.Forms.XplatUI:CreateWindow <0x00024>
at System.Windows.Forms.NativeWindow:CreateHandle <0x0004a>
at System.Windows.Forms.Control:CreateHandle <0x00098>
at System.Windows.Forms.Form:CreateHandle <0x00032>
at System.Windows.Forms.Control:CreateControl <0x000a6>
at System.Windows.Forms.Control:SetVisibleCore <0x000f2>
at System.Windows.Forms.Form:SetVisibleCore <0x00222>
at System.Windows.Forms.Control:set_Visible <0x00032>
at System.Windows.Forms.Control:set_Visible <0x0008a>
at System.Windows.Forms.Application:RunLoop <0x00402>
at System.Windows.Forms.Application:Run <0x00072>
at System.Windows.Forms.Application:Run <0x0005a>
at HelloWorld:Main <0x0004a>
Abort trap: 6
Version Used:
mono --version
Mono JIT compiler version 5.18.1.28 (2018-08/223ea7ef92e Tue May 21 12:03:39 EDT 2019)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS:
SIGSEGV: altstack
Notification: kqueue
Architecture: amd64
Disabled: none
Misc: softdebug
Interpreter: yes
LLVM: yes(600)
Suspend: preemptive
GC: sgen (concurrent by default)
=================================================================
Managed Stacktrace:
=================================================================
at <unknown> <0xffffffff>
at System.Windows.Forms.XplatUICarbon:CGDisplayBounds <0x0006d>
at System.Windows.Forms.XplatUICarbon:get_WorkingArea <0x00052>
at System.Windows.Forms.XplatUICarbon:get_VirtualScreen <0x00020>
at System.Windows.Forms.XplatUI:get_VirtualScreen <0x00025>
at System.Windows.Forms.Screen:.cctor <0x0013a>
at System.Object:runtime_invoke_void <0x00075>
at <unknown> <0xffffffff>
at System.Windows.Forms.Hwnd:GetNextStackedFormLocation <0x0018a>
at System.Windows.Forms.XplatUICarbon:CreateWindow <0x0044a>
at System.Windows.Forms.XplatUI:CreateWindow <0x00024>
at System.Windows.Forms.NativeWindow:CreateHandle <0x0004a>
at System.Windows.Forms.Control:CreateHandle <0x00098>
at System.Windows.Forms.Form:CreateHandle <0x00032>
at System.Windows.Forms.Control:CreateControl <0x000a6>
at System.Windows.Forms.Control:SetVisibleCore <0x000f2>
at System.Windows.Forms.Form:SetVisibleCore <0x00222>
at System.Windows.Forms.Control:set_Visible <0x00032>
at System.Windows.Forms.Control:set_Visible <0x0008a>
at System.Windows.Forms.Application:RunLoop <0x00402>
at System.Windows.Forms.Application:Run <0x00072>
at System.Windows.Forms.Application:Run <0x0005a>
at HelloWorld:Main <0x0004a>
at System.Object:runtime_invoke_void <0x000ca>
=================================================================
Abort trap: 6
There's plethora of issue around this already (eg. https://github.com/mono/mono/issues/6701). Mono currently has only Carbon driver for WinForms on macOS. That limits it to 32-bit processes (mono32) and it likely won't work on macOS 10.15+ now. Our company maintains a fork of WinForms that has a Cocoa driver and some support for using native controls (https://github.com/emclient/mac-playground). It may be an option for you in the short term.
@filipnavara thank you for the direction and information. I feel that one of the benefits if WinForms is that one is able to compile (in a macOS computer) and easily deploy it to a windows machine.
The compilation is as simple as doing and then sending to the target computer:
csc App.cs /target:winexe /r:System.Windows.Forms.dll
Is the work done here the similar?, based on the thread that you pointed out where could start contributing?,
How does it compare to Xwt?
Before closing this issue, (as duplicate of, say, #6755 ) it might make sense to patch the documentation to
At:
https://www.mono-project.com/docs/gui/winforms/getting-started-guide/#winforms-example
https://www.mono-project.com/docs/getting-started/mono-basics/
I guess those pages are maintained in git. Is the right way to update them to send a pull request against https://github.com/mono/website or would you prefer a thread opened at https://github.com/mono/website/issues first?
Thanks, I added a note to that page.
Most helpful comment
There's plethora of issue around this already (eg. https://github.com/mono/mono/issues/6701). Mono currently has only Carbon driver for WinForms on macOS. That limits it to 32-bit processes (mono32) and it likely won't work on macOS 10.15+ now. Our company maintains a fork of WinForms that has a Cocoa driver and some support for using native controls (https://github.com/emclient/mac-playground). It may be an option for you in the short term.