System.Net.HttpListenerException: Failed to listen on prefix 'http://localhost:8080

When faced with error: "Failed to listen on prefix 'http://someURL:somePortNo/' because it conflicts with an existing registration on the machine." It is not really necessary that there is an application actively listening on that port - thus output of Netstat -abno may not always help. If the already registered application is running it can help you narrow down to which application is causing the issue by looking at the info Netstat provides.

However, you will get this error even after the application in question is stopped since the error indicates a registration. The correct diagnostic command therefore is:

netsh http show urlacl

We need to examine the output and check whether any of the listed reserved URLs is configured to listen on the specific port your application is trying to use. You need to note the value of the "Reserved URL" field for that specific application. You will need it later for deleting the registration which is causing the error.

Uninstalling that specific application - assuming their uninstall procedure does include an un-registration - may resolve the problem. Alternatively you could take a more direct and precise approach of using the command for deleting a URL reservation:

(Note that if the conflict is legitimate, it may be better to reconfigure your application to listen on a different port instead.)

netsh http delete urlacl url=<value of "Reserved URL" in the output of netsh http show urlacl>

When the command works you will see output: URL reservation successfully deleted.

Upon running netsh http show urlacl a second time you will now see that the url registration is indeed gone. And now running your application should not result in the error you were seeing earlier.

Tags:

Port

Owin

Katana