views:

41

answers:

2

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?

+1  A: 

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

bowenl2
A: 

Here is excellent explanation how properly configure VS 2010:
http://blogs.msdn.com/b/mshneer/archive/2010/03/19/com-shim-wizards-for-vs-2010.aspx
follow "Debugging add-ins targeting CLR 2.0 in Visual Studio 2010".

airmax