Owin自我主持人无法启动

时间:2017-02-01 17:52:57

标签: c# owin self-hosting

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

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

            throw new  Exception(ex.Message);
        }
    }

当我使用Visual Studio Extension创建安装项目并构建和安装然后使用admin privalages运行时,我没有得到任何例外但是找不到服务器。我关闭了防火墙。我有现在用完了想法?

更新:我收到异常

  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);
            }



        }
    }


}

2 个答案:

答案 0 :(得分:1)

你有一些带有空捕获块的try / catches链。

            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,然后尝试使用它。

您需要以这样的方式处理捕获:您可以记录那些尝试/捕获中的任何问题。据推测,它在失败的环境中存在问题,但由于捕获空洞,你不知道这一点。

答案 1 :(得分:0)

由于异常处理程序中的设计错误,并且依赖项被注入null,因此NancyFx引导程序中的TinyIoc容器存在问题。