在 CentOS 5 CLI 上運行 Mono

在 CentOS 5 CLI 上運行 Mono

我有在 Linux CentOS 5 32 位元上運行的 vps 伺服器(虛擬專用伺服器),我安裝了vncserverX-Windows、GNOME 和 KDE 環境,並從 Windows 7 桌面中的 vncviewer 連接到 VNC 伺服器

現在我執行命令

mono Radegast.exe

在終端,我得到了

[ERROR]: - Unhandled System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.ArgumentNullException: Could not open display (X-Server required. Check you DISPLAY environment variable)
    Parameter name: Display
      at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000]
      at System.Windows.Forms.XplatUIX11..ctor () [0x00000]
      at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000]
      at System.Windows.Forms.XplatUI..cctor () [0x00000]
      --- End of inner exception stack trace ---
      at System.Windows.Forms.Application.EnableVisualStyles () [0x00000]
      at Radegast.MainProgram.RunRadegast (System.String[] args) [0x00000]
      at Radegast.MainProgram.Main (System.String[] args) [0x00000] : An exception was thrown by the type initializer for System.Windows.Forms.XplatUI
      at System.Windows.Forms.Application.EnableVisualStyles () [0x00000]
      at Radegast.MainProgram.RunRadegast (System.String[] args) [0x00000]
      at Radegast.MainProgram.Main (System.String[] args) [0x00000]

單聲道版本是

# mono -V
Mono JIT compiler version 2.4.2.3 (tarball Sat Apr 20 19:49:33 MSD 2013)
Copyright (C) 2002-2008 Novell, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        GC:            Included Boehm (with typed GC)
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  x86
        Disabled:      none 

答案1

您沒有在問題中明確說明這一點,但您遇到的錯誤:

[錯誤]: - 未處理的 System.TypeInitializationException:System.Windows.Forms.XplatUI 的類型初始值設定項目引發例外狀況 ---> System.ArgumentNullException:無法開啟顯示(需要 X-Server。檢查 DISPLAY 環境變數)參數名稱:顯示

聽起來您正在嘗試執行以下兩件事之一:

  1. 在無法存取 X 桌面的 shell 中啟動 mono 應用程式
  2. 正在以無權存取顯示器的使用者身分運行

這條線索在瑞德嘉斯特論壇聽起來像你同樣的問題。

潛在的解決方案

您需要:

  1. 以擁有 X 桌面的相同使用者身分 ssh 進入 vps 後,將 $DISPLAY 環境變數設為“:0.0”
  2. xhost +在以其他使用者身分執行 mono 指令之前,以擁有桌面的使用者身分執行(不要忘記也為該其他使用者設定 $DISPLAY 變數!)

我相信你也可以像這樣運行你的 mono 命令:

% XAUTHORITY=/home/$YOURUSER/.Xauthority DISPLAY=:0.0 mono Radegast.exe

筆記:$YOURUSER 是擁有 X 桌面的使用者。

答案2

如果你的C#程式碼有GUI,你需要給它一個$DISPLAY。您可以先echo $DISPLAY在遠端 linux 上輸入 $DISPLAY 。

  1. 如果您想使用遠端開發計劃(遠端桌面協定),您可以安裝套件XRDP

    $ sudo apt-get install xrdp
    
  2. 連接到遠端伺服器(Remmina,)。

  3. 打開終端並取得 $DISPLAY。

    $echo $DISPLAY
    :10.0
    
  4. 使用 ssh 運行單聲道程式:

    $ ssh [email protected]
    $ export DISPLAY=:10.0
    $ mono server.exe > /dev/null 2> /dev/null &
    

相關內容