Answered Debugging VSTO / C# App

  • 9. srpna 2012 16:53
     
     

    How does one properly "clean up" after ones self?

    I found some sample Outlook 2010 VSTO C# code that I compiled and ran successfully.  Yay!

    Now, I thought I would try stepping through the code to see exactly what was going on in the addin.

    Switched to Debug Build.

    Clicked on Run arrow and outlook started.

    I'd gotten some Value Out of Range Message.

    After, that I switched back to the release build then got a different value out of range message.

    I'm clear that the cause of my problems was that I likely did not unload the addin properly, and stuff just got left over.  It's a far different experience from my Native COM Add-In programming days in C/C++.

    Q:  How does one step through a VSTO/c#/2010 Addin?

    Q: How does one make sure that this Addin is completely unloaded?  (I've been mucking around the registry with mixed results)

    I really miss regsvr32

Všechny reakce

  • 9. srpna 2012 17:50
     
     
    You just compile in debug mode and start the addin, make sure it starts the correct executable in the Debug tab of the project. VSTO will add the necessary registry settings for you.
     
    Generally your VSTO addin will be registered in HKCU\Software\Office\<app>\Addins, where <app> would be Outlook/Excel/Word and so on. This is for application wide addins. If you use regedit to set LoadBehavior of the addin to 2 from 3 it won't load with the Office application. Some of this is version specific, so make sure to review the pinned posts and FAQ's at the top of this forum.
     
    Regsvr32 still works (I haven't tested in Win8 though). For Win7 (and Vista <gag>) I do have to start it "asAdmin" though for it to work. I use it all the time to register and unregister various dll's.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "TSRACT" <=?utf-8?B?VFNSQUNU?=> wrote in message news:d4485893-2aa1-433b-96c4-04de74be6b15...

    How does one properly "clean up" after ones self?

    I found some sample Outlook 2010 VSTO C# code that I compiled and ran successfully.  Yay!

    Now, I thought I would try stepping through the code to see exactly what was going on in the addin.

    Switched to Debug Build.

    Clicked on Run arrow and outlook started.

    I'd gotten some Value Out of Range Message.

    After, that I switched back to the release build then got a different value out of range message.

    I'm clear that the cause of my problems was that I likely did not unload the addin properly, and stuff just got left over.  It's a far different experience from my Native COM Add-In programming days in C/C++.

    Q:  How does one step through a VSTO/c#/2010 Addin?

    Q: How does one make sure that this Addin is completely unloaded?  (I've been mucking around the registry with mixed results)

    I really miss regsvr32


    Ken Slovak MVP - Outlook
  • 9. srpna 2012 18:08
     
     

    As you've pointed out, it shouldn't be rocket science.   I'll give my registry a good scrubbing and make sure the Addin isn't sitting in the office app disabled.  In other words remove all traces and start again.  I'll let you know how it goes.

    Thanks much

  • 9. srpna 2012 18:59
     
     

    You say that regsvr32.exe is still there.  Actually, what I meant is that I cannot use regsvr32.dll to unregister an adding the way I used to when I was writing my addins using C++/COM/ATL.

    I'll look up how to do it.  Won't waste your time here with that one.

  • 10. srpna 2012 9:19
     
     

    ANSWER TO MY QUESTION:

    I discovered that although the output of my code was placed under the Debug directory where I expected it to be, my code actually ran from 

    C:\Documents and settings\<username>Local Settings\Application Data\assembly\dll3\<some id>\<some other id>\<yet another id>\<id>\FinallyMyCode.dll

    So the first time this path got created my code was copied there and ran fine.  However, my updates were not put there.  I ended up having to copy my code to that directory.

    NOTE:  I have not created a setup project as yet.  I'm still getting my sea legs, if you will.

  • 10. srpna 2012 9:31
     
     

    [HERE'S What I was confused about:]

    MAJOR CONFUSION:

    I decided to create a dirt simple project.  All it would do is load and do nothing.  I pressed F5 and everything ran fine.  I checked to make sure it loaded.

    I then closed the app and went back to my IDE and then added a break point just to see if I could do some stepping.  The following dialog message appeared.

    "The following module was built either with optimizations enabled or without debug information:

    <path given>

    To debug this module, change its project build configuration to Debug mode ..."

    - The path given by the dialog is not the path to my debug directory.

    - My configuration is already set to Debug.

    VS2010 is loaded out of the box right now; I've been checking some sites and found a whole host of reasons this might be happening;  Some are referring to the GAC, and others are suggesting to Clean the solution and restart the IDE.

    I cannot believe hitting F5 could be such a source of problems.

    Is my being on Windows XP SP3 the source of any problems.  Maybe some old assemblies that should be gotten rid of?

  • 10. srpna 2012 9:39
     
     
    check your registry, this is where outlook gets info about dlls to load - maybe it is pointing to some other dir? best would be to delete whole key related to your add-in and let VS on next recompilation create it anew.
  • 10. srpna 2012 14:17
     
     Odpovědět
    The path where the code is running sounds like it's being utilized by Shadow Copy to run the code there. If you check where the code is running from even in deployed release addins, it's often running from an unexpected location.
     
    That can be checked by logging Assembly.GetExecutingAssembly().Location as opposed to Assembly.GetExecutingAssembly().CodeBase.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "DamianD" <=?utf-8?B?RGFtaWFuRA==?=> wrote in message news:7d6d8744-a6da-419f-8ca2-e2cce14ff218...
    check your registry, this is where outlook gets info about dlls to load - maybe it is pointing to some other dir? best would be to delete whole key related to your add-in and let VS on next recompilation create it anew.

    Ken Slovak MVP - Outlook
  • 10. srpna 2012 15:04
     
     

    Yeah, this one was a real head scratcher.  Eventually I stumbled across where the code was running from.

    Can't wait for my VSTO programming book to arrive. 

    Thanks folks.  I am archiving your suggestions... good on the basics. Nice