gpt4 book ai didi

c# - Owin Self Host 无法启动

转载 作者:太空宇宙 更新时间:2023-11-03 12:33:04 27 4
gpt4 key购买 nike

使用具有管理员权限的 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 创建安装项目并构建和安装,然后使用管理员权限运行时,我没有遇到任何异常,但是找不到服务器。我已经关闭了防火墙。我现在已经运行没有想法?

更新:我遇到异常

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



}
}


}

最佳答案

您有带有空 catch block 的 try/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/catch 中的任何问题的方式来处理捕获。大概是环境出了问题,但由于空捕获你不知道。

关于c# - Owin Self Host 无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41986429/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com