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.

Azure Remote Debugging

“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

Related Posts

Azure Managed Service Identity and Local Development Instead of storing user credentials of an external system in a configuration file, you should store them in the Azure Key Vault. Before MSI (Managed S...
The securitydata Azure resource group Most of the times companies have rules in place for managing their Azure environment. The main rules that should be in place are “Azure Policies” and ...
Point to Site VPN Client won’t install To connect an Azure App Service to a on-premise database you can make use of different solutions. Two of those solutions are: Hybrid Connection ...
Invoke Azure Function in your Visual Studio Team Services CI/CD pipeline A utility task is available for Visual Studio Team Services (VSTS) to invoke an http triggered Azure function. The ability to invoke a Function from y...
VSTS Extension for Azure Role Based Access Control Today I published an extension for Visual Studio Team Services (VSTS) that gives you the ability to add and remove role based access assignments in Az...
Listing Azure Services within a CSV file In some situations you will look into a current Azure Environment and the setup/governance of it and need to migrate or move resources around. The ...

7 comments

  • Hello,

    I am facing exactly this problem now and I can’t find a solution.
    Which firewall settings do you have to change? At the developer box or in Azure? Could you please provide more information?

    Best regards

  • Just in case anyone reading this has the same problem but has all the correct firewall configurations, we got this same error message because we switched to IP based SSL. It caused the URL of our web app: “****.azurewebsites.net” to point to a new IP that I suspect is a proxy allowing a permanent IP for the app. It allows SSL to work but stopped the remote debugger from connecting properly, giving us the same error message.

    The solution was to add a new entry into the hosts file of the computer that is running Visual Studio (i.e your development machine):

    XX.XXX.XXX.XXX your-web-app-azurewebsites.net

    Where XX.XXX.XXX.XXX is the IP of the target address listed in the publish profile for the web app. It will probably be something like: your-web-app.scm.azurewebsites.net (note the “.scm”).

    Just thought I would write this out as I spent a whole working day trying to figure this out and might save someone else the time, and this page is one of the few search results I could find that addressed the error message

    • Hi Jonny, thank you for your addition!

    • Thanks Jonny, this just helped me solve my connection problems to the remote debugger!

      One addition: I had some custom domains set up and needed to add those to the hosts file as well. Hosts file looked like this after editing (where xxx.xxx.xxx.xxx is the IP address I found after running “ping .scm.azurewebsites.net” in a command prompt):

      xxx.xxx.xxx.xxx .azurewebsites.net
      xxx.xxx.xxx.xxx ..com
      xxx.xxx.xxx.xxx ..com

      • Seems that wordpress didn’t like me using > and < around text that needed to be repaced in the hosts addresses. The correct values are:

        ping yourappname.scm.azurewebsites.net

        xxx.xxx.xxx.xxx yourappname.azurewebsites.net
        xxx.xxx.xxx.xxx yourcustomsubdomain.yourcustomdomain.com
        xxx.xxx.xxx.xxx yourcustomsubdomain2.yourcustomdomain2.com

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.