0

I have an app. I'm working on which self-hosts WebApi. It can run as either a command-line app, or as a Windows service. It's compiled using the .NET 4.5 runtimes.

When I run it on my Windows 7 dev. machine, it works fine.

When I deploy and run as a command-line app on my Windows 2012 server machine, it fails with the exception:

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)

My code does this:

url = "http://localhost:5000";
_app = WebApp.Start<WebAppConfiguration>(url);

And the WebAppConfiguration class looks like this:

public class WebAppConfiguration : HttpConfiguration
{
    public void Configuration(IAppBuilders app)
    {
        ConfigureRoutes();
        ConfigureJsonSerialization();

        // This line throws the exception:
        app.UseWebApi(this);
    }
}

I did some searching and it sounded like I needed to reserve the port using NETSH, so this is what I did from an Admin command prompt:

netsh http add urlacl url=http://localhost:5000/ user=Everyone listen=yes delegate=yes

Unfortunately, I'm still getting the exception. Is there some other step I need to do to get this to work under Windows Server 2012?

EDIT:

The inner exception (which I didn't think to log) contained a much more helpful error. It turns out I was missing an assembly binding entry for Microsoft.Owin in my .config file for Owin. This was in my dev. version but didn't make it into the version on my server.

Paul Mrozowski
  • 6,604
  • 9
  • 34
  • 47
  • 2
    Isn't there more meaningful `InnerException` in `TargetInvocationException` you get? – dewaffled Oct 30 '14 at 19:21
  • It didn't even occur to me to look, but sure enough the inner exception pointed me to the real problem - a missing entry in my .config file. Thanks! – Paul Mrozowski Oct 30 '14 at 19:39

0 Answers0