2017-03-04 9 views
0

WebApplicationをIISServer上で実行しています。
私は静的クラス作成しました:私はJMSInformationGetterUAT.RunningJMSを使用していたときに私はエラーを取得するページに...WebApplication上のオブジェクトの.Net永続性

protected void Application_Start(object sender, EventArgs e) 
    { 
     JMSInformationGetterUAT.Init(); 
    } 

を::

public class JMSInformationGetterUAT 
{ 

    private static String userName = "123"; 
    private static String password = "321"; 

    public static String runningJMS = ""; 

    private static Admin adminConnection = null; 

    public static void Init() 
    { 
     try 
     { 
      String serverUrl = "tcp://localhost:1232"; 

      adminConnection.CommandTimeout = 500; 
      adminConnection = new Admin(serverUrl, userName, password); 
      runningEMS = "JMS1Instance"; 

     } 
     catch 
     { 
      EMSCriticalFailure = true; 
     } 
    } 

} 

とGlobal.asax.csにこれを追加しましたが

JMS側で

"Object reference not set to an instance of an object".

(そのアプリケーションが迅速モニタリングするためのものである)私は1ミリ秒接続した後なしを参照 - が、オブジェクトadminConnectionにによって充填メソッドは接続を維持する必要があります。私はこのオブジェクトも参照してくださいそれは空です...

だから、なぜこのオブジェクトは永続的ではありませんか?それは、静的プレフィックスを持ってい...

は、新しい管理者をインスタンス化する前に、adminConnectionのプロパティCommandTimeoutのを設定している

+0

の可能性のある重複した[?とNullReferenceExceptionは何ですか、と私はそれを修正しますか](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and -how-do-i-fix-it) –

答えて

2

私を助けてください。

は、あなたが任意の非静的プロパティにアクセスする前に発生する必要が

adminConnection =新しい管理(...)。

0

私はフランからの提案の少し後にコードを変更しました。 は、今では動作します:

public class JMSInformationGetterUAT{ 

private static String userName = "123"; 
private static String password = "321"; 

public static String runningJMS = ""; 

private static Admin adminConnection = new Admin("localhost:1234", userName, password); 

public static void Init() 
{ 
    //some other logic i needed 
} }