Mono WinForms 应用程序不会 运行 启动
Mono WinFroms app won't run on boot
我是 Raspbian 的新手。我在 RPi + 官方 7" 显示器上的 Raspbian 上有一个单声道 WinForms 应用程序。当我通过 UI(双击文件)和终端( /home/pi/scannerapp/start-app.sh
).
脚本 (start-app.sh
):
#!/bin/bash
/usr/bin/mono '/home/pi/scannerapp/Re-Express Scanner WinForms.exe'
我编辑了 rc.local 文件:
exec 2> /tmp/rc.local.log # send stderr from rc.local to a log file
exec 1>&2 # send stdout to the same log file
set -x # tell sh to display commands before execution
/home/pi/scannerapp/start-app.sh &
exit 0
并且在启动时,应用程序不会 运行。我在日志中发现以下内容:
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)
Parameter name: Display
at System.Windows.Forms.XplatUIX11.SetDisplay (System.IntPtr display_handle) [0x00435] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11..ctor () [0x00077] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11.GetInstance () [0x0001c] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUI..cctor () [0x0007d] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.Application.EnableVisualStyles () [0x00006] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at Re_Express_Scanner_WinForms.Program.Main () [0x00001] in <52b5a9f59ae647c0a7c47e5736c3742e>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)
Parameter name: Display
at System.Windows.Forms.XplatUIX11.SetDisplay (System.IntPtr display_handle) [0x00435] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11..ctor () [0x00077] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11.GetInstance () [0x0001c] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUI..cctor () [0x0007d] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.Application.EnableVisualStyles () [0x00006] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at Re_Express_Scanner_WinForms.Program.Main () [0x00001] in <52b5a9f59ae647c0a7c47e5736c3742e>:0
如果我尝试通过 SSH 运行 start-app.sh
脚本,我会得到同样的异常。
感谢任何帮助。
谢谢!
我最终从 rc.local 中删除了我的编辑,并通过使用 sudo nano 编辑它调用了 /etc/xdg/lxsession/LXDE-pi/autostart 中的 start-app.sh 脚本。现在正在启动。根据我的理解,从 rc.local 文件调用脚本是在 X 显示环境之外执行的,因此 X 显示错误以及为什么需要从显示环境 (/lxde-pi/autostart) 中调用它.
有关自动 运行 GUI 应用程序的更多信息,请参阅此内容:
http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs-gui
我是 Raspbian 的新手。我在 RPi + 官方 7" 显示器上的 Raspbian 上有一个单声道 WinForms 应用程序。当我通过 UI(双击文件)和终端( /home/pi/scannerapp/start-app.sh
).
脚本 (start-app.sh
):
#!/bin/bash
/usr/bin/mono '/home/pi/scannerapp/Re-Express Scanner WinForms.exe'
我编辑了 rc.local 文件:
exec 2> /tmp/rc.local.log # send stderr from rc.local to a log file
exec 1>&2 # send stdout to the same log file
set -x # tell sh to display commands before execution
/home/pi/scannerapp/start-app.sh &
exit 0
并且在启动时,应用程序不会 运行。我在日志中发现以下内容:
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)
Parameter name: Display
at System.Windows.Forms.XplatUIX11.SetDisplay (System.IntPtr display_handle) [0x00435] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11..ctor () [0x00077] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11.GetInstance () [0x0001c] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUI..cctor () [0x0007d] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.Application.EnableVisualStyles () [0x00006] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at Re_Express_Scanner_WinForms.Program.Main () [0x00001] in <52b5a9f59ae647c0a7c47e5736c3742e>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)
Parameter name: Display
at System.Windows.Forms.XplatUIX11.SetDisplay (System.IntPtr display_handle) [0x00435] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11..ctor () [0x00077] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11.GetInstance () [0x0001c] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUI..cctor () [0x0007d] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.Application.EnableVisualStyles () [0x00006] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at Re_Express_Scanner_WinForms.Program.Main () [0x00001] in <52b5a9f59ae647c0a7c47e5736c3742e>:0
如果我尝试通过 SSH 运行 start-app.sh
脚本,我会得到同样的异常。
感谢任何帮助。 谢谢!
我最终从 rc.local 中删除了我的编辑,并通过使用 sudo nano 编辑它调用了 /etc/xdg/lxsession/LXDE-pi/autostart 中的 start-app.sh 脚本。现在正在启动。根据我的理解,从 rc.local 文件调用脚本是在 X 显示环境之外执行的,因此 X 显示错误以及为什么需要从显示环境 (/lxde-pi/autostart) 中调用它.
有关自动 运行 GUI 应用程序的更多信息,请参阅此内容: http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs-gui