Remote Debug .NET dll - c#

I have a class library project done in visual studio 2012.
When building this project, a dll is generated.
This dll is deployed in a machine that is in the local network and is consumed by an application that I have no control (third-party).
Is there any way to debug this dll remotely with visual studio 2012?
For example: Attach the dll and await a call to them from the third-party application, then debug.

Download and install the Visual Studio remote tools on the machine that you are deploying to. https://www.microsoft.com/en-gb/download/details.aspx?id=38184
Run that program on the remote computer
Then launch you visual studio select Debug -> Attach to process -> Choose "Remote" for the transport option and enter the ipaddress or hostname for the qualifier.
All the processes should be listed for the remote machine. Choose the process which is loading your DLL. When the remote program uses your dll then your breakpoints will be hit.
If you receive any errors when attempting to attach to the remote machine your first step should be to restart visual studio. It always breaks for me and restarting visual studio fixes it.

Related

How to debug a Visual Studio 2022 console application running as a service using a gMSA

I am building a .NET 6 application in C# using Visual Studio 2022. The application has a worker service that runs a console application. A Group Managed Service Account (gMSA) has been created for me and I can successfully install the service (using PowerShell) under the gMSA credentials on my local PC as well as a staging server. The gMSA passes Active Directory credentials from the service context to my application and works correctly. However, I do not have a way to debug my application using the gMSA account on my local PC.
Using a container or Azure is not an option and because this is a console application, an IIS-based solution is not possible either. I initially thought I would use runas to log into Visual Studio 2022 as the gMSA, but learned that runas would not work with a gMSA and that the preferred method to log into an application as a gMSA would be to use PsExec (64-bit version).
I attempted to do this, but was only able to log in via a command prompt as "nt authority\system" using
C:\psexec\PSExec64.exe -s cmd.exe
When I would attempt to log into the gMSA using
C:\psexec\PSExec64.exe \\local_pc\c$ -i -u gMSA_username -p ~ cmd.exe
no error message was displayed, but also no Microsoft copyright message (which is what is displayed when the command is successful). This seems to suggest the command failed in a way that could not be reflected in an error message. (It is worth mentioning that I also tried using both commands to open up a PSExec pipe and then connect using a gMSA, but I could not get that process to work.)
Adding to this issue is that Visual Studio 2022 no longer offers the "Start external program" functionality under the Debug section of a project's properties. So even if I was able to run a command prompt under a gMSA, I do not know how I could use that knowledge to log into Visual Studio under the gMSA credentials.
I would like to know how to debug my console application running as a service in Visual Studio 2022 using a gMSA. I am willing to do this using PSExec or another method. Any assistance offered will be greatly appreciated.
There were a couple of issues I had to resolve to be able to debug my .NET 6 service running a console application in Visual Studio 2022 using a gMSA. Here is how I got this to work:
At some point while I was trying to resolve my issues, the gMSA membership for my development PC was removed by another person in my IT Department. As it was explained to me, another computer was added to the gMSA, but the PowerShell command that was used overwrote the existing gMSA membership, including my development PC (the command adding a new computer to the gMSA membership should have included my development PC and any other existing gMSA computer members). Once this was resolved, I could tackle other issues.
Because I could find no way to share the gMSA context directly within my development environment (Visual Studio has no means, to my understanding, of running as a system process, gMSA, or an impersonation of a gMSA) I decided to try to attach a debugger to the service while it was running. This did not work until I discovered an SO post on a bug in the Visual Studio Just-In-Time Debugger. Per this post I navigated to
Computer\HKEY_CLASSES_ROOT\AppID\{E62A7A31-6025-408E-87F6-81AEB0DC9347}
in my development PC's registry and changed the value of AppIDFlags from 0x28 to 0x8. This got the Just-Time-Debugger working.
Once these issues were resolved I placed
#if DEBUG
Debugger.Launch();
#endif
in the StartAsync method of my .NET 6 worker service (worker.cs) so that the debugger would function within the gMSA context. After publishing the code to the location on my development computer that corresponds to the executable path accessed by the service I started the service and was prompted to attach the debugger. Upon doing so, I was able to debug under the gMSA context and access Active Directory via the gMSA in my Visual Studio 2022 development environment.

Trying to install Window Service on Production Server which does not have VS 2015 installed

I developed a Window Service which is running successfully(tested using Developer Command Prompt for VS 2015) on my local machine because I have Visual Studio 2015 installed. My machine is a development Server.
After successfully tested it on my machine, I tried to install the same process using installutil.exe.But, I think, this exe is not present on my Window Production server because VS 2015 is not installed on production server? I have IIS installed and my website is deployed there and working fine. I found that there is no Developer Command Prompt for VS 2015 on production server
Do I need any other way to install Window Server on my Production Server?
InstallUtil is a developer tool, so it is not present on most machines without Visual Studio. Besides creating a full blown MSI installer, you can implement a self-install that behaves like installutil. An alternative to implementing this yourself is to build your service using Topshelf because it includes this self-install functionality.

Debug code on machine without installing Visual Studio

I have one test machine that my program needs to run on that machine. It fails to run but I don't know the reason.
I want to debug the code on that machine to check the issue without installing Visual Studio 2012 on that machine. I have the source code of the program. What should I do?
Thanks.
You will need to use the remote debugging tools, go to your start menu, find your visual studio and expand it, find Visual Studio Tools and then remote debugging folder.
When you have this copy the x86 or x64 folder over to the machine you want to debug on and run the application or web page and msvsmon.exe.
Then on your machine from the debugging menu attach to process, and then target the machine that you want to run against.
Then look for the process you want to debug
You can use remote debugging and debug the remote code on your machine as you have the source code. You can also write exception logs in remote application to know what error has occurred at what place in your code. For remote debugging the see the detailed explanation about remote debugging as under from MSDN article.
How to: Enable Remote Debugging
Visual Studio provides support for remote debugging, that is, the ability to debug an .exe on another computer connected to your network. The Use remote machine property on the Debug page of the Project Designer enables remote debugging of an .exe. When this option is selected, you must specify the name of the machine on which the .exe will run. The location of the .exe on the remote machine must match the value of the Make exe path property, which is on the Compile page of the Project Designer.
In order to debug on a remote machine, the following conditions must be met:
The remote machine must have debugger components installed.
The user of the local machine needs to be in the Debugger Users group on the remote machine.
The .exe must be in a shareable directory on the remote machine.
For more information, see Remote Debugging Setup.
To enable remote debugging
Make sure that the remote machine is properly configured for remote 2. debugging. For more information, see Remote Debugging Setup.
With a project selected in Solution Explorer, on the Project menu click Properties.
Click the Debug tab.
Select the Use remote machine check box.
In the Use remote machine field, enter the name of the remote machine, using the format \domain\machinename.
I would check remote debugging. You can find information about here.

visual studio 2010 remote debugging: start external program: directory does not exist

Everything works if I do "Attach To Process".
But I need to debug a problem during launch of an application, so I need to be able to either "Start project" or "Start external program" the remote exe.
When I do, I get "directory does not exist". (Presumably, It is either looking for this non-existent directory LOCALLY, or it lacks permissions.)
Details:
* .Net Framework 3.5; C# Windows Form, with button that when clicked does
Debug.WriteLine("Hello World!");
Two Windows 7 Ultimate PCs, with same username and password, administrator.
Local PC:
Visual Studio 2010 Professional. Hello World project open and built.
Tested locally: Start Debugging / hit button / see "Hello World!" in VS Output pane.
Quit local version of app.
Remote PC:
Visual "Microsoft Visual C++ 2010 SP1 Redistributable" installed (so can run a debug version of this .Net application; before installing said "The program can't start because MSVCR100.dll is missing, when hit a breakpoint.").
Visual Studio Remote Debugging Monitor running.
says "(date/time) Msvsmon started a new server named Steve#FRESHINSTALL: Waiting for new connections".
When Attach to Process, says "FreshInstall\Steve connected".
Copy from local pc's project location (in default VS 2010 projects), \bin\debug* to C:\Code\HelloWorld*
Code folder is Shared with full privileges (just in case ...)
Attach to Process works fine:
click button => "Hello World" -- in Local PC's Output pane, just like when running locally.
Now, the problem. How LAUNCH the .exe remotely, instead of Attach to Process?
On Debug pane:
Tried "Start project"
alternatively, tried "Start external program:" C:\Code\HelloWorld\HelloWorld.exe" -- on Remote PC, this is the path to .exe
Working directory: "C:\Code\HelloWorld" <-- this directory ONLY exists on Remote PC (deliberately -- to make sure we aren't executing locally)
[checkmark] Use remote machine: FRESHINSTALL.
Tried with and without "Enable the Visual Studio hosting process".
When do "Start Debugging", all variations say "The working directory does not exist: "C:\Code\HelloWorld".
Well, of course not: it is on Remote PC, not locally.
Yet everywhere I look, this is what instructions say to do.
What am I supposed to do differently, or what could be wrong?
(Obviously this simple app, I could stick with Attach To Process. But I have a MUCH more complicated multiple-dll application, which is having a problem during startup. I need to breakpoint the "real" application during its start up, not after it is already running.)
(And the real situation I have to debug, is on the other side of the world, with a slow internet link. This is a local simulation of what is going wrong there. Not practical to install visual studio on the actual remote PC, to turn it into a local debugging situation. Spent a day trying to remote debug that; after I get it working on a local network, I have to duplicate the whole process with much less control over what is going on.)
In the interests of closing this question, to indicate that it has been addressed:
See wal's first comment on my question, and follow the link he gave, which I repeat here:
Visual Studio remote upload and debugging on other computer

.net Remote Debugging with Visual Studio -- "Can't find path."

My setup is:
Debugging computer:
Visual Studio 2008 Professional
Domain access
Application-running computer:
MSVSMon.exe
Workgroup only
Both computers:
Windows XP pro
Same local username and password
Access to same workgroup
I log into the same local username and password on both computers (username == "debugger"), and point VS 2008 to the remote computer, "Robot," under Project Properties > Use Remote Machine, and instruct VS to debug. In short, I followed the directions here and here. A ten second hang ensues then an error:
Error while trying to run project: Unable to start program '......\prog.exe'.
The system cannot find the path specified.
A few extra notes:
I tried "run an external program" pointing to the output of the project to no avail.
I'm not trying to debug an ASP.Net application.
The project source is on the local computer.
Please let me know if you have any solutions or leads. Thanks.
Make the executable and debug symbols accessible to both computers: in a shared or shareable directory. Make the debugging computer's project "start an external program" being the shared directory from the point of view of the application-running computer.
EDIT
Also, be sure that you are careful that you run the correct build. Don't run the Debug build remotely if the debug framework isn't installed on the remote machine!

Categories

Resources