How to attach a Visual Studio debugger to a Managed type process? - visual-studio-2010

I've been following this guide to debug a Windows Service application.
Basically, I need to attach the Visual Studio debugger to the process started after installing the Windows Service that has been developed. However, VS doesn't allow me attach the debugger to this process as shown in the following picture:
How can I attach the debugger to this process? If I clicked on any of the other processes the Attach button becomes enabled.
Any help would be greatly appreciated

check the checkbox Show processes from all users, then you will see AutomatedReports.exe. Attach that (not AutomatedReports.vshost.exe)
vshost is a host process to help with the debugging. More info on this MSDN Link
Also you need to place the following line in your service code where you want to hit the break point.
System.Diagnostics.Debugger.Break();

The service is probably running on a separate user account. Check the "Show processes from all users" checkbox and attach the debugger to AutomatedReports.exe process.
Also make sure that you are running a Debug build of the service, otherwise, you won't be able to debug a lot.

Have you tried to change the type of the code you are debugging?
Click on "Select ..."
Select "Debug these code types"
You can then select Types like: “Managed (v4.0…)"

Related

SharePoint 2013 Visual Studio workflow breakpoint not hit

I'm using VS 2013 and a SP 2013 farm solution which contains a workflow.
I'm desperately trying to debug my workflow to gain some inside information.
This is what I tried so far:
First of all I set a breakpoint on a GetCurrentItemId Activity
Next I hit F5.
The workflow test host console opens up and the web browser showing my sharepoint site
Next I navigate to my list and start the workflow on any (single) item
The workflow test console stays all black - not a single piece of information to find here
The workflow's internal status changes to "Completed".
...obviously my breakpoint has not been hit. WHY? :(
Solved
Reinstalling VS 2013 did in fact help.
From what I can see you have been starting your workflow in debug mode and trying to debug in on a list event.
Instead of doing that try adding your breakpoints (I always add breakpoint in the first scope) and then go to
Debug -> Attach to Process and look for Microsoft.Workflow.ServiceHost.exe and click attach.
Before doing any work with that list items to trigger the workflow verify that your breakpoints are active - if not try retracting your solution and redeploy, then one more time try attaching it to the WF service.
Hope it helps.
When you attach to the process Microsoft.Workflow.ServiceHost.exe you must select the type of code you will attach to. Just select Workflow and you´ll be able to see the workflow context variables.

Process is disabled in VS2010 attach to process dialog

I have a VS2010 running on a WTS machine (Windows2008).
I'm trying to attach the debugger into a process. The process is running a WPF client.
The process is presented in the attach to process dialog, but grayed out and the attach button is disabled.
I read through the discussions, and confirmed managed code is enabled for debugger, with no luck. Here are two screenshots representing the current situation (in the first image, the process I'm trying to debug is marked in blue - please note I'm running as admin):
snapshot goes here - but was removed by stack overflow...
After trying the automatic code type selection, I tried the manual way, with no luck. Here is the screenshot:
snapshot goes here - but was removed by stack overflow...
Any help would be appreciated.
Thanks,
Busi
Perhaps you are already attached to the process? Did start debugging before attaching to the process?
Found another cause/solution to this problem, select the 'Show processes from all users' and 'Show processes in all sessions' check boxes and I got two instances of my service, one greyed out (which was always visible) and another I could attach to. hth :).
I ran into the same issue with my windows service.
I could not attach to a running windows service that I built.
My solution has multiple projects with the windows service as the startup project.
I found out that my problem is caused by having the startup project is the same as the windows service.
To solve my problem, I just set a different project as the StartUp Project.
I'm not certain, but there may be a debugger already attached to the process, and that's why Visual Studio won't let you attach it. Are you certain that you're not running the application already in debug mode or do you have another VS instance running?
If you are trying to attach a web service or web app (w3wp.exe) then, try resetting the iis (iisreset). It worked for me.

Using "run as" with Visual Studio debugger

Is there any way to use the "Run As" option in Windows XP in conjunction with Visual Studio's debugger, to debug an issue that occurs in my application only when certain users are logged in?
I have ran the application from my machine using "run as" to pretend to be the user in question, and I got the same error as they did. I would like to debug this error and see where and what exactly is causing it. The error occurs specifically when a certain domain user is logged in, and never otherwise.
Is there any script or approach I can take to debug this error; that is too launch the application, as the problem user, and then use the debugger?
Trying to attach to the process didn't work since it was a C# managed process and VS didn't let me attach.
The first two options that come to mind are...
Log onto the machine as the user (simplest approach)
Right-click on the Visual Studio executable and run as that user.
I think that you could edit the .config file to use impoersonation, but I'm not sure if that will result in the app running truly the way it would for the user.
Although with good error handling, the error message itself should be enough to tell you where in the code the problem is... At the very worst, you could compile it in debug mode (so you have all the symbols) and add some global error hanlding and get the exact stack trace...
I use David Strattons second solution (run as Administrator) because my application requires administrator privileges (-> elevated).
Another solution could be to start the application as the user and use "Debug | Attach to process..."

How to debug Sharepoint solution/feature through Visual studio?

Recently I tried to install a webpart through wspbuilder utility to the Sharepoint Site. I have created, built and deployed a project to the 12 hive. After that installed the solution through Cental Administration Site and activated in the site collection.
I just wonder how can I debug the complex feature/solution ? Because both processes (build-deploy and activate) totally independent, how can I attach a process with the worker process ?
In the WSPBuilder context menu there is an option "Attach to IIS worker process". As long as the app is loaded (generally means that you have accessed a page in the SharePoint site before trying to attach) and the code deployed in SharePoint is the same as the code you have in Visual Studio, you should be able to set breakpoints and step through the code.
First, you need to open up your browser and navigate to the SharePoint website in question. Then, In Visual Studio, go to Debug --> Attach to Process, and find the w3wp.exe process associated with the Sharepoint website that you want to debug. Click it (the process) and then click the Attach button. You should now be able to debug any activities associated with your SharePoint feature.
Sometimes it is a bit of a pain to figure out which w3wp process to attach to. Try adding the following to your code to break into the debugger:
System.Diagnostics.Debugger.Break();
System.Diagnostics.Debugger.Break()
Like Muhimbi suggested, this is actually very useful in certain cases. Say you want to debug custom code (e.g. feature_deactivating event) when it might be invoked with stsadm and not the browser. (for e.g. you will have to use stsadm for feature deactivation when feature is hidden in UI).When using stsadm you cannot attach to cmd.exe because that's a separate process. If you type the command and hit enter and then find its id of stsadm.exe process to attach to, its too late. In situations like these, the command above is the easist and best solution
I tried the steps as mentioned here
go to Debug --> Attach to Process, and find the w3wp.exe process associated with the Sharepoint website that you want to debug
But I get "Breakpoints will not be hit, no symbols have currently been loaded for this document". Should I have to register the custom deployed solution dll using GACUTIL ? Should I have to copy the PDB files at any particular location ?
What am I missing here ?

Visual Studio Plug-in that can tell the Application Pool name of w3wp.exe when debugging

Is there any plug-in for Visual Studio that can display the associated Application Pool name for those w3wp processes when debugging them with "Attach to Process..." ?
Usually I have to do following steps before debugging:
c:> \Windows\system32\inetsrv\appcmd list wps
then I get the process id for the Application Pool I want to debug, and then attach it in the Attach to Process window.
I feel it will be very pleasure if there's a plug in can do this automatically, but didn't find any such thing after Googled.
You can use a macro—see my answer to a related question. I am practically always attaching to one of a few specific Application Pools, so I’ve made buttons to attach to those specifically in one click. If you really want to choose from a dynamic list each time you’ll just have to build that dialog, but you can lift from my macro code to get the list.

Resources