在 Mono for ARM 上运行简单的 winforms 应用程序 [英] Running simple winforms application on Mono for ARM

查看:74
本文介绍了在 Mono for ARM 上运行简单的 winforms 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently trying to set up an environment in which I can create winform applications with Visual Studio 2013 that I then want to put on an ARM v7 BeagleBone Black with an attached touchscreen where they are supposed to run with Mono.

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

In order to do so, I took a Ubuntu 14.10 AMD64 system and created a cross-compile environment with the BeagleBone Black's toolchain and scratchbox2.

我通过用它编译一些本机测试程序来验证工具链 an sb2 可以正常工作,它们确实在 Ubuntu 机器(使用 sb2)和 BeagleBone Black 上完美运行.

I verified that the toolchain an sb2 work correctly by compiling some native test programs with it, they do run flawlessly on the Ubuntu machine (with sb2) as well as on the BeagleBone Black.

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

Next, I compiled mono from source, once for the Ubuntu machine and also once for the BeagleBone Black. To do so, I mainly followed this post. In the end I had a directory with the complete mono tree whose native components had been correctly compiled for ARM. I verified that by running sb2 mono -V on the Ubuntu system as well as mono -V on the BeagleBone Black after copying the mono directory onto it. I can also run a simple .NET console application that I created with VS2013 on the BBB's mono.

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

Next I tried to run a simple GUI application that basically only consists of a single form and a button that pops up a messagebox. The project settings in VS were set to .NET Framework version 4.5 and "Release".

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

Next, I tried to run this EXE with mono on the Ubuntu system and it worked after tweaking the ./configure options, recompiling mono (--with-tls=__thread) and installing the required libraries (libgdiplus and libx11). But when I try to run the same EXE on the BBB it crashes with this exception:

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 

我想知道可能是什么问题?我如何才能从这里继续?

I wonder what the problem might be? How can I go on from here?

顺便说一句:这是 BBB 上的单声道版本:

BTW: This is the mono version on the 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 上运行它时,它告诉我:

Update: I just noticed this little mono utility called mono-test-install. When I run it on the BBB, it tells me this:

./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 它可以在哪里找到它的库和程序集,但我不能确定......如果有人能对此有所了解,那就太好了.

I think that may be my problem. Does somebody know how to get things on track in this case? I assume that I somehow have to tell mono where it can find its libraries and assemblies, but I can't tell for sure... It would be great if someone could shed some light on this.

更新 2: 通过为我手工制作的单声道版本(此处描述).另外,我必须编辑文件 [mono-directory]/usr/local/bin/mcs 并更正可执行文件的路径.我假设您可以在配置单声道时使用 PREFIX=... 自动设置它们,但我没有这样做.

Update 2: I was able to get rid of the error shown by mono-test-install by creating the relevant environment variables for my hand-made mono version (described here). Also, I had to edit the file [mono-directory]/usr/local/bin/mcs and correct the paths to the executables. I assume you can set them automatically with PREFIX=... when you configure mono, but I didn't do that.

现在,当我运行 mono-test-install 时,我得到了:

Now, when I run mono-test-install I get this:

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

So I think there should be everything in place and set up correctly now. But it still does not work. When I run my little winforms test program, I get the very same exception as given above.

经过一番搜索,我发现可能存在 mono 中的错误我不是第一个遇到这种情况的人.然而,奇怪的是,同一个 EXE 在具有相同单声道版本的 Ubuntu 上完美运行(只是为 amd64 而不是 armv7 编译,相同的配置选项).所以在 PC 上一切正常,在 arm 上它崩溃了.

After some searching I found out that there is probably a bug in mono as I am not the first one to run into this. The strange thing however is the fact that the same EXE runs flawlessly on Ubuntu with the very same mono version (just compiled for amd64 and not armv7, same configure options). So on the PC everything works fine, on arm it crashes.

更新:我提交了一份附带示例项目的报告,该项目产生了问题此处.

推荐答案

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

A bit of digging shows that GDI+ GdipCreateBitmapFromScan0 returns InvalidParameter when width or height is a non-positive number.

堆栈跟踪上方 表示当首选游标大小(由libX11 的XQueryBestCursor 报告)与原始游标不同时,从X11 驱动程序调用Bitmap 构造函数大小(即 32x32 像素).

Going upper the stack trace indicates that Bitmap constructor is called from X11 driver when preferred cursor size (reported by XQueryBestCursor from libX11) differs from original cursor size (which is 32x32 pixels).

所以想法是 BeagleBone 上的 XQueryBestCursor() 返回零宽度/高度的光标.一些谷歌搜索让我们看到 thread 描述一个类似的问题.那里甚至还有某种补丁.

So the thought is that XQueryBestCursor() on your BeagleBone returns zero width/height for cursor. A bit of googling gets us to the thread describing a similar issue. There's even some kind of patch there.

我相信您应该使用提供的补丁在 BeagleBone 上重新编译 X11,或者在单声道源中添加一些检查(在调用 XQueryBestCursor 之后),以便在 X11 返回零宽度时使用光标的原始宽度/高度/高度.

I believe you should either recompile X11 on your BeagleBone with a patch provided, or add some checks in mono source (after calling XQueryBestCursor) so it use cursor's original width/height when X11 returns zero width/height.

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

UPD: HW cursor size seems to be actually reported by video driver, so you can probably just try another one, like recent xf86-video-fbdev.

这篇关于在 Mono for ARM 上运行简单的 winforms 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆