2016-08-17 1 views
0

私は自分のProgram.csに以下のコードを持ち、Mono 4.2.2で自己ホストのnancyアプリケーションを開始しました。System.Net.Sockets.SocketException:ホストを解決できませんでした - MonoでセルフホストされたNancyアプリ

public static void Main (string[] args) 
    {   
     var uri = ""; 

     if(ReflectConfiguration.CurrentEnviroment == ReflectConfiguration.Environments.Production || ReflectConfiguration.CurrentEnviroment == ReflectConfiguration.Environments.Staging) 
     { 
      uri = string.Format("http://localhost:{0}", Environment.GetEnvironmentVariable("PORT").ToString()); 
     } 
     else if(ReflectConfiguration.CurrentEnviroment == ReflectConfiguration.Environments.Development) 
     { 
      uri = string.Format("http://localhost:8888"); 
     } 

     Console.WriteLine("Starting Reflect.Web application on " + uri); 

     // initialize an instance of NancyHost 
     var host = new NancyHost(new Uri(uri)); 
     host.Start(); // start hosting 

     // check if we're running on mono 
     if (Type.GetType("Mono.Runtime") != null) 
     { 
      // on mono, processes will usually run as daemons - this allows you to listen 
      // for termination signals (ctrl+c, shutdown, etc) and finalize correctly 
      UnixSignal.WaitAny(new[] { 
       new UnixSignal(Signum.SIGINT), 
       new UnixSignal(Signum.SIGTERM), 
       new UnixSignal(Signum.SIGQUIT), 
       new UnixSignal(Signum.SIGHUP) 
      }); 
     } 
     else 
     { 
      Console.ReadLine(); 
     } 

     host.Stop(); // stop hosting 
    } 

このコードは数か月間正常に実行されました。このライン上の

System.Net.Sockets.SocketException: Could not resolve host '+' 

host.Start(); // start hosting 

私は任意の依存関係に最近行ったすべての更新を認識していないですちょうど今、このエラーが現れて始めました。

誰もこれまでにこれまでに出会ったことはありますか?そしてなぜ「+」記号ですか?

答えて

0

+は、.NETのHttpListenerを(モノわからないが)、それはより多くの情報のためHttpListener's Class remarksをチェックアウトし、アプリケーションをホストする必要がある場所を決定するために使用する「URIプレフィックス文字列」の一部にすることができます:

同様にHttpListenerがポートに送信されたすべての要求を受け入れるように指定するには、ホスト要素を "+"文字「https://+:8080」に置き換えます。 "*"と "+"文字は、パスを含むプレフィックスに存在することができます。

私の推測では、あなたのコードはReflectConfiguration.CurrentEnviromentをチェックし、あなたが選択している場合が欠落していることです。

環境が設定されていないか存在していますか?または生産、ステージング、または開発に参加していないのですか?新しいURIオブジェクトを作成すると、uriの値は何ですか?

+0

ありがとうございます。エラーが発生しましたが、私のホストファイルに問題がありました。 – Corstiaan

関連する問題