Site icon Ryadel

'Web Server Failed to Start' in Visual Studio 2022: How to Fix

How to fix the "No executable found matching command dotnet-ef" error in Visual Studio with .NET Core

If you've come across this article, you’re likely looking for a way to resolve the "Web Server failed to start. Cause: An attempt was made to access a socket in a way forbidden by its access permissions" error while running an ASP.NET Core project in Visual Studio 2022 on Windows.

The cause of this error is almost always a temporary conflict with the Windows NAT Driver (winnat) service. This service manages network connections and can sometimes block access to the port used by your project. Here’s how to fix it in a few steps.

Why does this error occur?

The winnat service (Windows NAT Driver) handles Network Address Translation, often used by Hyper-V or Docker Desktop. In some cases, after a system update or an abrupt interruption of a project, this service may retain control over a network port, preventing Visual Studio from starting the web server (Kestrel or IIS Express).

Solution: Restart the winnat service

Follow these steps to resolve the issue:

  • Open a Command Prompt as Administrator
    • Click the Windows key and search for "Command Prompt".
    • Right-click the icon and select "Run as administrator".
  • Stop the winnat service
    • Type the following command and press Enter: net stop winnat
    • You’ll receive a confirmation message: "The Windows NAT Driver service was stopped successfully".
  • Restart the winnat service
    • Type the following command and press Enter: net start winnat
    • The response should be: "The Windows NAT Driver service was started successfully".

Once the service is restarted, try running your project in Visual Studio again.

Additional steps (if the issue persists)

  • Run Visual Studio as Administrator
    • Right-click the Visual Studio icon > Run as administrator.
  • Check for occupied ports
    • Verify if other applications (Skype, Zoom, SQL services) are using your project’s port (e.g., 5000, 5001) with:
    • netstat -ano | findstr :<your_port>
  • Regenerate the development SSL certificate
    • Open PowerShell as administrator and run:
      • dotnet dev-certs https --clean
      • dotnet dev-certs https --trust

Conclusion

Restarting the winnat service resolves the socket permission error in most cases. If the problem recurs, check for port conflicts or contact Microsoft Support for further assistance.

 

Exit mobile version