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

ぃ、小莉子 提交于 2019-12-03 09:53:21

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.

I was able to solve the problem by uninstalling several programs. Unfortunately I did not test after each, so I don't know which one it was.

They included Dropbox, Goto Assist, Goto Meeting and a winforms application

I had the same issue, and it was a silly fix. I had other console apps open that was using the same port number, so after I have closed all the console apps, I was able to run and did not get this error.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!