Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OWIN fails to start with "The network location cannot be reached"

I'm trying to run the following code on a .NET 4.5 Console app:

var app = WebApp.Start<Startup>("http://127.0.0.1:9000/");

This works on my colleagues machines but not mine.

The exception message reads "Exception has been thrown by the target of an invocation." with an inner exception of "The network location cannot be reached. For information about network troubleshooting, see Windows Help".

I have tried turning off my firewall, resetting my hosts file, no anti viruses are running, flushed my DNS and cleaned/rebuilt my solution.

Here is the 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 Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuilder builder)
   at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(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 OwinTest.Program.Main(String[] args) in C:\Temp\OwinTest\OwinTest\Program.cs:line 12

If I change the code to this it works:

var app = WebApp.Start<Startup>("http://localhost:9000/");

But the above code is not what I'm looking for.

Any ideas would be appreciated.

like image 868
Pierre Nortje Avatar asked Sep 19 '19 13:09

Pierre Nortje


Video Answer


2 Answers

After a whole day of research and troubleshooting, the following command worked:

netsh http add iplisten 127.0.0.1

When I ran this in command prompt, I did not receive any errors.

like image 151
Pierre Nortje Avatar answered Nov 10 '22 01:11

Pierre Nortje


Try this:

var app = WebApp.Start<Startup>("http://0.0.0.0:9000/");

0.0.0.0 should mean it's listening on all IPs...

like image 33
GPW Avatar answered Nov 10 '22 00:11

GPW