Mono: WinForms example not working

Created on 27 Jun 2019  Â·  4Comments  Â·  Source: mono/mono

The WinForms Example found here does not work:

Steps to Reproduce

  1. Copy the source found here
  2. Create a file called Hello.cs and paste the source
  3. Compile it: csc Hello.cs -r:System.Windows.Forms.dll
  4. Run it using mono mono Hello.exe

Current Behavior

mono ./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

=================================================================

Native Crash Reporting

Got a SIGSEGV 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 (0x7fff550d7982):0x7fff550d7972 53 50 48 89 fb 48 8b 05 ba f6 09 3c 48 8b 48 18 SPH..H..... 0x7fff550d7982 48 89 4f 18 48 8b 48 10 48 89 4f 10 48 8b 08 48 H.O.H.H.H.O.H..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

=================================================================

Native stacktrace:

 (No frames)

=================================================================

Telemetry Dumper:

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:

=================================================================

External Debugger Dump:

(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

  • thread #1, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x00007fff5bdf6356 libsystem_kernel.dylib__wait4 + 10 libsystem_kernel.dylib__wait4:
    -> 0x7fff5bdf6356 <+10>: jae 0x7fff5bdf6360 ; <+20>
    0x7fff5bdf6358 <+12>: movq %rax, %rdi
    0x7fff5bdf635b <+15>: jmp 0x7fff5bdf1421 ; cerror
    0x7fff5bdf6360 <+20>: retq
    Target 0: (mono) stopped.

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

  • thread #1: tid = 0x1434967, 0x00007fff5bdf6356 libsystem_kernel.dylib__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'
    thread #3: tid = 0x1434969, 0x00007fff5bdf1266 libsystem_kernel.dylibsemaphore_wait_trap + 10, name = 'Finalizer' thread #4: tid = 0x143496a, 0x00007fff5bdf2bfe libsystem_kernel.dylib__workq_kernreturn + 10
    thread #5: tid = 0x143496c, 0x00007fff5bdf2bfe libsystem_kernel.dylib`__workq_kernreturn + 10
    thread #6: tid = 0x1434982, 0x0000000000000000
    (lldb) thread backtrace all
  • thread #1, name = 'tid_307', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP

    • frame #0: 0x00007fff5bdf6356 libsystem_kernel.dylib__wait4 + 10 frame #1: 0x000000010ab39d60 monomono_dump_native_crash_info at mini-posix.c:1112:3 [opt]

      frame #2: 0x000000010ab39aa4 monomono_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]

      frame #4: 0x000000010aa32a95 monomono_sigsegv_signal_handler(_dummy=<unavailable>, _info=0x000000010afe7ee0, context=0x000000010afe7f48) at mini-runtime.c:3488:4 [opt] frame #5: 0x00007fff5bea7b5d libsystem_platform.dylib_sigtramp + 29

      frame #6: 0x00007fff550d7983 SkyLightSLDisplayBounds + 21 frame #7: 0x0000000111f41cde frame #8: 0x000000010afd1ae6 frame #9: 0x000000010aa35f23 monomono_jit_runtime_invoke(method=, obj=, params=0x0000000000000000, exc=0x0000000111f41710, error=) at mini-runtime.c:3148:12 [opt]

      frame #10: 0x000000010ac343e4 monodo_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=, obj=, params=, error=0x00007ffee51daab8) at object.c:3069:9 [opt]

      frame #12: 0x000000010ac30377 monomono_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=, error=0x00007ffee51daab8) at mini.c:4184:8 [opt]

      frame #14: 0x000000010aa319a9 monomono_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=, m=0x00007fa4cb84c658, vt=0x0000000000000000, vtable_slot=, error=0x00007ffee51daab8) at mini-trampolines.c:755:27 [opt]

      frame #16: 0x000000010aadfdc9 monomono_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

      frame #1: 0x00007fff5beb356e libsystem_pthread.dylib_pthread_cond_wait + 722 frame #2: 0x000000010ad0142e monothread_func [inlined] mono_os_cond_wait(mutex=) at mono-os-mutex.h:173:8 [opt]

      frame #3: 0x000000010ad0141b monothread_func at sgen-thread-pool.c:165 [opt] frame #4: 0x000000010ad0140d monothread_func(data=0x0000000000000000) at sgen-thread-pool.c:196 [opt]

      frame #5: 0x00007fff5beb02eb libsystem_pthread.dylib_pthread_body + 126 frame #6: 0x00007fff5beb3249 libsystem_pthread.dylib_pthread_start + 66

      frame #7: 0x00007fff5beaf40d libsystem_pthread.dylibthread_start + 13 thread #3, name = 'Finalizer' frame #0: 0x00007fff5bdf1266 libsystem_kernel.dylibsemaphore_wait_trap + 10

      frame #1: 0x000000010acaecea monofinalizer_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]

      frame #3: 0x000000010acaecc5 monofinalizer_thread(unused=<unavailable>) at gc.c:918 [opt] frame #4: 0x000000010ac5a163 monostart_wrapper [inlined] start_wrapper_internal at threads.c:1155:3 [opt]

      frame #5: 0x000000010ac5a0d3 monostart_wrapper(data=0x00007fa4c970ee70) at threads.c:1215 [opt] frame #6: 0x00007fff5beb02eb libsystem_pthread.dylib_pthread_body + 126

      frame #7: 0x00007fff5beb3249 libsystem_pthread.dylib_pthread_start + 66 frame #8: 0x00007fff5beaf40d libsystem_pthread.dylibthread_start + 13

      thread #4

      frame #0: 0x00007fff5bdf2bfe libsystem_kernel.dylib__workq_kernreturn + 10 frame #1: 0x00007fff5beaf6e6 libsystem_pthread.dylib_pthread_wqthread + 634

      frame #2: 0x00007fff5beaf3fd libsystem_pthread.dylibstart_wqthread + 13 thread #5 frame #0: 0x00007fff5bdf2bfe libsystem_kernel.dylib__workq_kernreturn + 10

      frame #1: 0x00007fff5beaf636 libsystem_pthread.dylib_pthread_wqthread + 458 frame #2: 0x00007fff5beaf3fd libsystem_pthread.dylibstart_wqthread + 13

      thread #6

      frame #0: 0x0000000000000000

      (lldb) detach

      Process 24881 detached

      (lldb) quit

=================================================================

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

Expected Behavior

On which platforms did you notice this

  • [x] macOS Mojave 10.14.5
  • [ ] Linux
  • [ ] Windows

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)

Stacktrace

=================================================================
    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
System.Windows.Forms

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.

All 4 comments

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

  1. note that the executable for macs is mono32 (or mono --arch=32)
  2. tell the reader that the documented method to run the Hello program is only for macOS 10.14 and earlier. Not macOS 10.15 Catalina.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

callmekohei picture callmekohei  Â·  3Comments

decriptor picture decriptor  Â·  4Comments

pjeutr picture pjeutr  Â·  5Comments

JoseTiagoCarvalho picture JoseTiagoCarvalho  Â·  3Comments

equalent picture equalent  Â·  4Comments