Unable to Establish connection with Azure Remote Debugging
Within one of my projects we had problems with attaching the debugger to our Azure Instances. During the the process we would get a model stating that the operation is taking longer as expected and finally got the model dialog shown below.
“The following error occurred while launching remote debugging: Unable to connect to the Microsoft Visual Studio Remote Debugger named [debugger name]. The Visual Studio 2015 Remote Debugger (MSVSMON.EXE) does not appear to be running on the remote computer. This may be because a firewall is preventing communication to the remote computer. Please see Help for assistance en configuring remote debugging.”
In the event log of the App Service we found a error stating that the connection could not be made, and that a instance of the remote debugger is already running.
<Event> <System> <Provider Name="Visual Studio Remote Debugger"/> <EventID>1000</EventID> <Level>1</Level> <Task>0</Task> <Keywords>Keywords</Keywords> <TimeCreated SystemTime="2016-02-17T11:21:39Z"/> <EventRecordID>1544228421</EventRecordID> <Channel>Application</Channel> <Computer>RD000D3A2303CA</Computer> <Security/> </System> <EventData> <Data>remdbguser connected.</Data> </EventData> </Event> <Event> <System> <Provider Name="Visual Studio Remote Debugger"/> <EventID>1001</EventID> <Level>3</Level> <Task>0</Task> <Keywords>Keywords</Keywords> <TimeCreated SystemTime="2016-02-17T11:21:41Z"/> <EventRecordID>1544230937</EventRecordID> <Channel>Application</Channel> <Computer>RD000D3A2303CA</Computer> <Security/> </System> <EventData> <Data>Msvsmon was unable to start a server named '127.0.0.1:51040'. The following error occurred: An instance of the remote debugger is already running on this computer, or another process is already bound to the specified TCP/IP port. View Msvsmon's help for more information.</Data> <Binary>08005E80</Binary> </EventData> </Event>
Since the remote debugger was activated on the Azure App Service it had to be a firewall configuration.
After a lot of searching we found out that the following ports needs to be opened to be able to remote debug a Azure App Service:
Ports | Incoming/Outgoing | Protocol | Description |
3702 | Outgoing | UDP | Remote debugger discovery |
4020 | Outgoing | TCP | Visual Studio 2015 |
4021 | Outgoing | TCP | Visual Studio 2015 |
4016 | Outgoing | TCP | Visual Studio 2012 |
4018 | Outgoing | TCP | Visual Studio 2013 |
The remote debugging port number is incremented by 2 for each Visual Studio version. You can open these ports for all or limit it to all Azure Datacenters IP’s that you can find here.
Also make sure you enable NAT (Network Address Translation) for the firewall exclusion because without it it will not work.
Reference:https://msdn.microsoft.com/en-us/library/mt592019.aspx and https://msdn.microsoft.com/en-us/library/mt592018.aspx