System.Net.Sockets.SocketException:无法解析主机 - Mono上的自托管Nancy应用程序

时间:2016-08-17 16:07:49

标签: c# mono nancy

我在Program.cs中有以下代码,可以在Mono 4.2.2上启动自托管的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

我不知道我最近对任何依赖所做的任何更新。

有没有人曾经遇到过这个?为什么'+'符号?

1 个答案:

答案 0 :(得分:0)

+可以是.NET的HttpListener(不确定单声道)用于确定应该托管应用程序的位置的“URI前缀字符串”的一部分,请查看HttpListener's Class remarks以获取更多信息:

  

同样,要指定HttpListener接受发送到端口的所有请求,请使用“+”字符“https://+:8080”替换host元素。 “*”和“+”字符可以出现在包含路径的前缀中。

我的猜测是您的代码正在检查ReflectConfiguration.CurrentEnviroment并错过了您选择的案例。

是否没有配置/存在环境?或者你不参与制作,舞台演出或发展?创建新uri对象时URI的价值是多少?

相关问题