繁体   English   中英

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

[英]System.Net.Sockets.SocketException: Could not resolve host - Self-hosted Nancy app on Mono

我在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

我不知道我最近对任何依赖项进行了任何更新。

有人遇到过吗? 以及为什么加上“ +”号?

+可以是.NET的HttpListener(不确定单声道)用于确定应在何处托管应用程序的“ URI前缀字符串”的一部分,请查看HttpListener的类说明以获取更多信息:

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

我的猜测是您的代码正在检查ReflectConfiguration.CurrentEnviroment并缺少您要选择的情况。

是否没有配置/存在环境? 还是您不在生产,暂存或开发中? 创建新的URI对象时uri的值是什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM