C# 在Mono for ARM上运行简单的winforms应用程序

C# 在Mono for ARM上运行简单的winforms应用程序,c#,mono,arm,cross-compiling,beagleboneblack,C#,Mono,Arm,Cross Compiling,Beagleboneblack,我目前正在尝试建立一个环境,在这个环境中,我可以使用Visual Studio 2013创建winform应用程序,然后我想将其安装在ARM v7 BeagleBone Black上,并附带一个触摸屏,在那里它们应该使用Mono运行 为此,我采用了Ubuntu 14.10 AMD64系统,并使用BeagleBone Black的工具链和scratchbox2创建了一个交叉编译环境 我用它编译了一些本机测试程序,从而验证了工具链an sb2的工作是否正确,它们在Ubuntu机器(使用sb2)和Be

我目前正在尝试建立一个环境,在这个环境中,我可以使用Visual Studio 2013创建winform应用程序,然后我想将其安装在ARM v7 BeagleBone Black上,并附带一个触摸屏,在那里它们应该使用Mono运行

为此,我采用了Ubuntu 14.10 AMD64系统,并使用BeagleBone Black的工具链和scratchbox2创建了一个交叉编译环境

我用它编译了一些本机测试程序,从而验证了工具链an sb2的工作是否正确,它们在Ubuntu机器(使用sb2)和BeagleBone Black上都可以完美地运行

接下来,我从源代码处编译了mono,一次用于Ubuntu机器,一次用于BeagleBone Black。为此,我主要遵循了。最后,我得到了一个包含完整mono树的目录,它的本机组件已经为ARM正确编译。我通过在Ubuntu系统上运行
sb2 mono-V
以及将mono目录复制到BeagleBone Black上后在BeagleBone Black上运行
mono-V
验证了这一点。我还可以在BBB的mono上运行我用VS2013创建的简单.NET控制台应用程序

接下来,我尝试运行一个简单的GUI应用程序,它基本上只包含一个表单和一个弹出messagebox的按钮。VS中的项目设置被设置为.NET Framework版本4.5和“版本”

接下来,我尝试在Ubuntu系统上使用mono运行这个EXE,在调整了./configure选项、重新编译mono(--with tls=_线程)并安装了所需的库(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 
更新:我刚刚注意到一个名为
mono测试安装的小型mono实用程序。当我在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测试安装所显示的错误。此外,我还必须编辑文件
[mono directory]/usr/local/bin/mcs
,并更正可执行文件的路径。我假设您可以在配置mono时使用
前缀=…
自动设置它们,但我没有这样做

现在,当我运行
mono测试安装时

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测试程序时,我得到了与上面给出的完全相同的异常

经过一番搜索,我发现可能有一个问题,因为我不是第一个遇到这个问题的人。然而,奇怪的是,同样的EXE在Ubuntu上以同样的mono版本完美地运行(只是为amd64而不是armv7编译,配置选项相同)。所以在PC上一切正常,在arm上崩溃


更新:我提交了一份报告,附带了一个产生问题的示例项目。

一点挖掘表明,当宽度或高度为非正数时,GDI+返回
InvalidParameter

Gong表示当首选光标大小(由libX11中的
XQueryBestCursor
报告)与原始光标大小(32x32像素)不同时,从X11驱动程序调用
Bitmap
构造函数

因此,您的BeagleBone上的
XQueryBestCursor()
为光标返回零宽度/高度。在谷歌上搜索一下,我们就有机会描述一个类似的问题。那里甚至有一些补丁

我认为您应该使用提供的补丁在BeagleBone上重新编译X11,或者在mono source中添加一些检查(在调用
XQueryBestCursor
)以便在X11返回零宽度/高度时使用光标的原始宽度/高度


UPD:HW光标大小似乎是由视频驱动程序实际报告的,所以您可能只需尝试另一个,比如最近的xf86视频fbdev。

可能是一个愚蠢的建议,但如果您将.NET Framework版本降低到3.5会发生什么?我尝试过,它也不起作用。请尝试以获得更多(错误)另一个问题:在使用mono编译(VS2013)解决方案之前,您是否清理了它?如果没有,请删除bin文件夹和(如果使用)系统。部署参考。然后在mono中再次编译。这可能有帮助:
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