在ARM架构上运行简单的Winforms应用程序(使用Mono)

9
我正在尝试建立一个环境,使用Visual Studio 2013创建winform应用程序,并在附有触摸屏的ARM v7 BeagleBone Black上运行这些应用程序,这些应用程序将使用Mono运行。为此,我使用了Ubuntu 14.10 AMD64系统,并使用BeagleBone Black的工具链和scratchbox2创建了交叉编译环境。我通过使用它编译一些本地测试程序来验证工具链和sb2是否正常,它们在Ubuntu机器(带有sb2)以及BeagleBone Black上都可以无缺地运行。接下来,我从源代码编译了mono,一次是为Ubuntu机器,一次是为BeagleBone Black。为此,我主要遵循this post。最终,我拥有了一个完整的mono树目录,其本机组件已正确编译为ARM。我通过在Ubuntu系统上运行sb2 mono -V以及在将mono目录复制到BeagleBone Black后运行mono -V来验证这一点。我还可以在BBB的mono上运行使用VS2013创建的简单.NET控制台应用程序。
下一步,我尝试运行一个简单的 GUI 应用程序,基本上只包括一个窗体和一个弹出消息框的按钮。在 VS 中,项目设置为 .NET Framework 版本 4.5 和“发布”。

接下来,我尝试在 Ubuntu 系统上使用 mono 运行此 EXE,在调整了 ./configure 选项,重新编译 mono(--with-tls=__thread)并安装所需库(libgdiplus 和 libx11)后,它可以正常工作。但是当我尝试在 BBB 上运行相同的 EXE 时,它会崩溃并显示此异常:

Unhandled Exception:
System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 
  at System.Drawing.Bitmap..ctor (Int32 width, Int32 height, PixelFormat format) [0x00000] in <filename unknown>:0 
  at System.Drawing.Bitmap..ctor (System.Drawing.Image original, Int32 width, Int32 height) [0x00000] in <filename unknown>:0 
  at System.Drawing.Bitmap..ctor (System.Drawing.Image original, Size newSize) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (System.Drawing.Image,System.Drawing.Size)
  at System.Windows.Forms.XplatUIX11.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, Color cursor_pixel, Color mask_pixel, Int32 xHotSpot, Int32 yHotSpot) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUI.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, Color cursor_pixel, Color mask_pixel, Int32 xHotSpot, Int32 yHotSpot) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Cursor.CreateCursor (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Cursor..ctor (System.Type type, System.String resource) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Cursors.get_SizeNWSE () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.SizeGrip..ctor (System.Windows.Forms.Control CapturedControl) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.SizeGrip:.ctor (System.Windows.Forms.Control)
  at System.Windows.Forms.ScrollableControl.CreateScrollbars () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ContainerControl..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form..ctor () [0x00000] in <filename unknown>:0 
  at guitest.Form1..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) guitest.Form1:.ctor ()
  at guitest.Program.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 
  at System.Drawing.Bitmap..ctor (Int32 width, Int32 height, PixelFormat format) [0x00000] in <filename unknown>:0 
  at System.Drawing.Bitmap..ctor (System.Drawing.Image original, Int32 width, Int32 height) [0x00000] in <filename unknown>:0 
  at System.Drawing.Bitmap..ctor (System.Drawing.Image original, Size newSize) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:.ctor (System.Drawing.Image,System.Drawing.Size)
  at System.Windows.Forms.XplatUIX11.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, Color cursor_pixel, Color mask_pixel, Int32 xHotSpot, Int32 yHotSpot) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUI.DefineCursor (System.Drawing.Bitmap bitmap, System.Drawing.Bitmap mask, Color cursor_pixel, Color mask_pixel, Int32 xHotSpot, Int32 yHotSpot) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Cursor.CreateCursor (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Cursor..ctor (System.Type type, System.String resource) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Cursors.get_SizeNWSE () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.SizeGrip..ctor (System.Windows.Forms.Control CapturedControl) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.SizeGrip:.ctor (System.Windows.Forms.Control)
  at System.Windows.Forms.ScrollableControl.CreateScrollbars () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ContainerControl..ctor () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form..ctor () [0x00000] in <filename unknown>:0 
  at guitest.Form1..ctor () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) guitest.Form1:.ctor ()
  at guitest.Program.Main () [0x00000] in <filename unknown>:0 

我想知道问题可能是什么?我该如何继续下去?
顺便提一下:这是BBB上的单声道版本。
Mono JIT compiler version 3.12.0 (tarball Mo 23. Feb 11:40:46 CET 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       normal
    Notifications: epoll
    Architecture:  armel,vfp+fallback
    Disabled:      none
    Misc:          softdebug 
    LLVM:          supported, not enabled.
    GC:            sgen
更新: 我刚刚注意到这个小型的单体实用程序叫做 mono-test-install。当我在BBB上运行它时,它告诉我以下内容:
./mono-test-install 
Active Mono:
Warning: pkg-config could not find mono installed on this system
No dotnet pkgconfig found, Windows.Forms, System.Drawing and others will not work

我认为这可能是我的问题。有人知道如何在这种情况下使事情顺利进行吗?我想我必须告诉mono它在哪里可以找到其库和程序集,但我不能确定...如果有人能够阐明一些问题,那就太好了。
更新2:通过创建手工制作的mono版本的相关环境变量(在此处描述),我已经成功摆脱了mono-test-install显示的错误。此外,我还必须编辑文件[mono-directory]/usr/local/bin/mcs并更正可执行文件的路径。我想当你配置mono时可以使用PREFIX=...自动设置它们,但我没有这样做。
现在,当我运行mono-test-install时,我得到以下结果:
Active Mono: /home/root/monotree_armv7/usr/local/bin/mono
Other Mono executables: /usr/local/bin/mono 

Your have a working System.Drawing setup
Your file system watcher is: System.IO.InotifyWatcher

所以我认为现在应该一切就绪,设置正确。但它仍然不起作用。当我运行我的小型winforms测试程序时,我得到与上面给出的完全相同的异常。
经过一些搜索,我发现可能有一个mono中的错误,因为我不是第一个遇到这个问题的人。然而奇怪的是,相同的EXE在Ubuntu上运行得非常顺畅,使用的是完全相同的mono版本(只是编译为amd64而不是armv7,相同的配置选项)。所以在PC上一切正常,在arm上崩溃。
更新:我提交了一个报告,并附上了一个产生问题的示例项目here

也许这是一个愚蠢的建议,但如果将.NET Framework版本降至3.5会发生什么? - Odrai
我尝试过了,也不起作用。 - Rob
尝试使用MONO_LOG_LEVEL=debug,这样您可以获得更多的(错误)信息。 - Odrai
另一个问题:在使用mono编译之前,你是否清理了(VS 2013)解决方案?如果没有,请删除bin文件夹和(如果使用)System.Deployment引用。然后在mono中重新编译。 - Odrai
这可能会有帮助:http://stackoverflow.com/questions/8686049/c-sharp-program-doesnt-work-under-mono-in-linux - Odrai
请查看我在另一个线程发布的答案:http://stackoverflow.com/a/39104944/6748622 - dougstefe
1个回答

2
一番调查后发现,当宽度或高度为非正数时,GDI+的GdipCreateBitmapFromScan0会返回InvalidParameter。
上溯堆栈跟踪表明,当首选光标大小(由libX11的XQueryBestCursor报告)与原始光标大小(32x32像素)不同时,X11驱动程序从Bitmap构造函数中调用。因此,您的BeagleBone上的XQueryBestCursor()可能会返回零宽度/高度的光标。通过一些搜索���我们找到了描述类似问题的线程。那里甚至有某种补丁。
我认为你应该在BeagleBone上重新编译X11并使用提供的补丁,或在调用后在mono源代码中添加一些检查,以便在X11返回零宽度/高度时使用光标的原始宽度/高度。

更新:硬件光标大小似乎实际上是由视频驱动程序报告的,因此你可以尝试另一个驱动程序,例如最近的xf86-video-fbdev。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接