Owin self-host - Failed to listen on prefix 'http://localhost:12345/' because it conflicts with an existing registration on the machine
Asked Answered
O

2

9

I'm trying to self-host a simple WebAPI:

public class AccountViewApplication {
    protected IDisposable WebApplication;

    public void Start() {
        WebApplication = WebApp.Start<WebPipeline>("http://myhost.mymachine.me:12345");
        new AccountViewApplication().Start();
    }

    public void Stop() {
        WebApplication.Dispose();
    }
}

The first time I run this, it starts to listen just fine, but the next time that I try - I get this:

Failed to listen on prefix 'http://myhost.mymachine.me:12345/' because it conflicts with an existing registration on the machine

What can I do to make it listen every time, and not complain about an existing reservation?

Obovate answered 16/10, 2014 at 13:52 Comment(0)
H
2

If it's complaining about an existing registration, it's because something else is running on that port. If it worked the first time, then it sounds like your first instance of the program is still running.

Check in Task Manager for your program name and see if it's still alive.

Heliogabalus answered 29/3, 2015 at 1:10 Comment(2)
can I programmatically handle it?Schleswig
@IamStalker you catch that HttpListenerException and try it on a new port. Basically create a loop on WebApp.Start(...) up to X number of retries.Frenzy
T
0

check the solution

1- open cmd and "netstat -aon" search for port in local address column after find check PID maybe port use by another procces

2- maybe two or more times call this line WebApplication = WebApp.Start("http://myhost.mymachine.me:12345");

3-try this

"http://myhost.mymachine.me:12345/user:everyone"

Telepathy answered 18/12, 2017 at 10:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.