VS2015 Unable to connect remote debugger - visual-studio

I have VS2015 locally. Windows 2012 R2 server hosting an IIS8 test website.
I've put the updated DLL and PDB files in the BIN of the test website.
Step 1) On the remote server, I make sure the Remote Debugger is started.
Step 2) While in VS, I navigate to Debug => Attach to Process. Click "Find". Then click "Select"
This is when the error shows up "Unable to connect to 'address'. An operation is not legal in the current state."
I noticed the Qualifier port was changed, and is different than what shows in Step 1... so I try manually changing what's in the Qualifier to match.. but same issue.
I see the "Transport" is changed from Remote to WebKit. Not sure if this is a problem...

I figured it out. Instead of choosing Remote in the Transport dropdown. Select Default and then put your server in the textbox. Even though I am doing remote debugging, it solved the problem.

I got the same error while I tried to attached my solution with running localhost application hosted in iis. I just fixed it by selecting "Native code" in the "Attach to" field of the "Attach to Process" dialog.

In my scenario, a process running on a machine behind firewall had to be debugged. Usual steps did not help in discovering the machine or its process by selecting the Remote (No Authentication) option.
The following steps helped in remote debugging the process with firewalls on:
Run Remote Debugger on remote machine. The remote machine may have the firewall on. Leave Remote Debugger to run with Authentication Mode as Windows Authentication.
On the debugging machine, go to Debug->Attach to Process, and leave Default in Transport drop-down. Enter the IP of the remote machine for Qualifier and press Enter. This will ask to provide credentials to log into remote machine. Provide credentials. Processes running on the remote machine should now be listed under Available Processes
If the intended process on remote machine is not listed in Available Processes, check ""Show processes from all users"". This should show the process intended to be debugged.
If the break points are not loaded or hit when expected, go to Tools->Options->Debugging-> Uncheck Enable Just My Code. Break points should now hit.
Hope this helps.
Can a moderator add tags remote debugging and remote debugging with firewall to this post, and remove this line?

Related

The debugger cannot connect to the remote computer - but application running on the same computer

I am trying to debug an application but every time I do it reports it is unable to start debugging as the debugger cannot connect to the remote computer.
Only thing is the application it is debugging is a console application and there is no need to access a remote PC.
In the Debug Section of the Project Properties the Use Remote Machine checkbox was clicked (why I don't rightly know) - for this reason it was trying to connect to a remote machine which just did not exist.
Clearing this flag got rid of the issue.
Under Project Properties > Web section, I changed Project Url from some url that mapped to remote server to http://localhost/somePath, and it worked just fine.

Remote debug a Windows service using VS2012

I've tried to find an answer to this before posting this question. I've got a windows service running on another machine. I've written the service in C# and the directory from which the service executable runs holds both executable and debug files (.pdb). I'm attempting to remote debug the service for the first time using VS 2012 Remote debugging. I'm able to attach to the service process successfully. However, as this is my first time I'm not sure what I can do next. I've clicked the pause button and that pauses the service on the line ServiceBase.Run(ServicesToRun) which isnt much use to me. The service has a timer which sets off every 30 seconds and will run the code in the timer event.
My question is ... is there a way of stepping through the code using the debugger in such a scenario.
Do I need to have some debug specific code already in my codebase so that when a debugger attaches it will take me to a place in the code from where i can step through the code?
Thanks,
Andrew.
There are several ways to debug your developed remote application or windows service. If you were in your machine(local) that would be simple to debug.
System.Diagnostics.Debugger.Launch();
But as you are in different machine it depends how your both Machines are connected. Which means you have some limitations on debugging remote application/services.
A Quick search gave me the following result that seemed helpful to me for you,
You can use Remote Debugging Monitor that visual studio use for connecting to remote device and debugging. You can have a clear instruction here on How to: Run the Remote Debugging Monitor.
There's another tool which lets you debug remote application's after a proper setup. But it has some limitations or conditions that you must abide by.
Here is the tool named Remote Tool, you can find a detailed setup process from MSDN here on How to: Set Up Remote Debugging.
It has been clearly quoted there about the prerequisites for using this tool. But still I'm rephrasing those again for quick reviewers.
Prerequisites to use Remote Tool for Visual Studio
To debug on a remote device:
The remote device and the Visual Studio computer must be connected over a network or connected directly through an Ethernet cable. Debugging over the internet is not supported.
The remote device must be running the Remote Tools for Visual Studio 2012.
You must be an administrator to install the remote tools on the remote device. To communicate with the remote tools, you must have user access to the remote device.
Feel free to share if you get to a better and working solution.
Thanks for your response. It reminded me to post my solution here for others like me.
The solution is simple (It always is once you know it).
Ensure that you are running the same code on the target machine as you have open in Visual Studio. It has to be the same assembly and version else the debugger will not hit your breakpoints. Ensure you have your breakpoints setup where you want the debugger to break execution. Then attach to the target machine process and wait for the timer to kick in and run the process where you breakpoint is set.
Hope this helps.
Andrew.

Getting Visual Studio debugging to work when running in Parallels

I've got a Windows 7 machine set up on Paralells.
Everything is working fine. Can access internet from IE or other browsers on my Parallels.
However, when trying to debug a web application in Visual Studio 2010 (by pressing F5 for example) then my default browser in OSX launches, which is great, with localhost:4243 (or whatever port Cassini has allocated on my vm)
Naturally, this doesn't find anything...
What do I need to do to either my parallels vm, or the settings on OSX to get debugging working? ie- my mac talking to the vm?
Make sure you are on the same network.
Use IIS.
Like so:
Your Win-machine has a name, let's say it's called "myWin7machine". Change "localhost:4243" to "myWin7machine:4243" in the browser.
If this doesn't work (well... it shouldn't) you might have the firewall on or the network not bridged. Let's start with the bridging.
Time to check some basics - be on the same network
Check your IP address. It's "ipconfig" on the Win machine and "ifconfig" on the mac; both run from the command prompt. The IP address should be something like 10.4.... or 192.168... on both. The important thing is that only the last number is different. (this is technically not correct but works for 99% of the cases) If they are equal (except the last) you are bridged - which means both machines are on the same network. If they differ too much you had running the Win machine's network "inside" the Mac's. Go to the settings for Parallels (in windows: move your mouse to the top to show Parallel's menu and go to Devices->Network and something "(bridged)". Wait until the balloons disappear and check ipconfig again.
Check that you can ping the Win machine from the Mac. Ping functionality might be turned off in the Win machine but probably isn't.
Now we know we are on the same network.
Still doesn't work
Can you do http://myWin7machine:4243 from the mac? Well.. you shouldn't be able to.
Can you do it from the Win machine? You should.
IIRC Cassini doesn't talk to strangers. I.e. it doesn't talk to anything but localhost.
If I am wrong - just open port 4243 in the firewall on the win machine and you should be good to go.
But otherwise...
Time to change web server.
Install IIS on the win machine.
In the Mac: surf to http://myWin7machine and see the IIS7 logo show.
If you don't you have a firewall issue. Open port 80. Try again.
If you have come this far then you can surf from the Mac to the IIS on the Win machine.
Time to set up your VS solution
Open the IIS admin GUI. Create a new Site. Let's say you call it MyTestSite. (you can always rename it later) Point it to your VS solution's web. Typically the same folder as web.config resides in. On the win machine: try surfing to "http://localhost/MyTestSite". Your site should show up. You might get an Apppool error.
Now try http://myWin7machine/MyTestSite on the Mac. It should work.
ROCK!
Time to set up debugging in VS
For debugging in IIS you have to connect to the process. In Win7 it requires elevated privileges so either you restart VS as admin or you try to connect and VS will do it for you.
The menu in VS is Debug->Attach to process and you choose w3wp.exe.
This is how you debug faster anyway - by connecting. Restarting your web for every debugging session is a waste of time.
To make connecting faster - use ctrl-alt-p and the continue with using the keyboard.
To make connecting even faster use a macro.
There is more info in these 4 articles: http://www.selfelected.com/tag/iis/
Set a breakpoint. Refresh your browser and the breakpoint should be hit.
Time to hack some code
Good luck!
I'm using Windows 10, VS 2015, Parallels 11 on iMac with OS X El Capitan (10.11.5). The following are the steps that worked for me:
On Windows side:
Get the IP (run ipconfig command in command window)
Get the host name (run hostname command in command window)
In control panel look for Windows Firewall -> Advanced Settings and add a new inbound rule and a new outbound rule. For both make sure you select Port, Allow Connection, TCP and specific IPs. I added a range of IPs 45000 - 45999 but you can select the range you like.
In Visual Studio:
Look for project properties and under web section change Server settings to look something like this.
Instead of "winmac" you will use the host name found in "Windows Side - Step 2". The port can be any number inside the range you setup for your firewall rules.
On Mac OS side:
Update /etc/hosts file. At the end of the file add the IP and host name that we found on steps 1 and 2 of the "Windows side" section. When you finish this step the file should like something similar to this.
Ready to debug:
Now you can start debugging in your Mac from Visual Studio. Make sure that before start the debugging process you select "Open In Mac" option (instead of Chrome or IE in your debugging options in visual studio).

Remote Debugger over internet (Remote IP machine)

My setup:
Local PC: x86 vista & visual studio
Client server: x64 server ( static ip ).
Currently I connect with it using Remote desktop. Remote Debugger is running as service and there is a user name with login as service privilege.
Can I configure remote debugger to this setup?
Guides, experiences will make my life little less of a hell. Thanks.
I had a similar problem, and like Hans Passant said above, a VPN is necessary. I was able to attach to the process and debug over the internet by doing the following:
Install the latest microsoft remote debugger on the server.
Install Hamachi on both my local machine and the server and connect so that I was on the same network.
Go to Debug->Attach To Process on my local machine's Visual studios and enter the Hamachi IP address of the server.
Pick "show processes from all users" and pick the process in question.
Note: I was logged in as the exact same user on both machines and had the same password on each.
I hope that helps someone out there.
There's no way to channel your debugger to work over Remote Desktop.
Check out How to: Set Up Remote Debugging, specifically the "Configuring the Windows Firewall" section. You will need make sure you can connect to the correct ports, which will require Software and/or Hardware firewall changes. A VPN could be part of the solution (as #Hans Passant suggested in his comment).
A simpler answer may be to install Visual Studio on a machine within the same network as where you're trying to debug. Then your debugger is making a local connection and you are still interacting with the remote network via Remote Desktop. I'm not sure if this is an option.
For me it just worked over a public ip address. Ensure Visual Studio remote tools will open firewall ports for all relevant networks when installing. Also ensure the connection target public IP address is written with the TCP port (the default for VS2019 is 4024) when listing processes.
No 3rd party apps needed!
(I advise to follow this tutorial, especially the bottom part titled "Set up the remote debugger"). However, to say shortly, after installing Remote Debugging Tools on remote machine, run it with administrator privilegges and then:
Open up Windows Firewall settings page
Click Advanced Settings and there will show up such window:
Click Inbound Rules->New Rule and choose on the following pages:
- [Rule Type] Custom
- [Program] Specific program (and choose : C:\Program Files\Visual Studio\Common7\IDE\Remote Debugger\x64\msvsmon.exe or whatever is your correct path, also note x86/x64 your desired route)
- [Protocol and Ports] Skip that page by clicking Next (or for maximum security, you can actually choose the exact port that Remote Debugger window is showing)
- [Scope] Choose in the second field (where it says Which REMOTE IP..) your current IP address
- [Action] Allow connection
- [Profile] Next
- [Name] whatever slug you want to identify, i.e. My rule for VS
The last step what you might need, is to set the Junction (hardlink) for folder on remote machine to correctly resolve the application files:
* When connecting with Remote-Desktop, share drive from Local Resources > More > Drives > C
* After you connect, on remote "My PC" there will appear your "mapped drive" and copy it's location (i.e. \\RobertoPC\). Then open CMD with admin privilegges and execute:
mklink /D C:\my_folder \\RobertoPC\C\my_folder
On your local PC C: drive create a folder my_folder and put the project into that folder, and run the project with remote debugging option:

Remote Debugging .net

I've read all related remote debug entries here and couldn't find an answer to my problem. I've trying to setup remote debugging to test a console app.
Dev Machine - Vista, VS 2008
Remote Machine - Win 2008
I've followed the steps in this article to configure it and I'm stuck with the following error when I try to list processes in remote machine under 'Attach to Process'.
"The remote procedure call failed and did not execute".
But in my remote machines 'Remote Debug Monitor' I see that the dev machine connection was established.
Can anyone provide me with any clues?
Whenever I run into this problem the first thing I do is disable the firewall on both computers. Firewall problems are the most common issue I run into with remote debugging and it's best to eliminate that problem from the start.
Do take care to turn the firewall back on when you're done diagnosing the problem :).

Resources