Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difficulty starting VS 2010 debugger attached to Outlook to debug plugin

I'm trying to write an Outlook Addin in C# using Visual Studio 2010 and WPF and it's turning out to be difficult to debug. I would like to have VS automatically attach to OUTLOOK.EXE upon startup so that I can hit breakpoints easily. So, I went into the project's properties > Debug tab > Start Action and changed this setting from "Start project" (which of course won't work because it's a DLL) to "Start external program."

This seems to work; Outlook starts and clearly the debugger is attached. However, no breakpoints are hit. I noticed that when I go into the "Attach to Process" dialog it says that Outlook is only running x86 (which I think is incorrect because my manged code is running in that address space -- right?), so in the Debug tab of the Settings panel I clicked "Enable unmanaged code debugging," and now I'm out of ideas. I also can't pause the process because I get an error telling me that the process isn't running the type of code I selected to debug. I know my Addin is definitely loaded and executing because I can see it working.

As a workaround I've been using System.Diagnostics.Debugger.Launch(), which is annoying, but it works. Any ideas?

like image 624
Hut8 Avatar asked Jul 07 '10 19:07

Hut8


1 Answers

So it turns out that Outlook doesn't load the CLR on startup (it must be loaded shortly thereafter when it becomes necessary), which apparently confuses the VS debugger and causes it to only debug native code. To force it to load the CLR immediately, create an OUTLOOK.EXE.config file in the same folder with:

<configuration>
   <startup>
      <supportedRuntime version="v2.0.50727"/> <!-- or whatever -->
   </startup>
</configuration>

which is from this blog post. Then, even when VS starts attached, it will debug CLR code

like image 144
Hut8 Avatar answered Sep 22 '22 05:09

Hut8