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 サーバーが必要です。DISPLAY 環境変数を確認してください) パラメーター名: Display

次の 2 つのうちのいずれかを実行しようとしているようです:

  1. Xデスクトップにアクセスできないシェルでmonoアプリを起動する
  2. ディスプレイにアクセスする権限を持たないユーザーとして実行されています

このスレッドはラデガストフォーラムあなたも同じ問題のようですね。

潜在的な解決策

次のいずれかを行う必要があります。

  1. Xデスクトップを所有する同じユーザーとしてvpsにssh接続した後、$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. 使用したい場合はRDP(リモートデスクトッププロトコル)のパッケージをインストールすることができますxrdp

    $ sudo apt-get install xrdp
    
  2. リモート サーバー (Remmina、) への接続。

  3. ターミナルを開いて$DISPLAYを取得します。

    $echo $DISPLAY
    :10.0
    
  4. ssh で mono プログラムを実行します。

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

関連情報