How to Remote Debug Console application - c#

Does any know how can I remote Debug Console application?
With snippet I can Hold the execution process util enter into the main code but, when I attach to the process from VS breakpoint appears not hittable.
static void Main(string[] args)
{
if (args.Any(arg => arg == "debug"))
{
while (!Debugger.IsAttached)
{
Thread.Sleep(10000);
}
Debugger.Break();
}
}

What you are showing is not how remote debugging works. You run an application on another machine (usually within your workgroup/domain) with the Remote Debugging tools installed on the REMOTE machine that match your version of Visual Studio. Make sure you deploy the application compiled as DEBUG and have the symbols available on the remote computer.
Then on your local machine, you need to go to the Debug Menu --> Attach to Process and connect the debugger to the running process that you want to debug on the remote computer. Now when the code is running and hits a breakpoint that you set locally (or exception), you'll see the debugger pause on your local computer.
MSDN: https://msdn.microsoft.com/en-us/library/vstudio/bt727f1t%28v=vs.110%29.aspx
EDIT - Locating Symbols File:
If you look in the location of your compiled binaries (bin folder then the compile type) and locate the file that ends in *.pdb. This contains the symbols. Make sure its in the same location as the exe on the remote computer

Related

Remote debugging throws strange exception

When remote debugging my UWP application, VS always throws the following error after deployment process starts:
Error: Exception has been thrown by the target of an invocation.
Remote machine is a Win10 VM. The application runs fine when I select "Local Machine" from target machines list.
Things that I have ensured:
VM and development machine can see each other.
Remote tools are installed on the VM and Remote debugger is running.
Remote debugger says "[UserX] connected" when I start deployment, so VS is talking to it.
I have tried all 3 modes of authentication (None, Windows, Universal) and neither works.
I have restored NuGet packages, rebuilt all projects in the solution etc.
I have tried "Debug instead of Launch" checkbox and "Uninstall and reinstall my package" options too.
Has anyone else seen this behavior?
(Exception has been thrown by the target of an invocation generally contains a more specific exception inside it that shows what actually went wrong, but in this case I do not have any way to dig into the main exception).
Here's a snapshot of Output window:
Edit
Some more information. The error changes to the following if I choose Universal authentication:
Error: Field not found: 'Microsoft.VisualStudio.ImmersiveProjectServices.BootstrapperOperationPackage.StandardCollectorCpuAgent'.

Require a full clean/rebuild prior to running a console application in Visual Studio

I have a c# console application project in visual studio that should only be run:
with the debugger attached
and only after a full clean / rebuild
Is there a way to force the project to fail if hasn't had a full clean/rebuild prior to launch?
Background info: The application is used to deploy versions of another application. It gathers up everything that's needed from various sources including downloads, zips them and and places them in a version deployment system.
One of the sources it gathers up files from is the output directory of another project that it references. The full clean/rebuild is required to ensure that output directory contains the latest and correct binaries.
The REAL problem I'm trying to solve is making sure that we are deploying the latest and correct binaries from another project.
The only way for an application to know if it was built-clean is for it to inspect the rest of the files in the directory it lives in, how you do that is up to you (try using FileInfo and inspect the LastWriteTime property).
As for the debugger, try this:
using System.Diagnostics;
using System.Threading;
...
public static Int32 Main(String[] args) {
if( !Debugger.IsAttached ) {
Console.WriteLine("No debugger attached. Execution will resume once a debugger is attached.");
while( !Debugger.IsAttached ) Thread.Sleep( 100 );
}
}

No output produced for C# Console Application on 'Start without Debugging'

When attempting to run a C# console application without the debugger (ie Ctrl+F5) no output appears in the terminal.
When run with the debugger (ie just F5), program executes as expected.
I made a quick test project to make sure it wasn't just my project:
namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Test");
Console.ReadKey();
}
}
}
Run with the debugger, "Test" is output to console, without it, nothing.
I don't know what I've changed, because (my original) programme was running fine without the debugger before now
Problem was found to be Avast preventing the executable from running properly. Temporarily disabling the File System Shield acts as a workaround.
Visual Studio 14.0.23107.0 D14REL
Avast 10.4.2233 (virus definition version: 151130-0)

VS 2010 remote debugger breakpoint will not currently be hit. No symbols have been loaded for this document

1) Make an Windows account on Host Machine. Log In.
2) Make an Windows account, with same user name and password as Host Machine, on the Remote Machine. Log In.
3) Copy all .pdb files to same directory as .exe on the Remote Machine.
4) Run Remote Debugger on the Remote Machine.
5) Tools -> Options
6) Radio Button to "No Authentication (native only)" and Check "Allow any user to debug", OK.
7) Run the .exe (debug build) on the Remote Machine.
8) On the Host Machine, open your solution.
9) Debug -> Attach To Process
10) Transport : Remote ( Native only with no authentication )
11) Qualifier : Server IP
12) Refresh
13) Choose the application to debug.
14) Attach
application seems to be running in the visual studio but all the breakpoints grey out with the following comment :
breakpoint will not currently be hit. No symbols have been loaded for this document
I did the folowing I deploy my applicatiob (including the pdb files) in the remote pc under c:\abc
I add the symbols location as you can see in the screenshot and I try to debug from my pc to the remote pc butstill no breackpoint
Any Idea?
When remotely debugging native code, your symbols must be on the machine with Visual Studio, not on the remote machine.
To let VS find the symbols, just add a folder containing the symbols to your symbol path. Go Tools > Options > Debugging > Symbols, and add the folder to the list.
it seems that if you used native you cannt debug c# .net application

crashdump debugging with Visual Studio 2010

I am trying to get crash dump debugging working with 2010, but it keeps failing.
I get this error when I try to start debugging:
"Managed Minidump Debugging: The signature verification for the file 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscordbi.dll' failed with the error 0x800700c1.:
I'm using the simplest program I can think of just to get off the ground (below).
Here are the steps I am taking:
Build
Run with a double-click from Windows explorer
right-click on the process in TaskManager, and select "Create Dump File"
kill the process
open the dump file in Visual Studio (File | Open, set filter to crash dumps)
Select "Debug with Mixed"
much loading of symbols (I have MS Symbol server enabled)
Boom (I get an error dialog saying I need to specify my symbol path -- which I believe I have done -- MS symbol server is enabled, and my solution is loaded)
In the output window, I get the following error (note that there are also a bunch of successful symbol loads, including for my exe):
Managed Minidump Debugging: The signature verification for the file 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscordbi.dll' failed with the error 0x800700c1.
(All the while, the solution with the code for my exe is loaded in the Visual Studio instance).
Any idea what I am doing wrong? Is this the right procedure for crashdump debugging in VS 2010?
The test dummy program:
class Program
{
public static string AStaticProperty = "Hello World";
static void Main(string[] args)
{
DoLoop(10000);
}
static void DoLoop(int iterations)
{
for (int i = 0; i < iterations; i--)
System.Threading.Thread.Sleep(500);
}
}
Edit
I'm going to vote to close -- I don't know exactly what the deal is, but everything is working now.
Here's what I did:
I started debugging the running process in VS 2010
I used the "save dump file" option off of the debug menu in 2010
I stopped the process and loaded the dump file.
It worked, so I thought "hmm, maybe the problem was with the dump file that I created (had used both adplus and TaskManager).
But no, now those work too. (although they failed very reliably until I did the 3 steps above). Weird, but now I cannot repro, so I'm going to vote to close.
Maybe this question/answers "Symbol issue when debugging C# code" helps you out.
The common tool used to debug dumps is WinDbg which is available in Debugging Tools for Windows. For x64 dumps you need the x64 debugger, while for x86 you need x86 debugger.
Visual Studio is x86 only, so you should not expect it can debug all dumps.
I think that this was an unstable machine/need a reboot issue. I have been unable to repro the problem

Categories