Owin Self Host 无法启动

Owin Self Host Will Not Start

使用具有管理员权限的 VS2015 我的主机启动并且我可以使用 Nancyfx 接收请求。

    IDisposable host = null;
    IDisposable HostStart()
    {
        try
        {
            return WebApp.Start<Startup1>("http://*:7002");
        }
        catch (HttpListenerException ex)
        {

            throw new  Exception(ex.Message);
        }
    }

当我使用 Visual Studio 扩展创建安装项目并构建和安装,然后使用管理员权限 运行 我没有得到任何异常,但服务器不能 found.I 都关掉了 firewall.I 现在有 运行 出主意了?

更新:我遇到异常

  An exception has been thrown by the taget of invocation.


  System.Reflection.TargetInvocationException: Exception has been thrown by          the  target of an invocation. ---> System.Exception: Object reference not set to   an instance of an object.
  at CabbyTechOffice.Startup1.Configuration(IAppBuilder app)
  --- End of inner exception stack trace ---
  at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[]    arguments, Signature sig, Boolean constructor)
  at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,    Object[] parameters, Object[] arguments)
  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags   invokeAttr,      Binder binder, Object[] parameters, CultureInfo culture)
  at Owin.Loader.DefaultLoader.<>c__DisplayClass12.   <MakeDelegate>b__b(IAppBuilder builder)
  at Owin.Loader.DefaultLoader.<>c__DisplayClass1.  <LoadImplementation>b__0(IAppBuilder builder)
 at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp(StartContext   context)
 at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
 at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions    options)
 at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options)
 at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider  services, StartOptions options)
 at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options)
 at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options)
 at Microsoft.Owin.Hosting.WebApp.Start[TStartup](String url)
 at CabbyTechOffice.MAIN.HostStart()

null ref 似乎在启动中:

     public class MyBoot : DefaultNancyBootstrapper
    {
        protected override void ConfigureApplicationContainer(TinyIoCContainer container)
        {
            CabbyTechOfficeConfig fig = ConfigUI.GetCabbyTechConfig();
            if (fig == null)
            {
                throw new Exception("NO CONFIG");
            }
            ICabbytechOfficeDataAccess DB = null;
            try
            {
                DB = ConnDBCreater.CreateDB(fig.DatabaseComputerName + "\" + fig.DatabaseInstanceName, "taxidb", fig.DbPassword, 8);
                IPEndPoint smsEP = null;
                SmsCommsMob sms = null;
                var comms = new ControlConnectAndSend(new IPEndPoint(IPAddress.Any, fig.DispatchFromPDAServerPort));
                try
                {
                    smsEP = new IPEndPoint(IPAddress.Parse(fig.SmsIp), fig.SmsPort);
                    sms = new SmsCommsMob(smsEP);
                }
                catch (Exception)
                {
                }
                StateInjector stateInjector = new StateInjector(DB, comms, sms);
                UdpBroadcasterJson.Send(new UDPCmd() { code = UDPCmd.commandsEnum.broadcastForDispatch }, stateInjector.UDPDispatchPort);

                try
                {
                    var comp = DB.CompaniesGet();
                    stateInjector.CompanyName = comp.company;
                }
                catch (Exception)
                {
                }

                try
                {
                    stateInjector.zones = DB.ZonesGet();
                }
                catch (Exception)
                {
                }
                try
                {
                    var locLog = new PdaLocLog();
                    var locLogger = new PdaLocLogger(DB, locLog);
                    stateInjector.locLogger = locLogger;
                }
                catch (Exception)
                {
                }
                container.Register<IStateInjector, StateInjector>(stateInjector);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }



        }
    }


}

您有 try/catches 链,其中包含空的 catch 块。

            try
            {
                var comp = DB.CompaniesGet();
                stateInjector.CompanyName = comp.company;
            }
            catch (Exception)
            {
            }

            try
            {
                stateInjector.zones = DB.ZonesGet();
            }
            catch (Exception)
            {
            }
            try
            {
                var locLog = new PdaLocLog();
                var locLogger = new PdaLocLogger(DB, locLog);
                stateInjector.locLogger = locLogger;
            }
            catch (Exception)
            {
            }

这可能会使您尝试使用的 stateInjector 为 null。

您需要以可以记录这些 try/catches 中的任何问题的方式处理捕获。大概是环境出了问题,它失败了,但你不知道,因为空捕获。

NancyFx 引导程序中的 TinyIoc 容器存在问题,原因是异常处理程序的设计不当,并且依赖项被注入 null。