In my dotnet core 2.0 application I re-launch the same application in a different process (with some different arguments) at a certain point. I want to be able to programmatically attach the current Visual Studio (2017) debugger to the new process.
Here is an example of how it is done in full framework but for starters the Marshal.GetActiveObject
method doesn't appear to exist.
Is there a different way to achieve this in dotnet core 2.0? Or is it just not possible?
You can attach the Visual Studio debugger to a running process on a local or remote computer. After the process is running, select Debug > Attach to Process or press Ctrl+Alt+p in Visual Studio, and use the Attach to Process dialog to attach the debugger to the process.
Set a breakpointTo set the breakpoint, click in the gutter to the left of the doWork function (or select the line of code and press F9). The breakpoint is set to the left of the opening brace ( { ). Now press F5 (or choose Debug > Start Debugging).
To start debugging, select IIS Express (<Browser name>) or Local IIS (<Browser name>) in the toolbar, select Start Debugging from the Debug menu, or press F5. The debugger pauses at the breakpoints. If the debugger can't hit the breakpoints, see Troubleshoot debugging.
To debug an ASP.NET application that has been deployed to IIS, install and run the remote tools on the computer where you deployed your app, and then attach to your running app from Visual Studio.
While this is changing, .Net Core was envisioned to be as cross-platform as possible and originally left out many 'windows-only' methods. That said, you can still call into the underlying windows functions using P/Invoke:
[DllImport("oleaut32.dll", PreserveSig = false)]
static extern void GetActiveObject(ref Guid rclsid, IntPtr pvReserved,
[MarshalAs(UnmanagedType.IUnknown)] out object ppunk);
[DllImport("ole32.dll")]
static extern int CLSIDFromProgID(
[MarshalAs(UnmanagedType.LPWStr)] string lpszProgID, out Guid pclsid);
....
// Replace XX with the correct version
CLSIDFromProgID($"VisualStudio.DTE.XX.0", out var classId);
GetActiveObject(ref classId, default, out dte);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With