.net 4.5 为什么我的自托管Web API服务在Windows 2012上引发异常?

.net 4.5 为什么我的自托管Web API服务在Windows 2012上引发异常?,.net-4.5,asp.net-web-api,owin,windows-server-2012,self-hosting,.net 4.5,Asp.net Web Api,Owin,Windows Server 2012,Self Hosting,我有一个应用程序。我正在研究哪个self托管WebApi。它可以作为命令行应用程序或Windows服务运行。它是使用.NET4.5运行时编译的 当我在Windows7开发机器上运行它时,它工作正常 当我在Windows 2012 server计算机上部署并作为命令行应用程序运行时,它会失败,但出现以下异常: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle.Inv

我有一个应用程序。我正在研究哪个self托管WebApi。它可以作为命令行应用程序或Windows服务运行。它是使用.NET4.5运行时编译的

当我在Windows7开发机器上运行它时,它工作正常

当我在Windows 2012 server计算机上部署并作为命令行应用程序运行时,它会失败,但出现以下异常:

Exception has been thrown by the target of an invocation.

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments,
 Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Objec
t[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture)
   at Owin.Loader.DefaultLoader.<>c__DisplayClass12.<MakeDelegate>b__b(IAppBuild
er builder)
   at Owin.Loader.DefaultLoader.<>c__DisplayClass1.<LoadImplementation>b__0(IApp
Builder builder)
   at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp(StartContext contex
t)
   at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
   at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions opt
ions)
   at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider service
s, StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options)
       at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options)
我做了一些搜索,听起来好像我需要使用NETSH保留端口,所以这是我在管理命令提示符下所做的:

netsh http add urlacl url=http://localhost:5000/ user=Everyone listen=yes delegate=yes
不幸的是,我仍然得到例外。在Windows Server 2012下,我是否还需要执行其他步骤才能使其正常工作

编辑:


内部异常(我认为没有记录)包含一个更有用的错误。原来我在Owin的.config文件中缺少Microsoft.Owin的程序集绑定项。这是在我的开发版本中,但没有进入我服务器上的版本。

targetingException
中没有更有意义的
InnerException
吗?我甚至没有想到要查看它,但可以肯定的是,内部异常指出了真正的问题-我的.config文件中缺少一个条目。谢谢
public class WebAppConfiguration : HttpConfiguration
{
    public void Configuration(IAppBuilders app)
    {
        ConfigureRoutes();
        ConfigureJsonSerialization();

        // This line throws the exception:
        app.UseWebApi(this);
    }
}
netsh http add urlacl url=http://localhost:5000/ user=Everyone listen=yes delegate=yes