locked
COM Addins / VSTO Addins Do not load no matter what I do... pls help RRS feed

  • Question

  • Hello,

     

    A couple of months back, for a larf, I tried making a basic COM Addin for Office 2007. I went through the steps, pushed the shiny buttons, edited the xml to manipulate the ribbon and 20 some minutes later, voila! I had the skeleton of an addin. So, I put it away in the "todo" pile...

     

    So I came back to it a couple of days ago, and it wouldnt load up. I tried numerous things, all by suggestions I found on the net. Also, I had tried starting from scratch, as well as using some of the supposed "working" examples from MS, all of which did not work..

     

    2 things frustrate me in addition to this new found "feature". 1) I cannot seem to debug or set breakpoints (and yes I am in the VS debug configuration)  and 2) none of the office products seem to spit out any sort of error log to say WHY The addin doesnt load, it simply disables it.

     

    If I actually had any of my code in the addin, I could maybe understand why things may not work, but I am getting absolutely nowhere, and so far I have spent more time then I care to admit in figuring this out.

     

    So, that is to say, can someone here provide me with an answer as to what I can do to make this thing fly as it once did? I would LIKE to have something to show for as a product at one point (and being able to debug would be great too) Smile

     

     

    Thanks muchly,

     

    Andrew

    Wednesday, April 2, 2008 5:50 PM

Answers

  • Hi Andrew,

     

    Here are all of the tricks I know (reposted from http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=818608&SiteID=1).  That thread is probably the best one out there for debugging add-in loading issues, so you'll probably want to review all of it if the blurb below doesn't help you.

     

    >>>>>>>>>>>>

    Sorry to hear you are having trouble.  You are going to need to back into this to see where things are breaking down.  Before we start, are you running Windows Vista on the problem machine?  If so, is your Add-in registered in HKCU and are you launching Excel with an elevated token?  Recent builds of Vista have disabled that scenario; otherwise malware could register itself as an add-in when running as user and then get elevated when the host application was launched elevated.  If that is what is happening, you just need to launch Excel normally (i.e. non-elevated).

    Assuming you aren't running Vista, the first thing to do is set VSTO_SUPPRESSDISPLAYALERTS=0 in your environment.  Then launch Excel under that environment and try again.  If there is an exception coming from us, that will allow you to see it.

    After that, you will want to start with the registry.  First find the Add-in registration under either HKCU or HKLM  (\Software\Microsoft\Office\Excel\Addins).  Locate the FriendlyName value.  Then go to HKCR and find the key that matches the friendly name.  Under that key, find the CLSID key and get the value.  Now find that key under HKCR\CLSID.  There should be an InProcServer32 key underneath.  The default value should point to AddInLoader.dll.  Verify that AddInLoader.dll exists where it is registered.  Next, check the ManifestLocation value.  Make sure the manifest exists in that location and make sure it correctly identifies the Add-in assembly and location.  If all of this is correct, then setup apparently worked.  Otherwise the problem is in your setup.

    Assuming setup worked correctly, you'll need to determine how far in the loading process you get.  The first step would be to attach a debugger to Excel (make sure you attach to debug native code) and attempt to load the Add-in.  After receiving the error, you will want to check the modules window in the debugger (Debug.Windows.Modules) and see if AddInLoader.dll got loaded.  If it did not, the first thing to do is go back to the registry and search on AddInLoader.dll.  You should find both a CLSID key and a TypeLib key.  Verify that the Add-In loader is installed where it should be.  If everything looks good, you are going to need to get your hands dirty and debug CoCreateInstance.  To set that breakpoint, type Ctrl-B to bring up the New Breakpoint dialog.  In the Function edit box, type {,,Ole32}_CoCreateInstance@20.  Set the language combo box to C and click Ok.  The breakpoint should show up as resolved in the breakpoint window.  If you don't have symbols, you can get them from our public symbol server--see http://support.microsoft.com/kb/311503.  Once you have the breakpoint set,  try loading the Add-in.  You should hit the CoCreateInstance breakpoint.  Step over it and check the return code.  Verify that you got a failure and see if the HRESULT gives you an answer.  Otherwise, you'll need to do some assembly level debugging to figure out what is going on.  The CoCreateInstance implementation is fairly straightforward.  At a high level, it will locate the passed in CLSID in the registry, find the InProcServer32 key, load the server, call _DllGetClassObject to get the IClassFactory and then call IClassFactory::CreateInstance.   You will just need to figure out where in that sequence you are getting a failure.

    Alternatively, if the Add-in loader is getting loaded, then we are either unable to create the AppDomain or we couldn't load the assembly.  The first thing to check would be the fusion log.  Run fuslogvw.exe from %ProgramFiles%\Microsoft.Net\SDK\v2.0\bin, click Settings, select Log all binds to disk, and click Ok.  Try to load your Add-in.  Then click the refresh button in the Log Viewer.  Check the log to see where Fusion is looking for things and see if that gives you any hints.  More than likely though, you never got this far--otherwise you should have gotten exceptions from the loader.  That said, do enable Common Language Runtime, Win32, and C++ exceptions in the exceptions dialog (make sure you are attached for both managed and native debugging) and try loading your Add-in.  If there are any exceptions going on, doing that will catch them. 

    Well there you have it.  An advanced course in debugging Add-in startup problems.  Hopefully that will enable you to sort out the problem.

     

    >>>>>>>>>>>>>>>

     

    The other possibility could be that you have some other Add-In installed in Office that is causing the .Net FX 1.1 framework to load.  If that happens, VSTO add-ins aren't going to load.  If you can't attach the Visual Studio debugger at all, that may well be what is happening.  You should be able to confirm this by attaching WinDbg (since it doesn't have .Net FX dependencies) and checking to see if the version of mscoree.dll (or any mscor*.dll) is 1.1 something. The 'lm' command will dump loaded modules once you have attached.  You can download WinDbg here: http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx).  You would need to get around this by creating an app.config file for the Office application that includes a SupportedRuntime element specifying the .Net FX 2.0 or greater.  See: http://msdn2.microsoft.com/en-us/library/9w519wzk(VS.85).aspx

     

    If the above doesn't help, you are probably into something very strange.  You might have a look at the following thread to see if it helps:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1031326&SiteID=1

     

    Sincerely,

     

    Geoff Darst

    Microsoft VSTO Team

     

    Friday, April 4, 2008 4:01 PM
    Answerer

All replies

  • Hello Andrew,

     

    I'm not sure if it helps here,

    but I would recommend the following:

     

    1. Goto Control Panel and do a Repair installation of your Office 2007

    2. Install the Office 2007 Primary interop assemblies

    3. Do a repair installation of Visual Studio (wich Version ?) + SP1 + (wich OS ?) -> VS Upgrade for Vista ???

    4. Install the VSTO SE

     

    Then try again.

    If that won't help,

    I would try to setup a virtual machine from scratch.

     

    Hope this helps,

    greets, Helmut

     

     

    Wednesday, April 2, 2008 6:39 PM
    Answerer
  • Helmut,

     

    Thank you for your suggestions. Before I had posted, I had already done suggestions #2, and #4. I tried #1 with no result. I am running VS 2005 pro SP1 on a Win XP pro box. I can set up the virtual machine with no problems, but my question remains, is there a way that I can find out exactly what the Office addin framework is unhappy about? Can I rig Office to provide some sort of verbose logging to tell me what is wrong? I have to think MS at one point during development had to troubleshoot this sort of issue. My main concern is that I dont want to leave my main development box "broken" if there is a way to get to the heart of the issue.

     

    Thanks again,

     

    Andrew

     

    Thursday, April 3, 2008 4:34 PM
  •  Andrew Maxin wrote:

    Thank you for your suggestions. Before I had posted, I had already done suggestions #2, and #4. I tried #1 with no result. I am running VS 2005 pro SP1 on a Win XP pro box. I can set up the virtual machine with no problems, but my question remains, is there a way that I can find out exactly what the Office addin framework is unhappy about? Can I rig Office to provide some sort of verbose logging to tell me what is wrong? I have to think MS at one point during development had to troubleshoot this sort of issue. My main concern is that I dont want to leave my main development box "broken" if there is a way to get to the heart of the issue.

    See if the information posted at the end of this message thread helps at all

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3074283&SiteID=1

    Thursday, April 3, 2008 4:59 PM
  • Cindy,

     

    Thank you for your suggestion. Unfortunately, I have been through that thread already to no avail. I shut off all other addins, tried safe mode, and set the environment variable, all of which to the same empty addin project to get the same result.

     

    Whatever is happening, it is new & exciting

     

    Thanks,

     

    Andrew

    Thursday, April 3, 2008 5:05 PM
  • Hi Andrew,

     

    All scratch Add In projects cannot debug? Quite strange!

    Have you tried to download updated version of VSTO Runtime and install it?

    http://www.microsoft.com/downloads/details.aspx?familyid=8315654B-A5AE-4108-B7FC-186402563F2B&displaylang=en

     

    Thanks,

    Ji

    Friday, April 4, 2008 7:28 AM
  • Ji,

     

    I sure did try that... I also went so far as to fire up a clean XP virtual machine put office 2007 on it as well as the .net runtimes. It still failed.

     

    Then, I went and made something in VB6 (pure COM) just to be sure this wasnt some silly security thing.. No, that came up just fine...

     

    So I ask this question: When I compile this .net addin, I am registering it for COM interop, so could it possibly be an interoperability issue between the COM/.net layer?? how would I test this? Is there some magic setting I can check?

     

    Another thing I noticed: I cannot set breakpoints in my code. I ran into this before because I had my configuration set to release instead of debug, however, I do not have access to the configuration manager dialog this time... weird...

     

    Ideas?

     

    Thanks,

     

    Andrew

    Friday, April 4, 2008 3:26 PM
  • Hi Andrew,

     

    Here are all of the tricks I know (reposted from http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=818608&SiteID=1).  That thread is probably the best one out there for debugging add-in loading issues, so you'll probably want to review all of it if the blurb below doesn't help you.

     

    >>>>>>>>>>>>

    Sorry to hear you are having trouble.  You are going to need to back into this to see where things are breaking down.  Before we start, are you running Windows Vista on the problem machine?  If so, is your Add-in registered in HKCU and are you launching Excel with an elevated token?  Recent builds of Vista have disabled that scenario; otherwise malware could register itself as an add-in when running as user and then get elevated when the host application was launched elevated.  If that is what is happening, you just need to launch Excel normally (i.e. non-elevated).

    Assuming you aren't running Vista, the first thing to do is set VSTO_SUPPRESSDISPLAYALERTS=0 in your environment.  Then launch Excel under that environment and try again.  If there is an exception coming from us, that will allow you to see it.

    After that, you will want to start with the registry.  First find the Add-in registration under either HKCU or HKLM  (\Software\Microsoft\Office\Excel\Addins).  Locate the FriendlyName value.  Then go to HKCR and find the key that matches the friendly name.  Under that key, find the CLSID key and get the value.  Now find that key under HKCR\CLSID.  There should be an InProcServer32 key underneath.  The default value should point to AddInLoader.dll.  Verify that AddInLoader.dll exists where it is registered.  Next, check the ManifestLocation value.  Make sure the manifest exists in that location and make sure it correctly identifies the Add-in assembly and location.  If all of this is correct, then setup apparently worked.  Otherwise the problem is in your setup.

    Assuming setup worked correctly, you'll need to determine how far in the loading process you get.  The first step would be to attach a debugger to Excel (make sure you attach to debug native code) and attempt to load the Add-in.  After receiving the error, you will want to check the modules window in the debugger (Debug.Windows.Modules) and see if AddInLoader.dll got loaded.  If it did not, the first thing to do is go back to the registry and search on AddInLoader.dll.  You should find both a CLSID key and a TypeLib key.  Verify that the Add-In loader is installed where it should be.  If everything looks good, you are going to need to get your hands dirty and debug CoCreateInstance.  To set that breakpoint, type Ctrl-B to bring up the New Breakpoint dialog.  In the Function edit box, type {,,Ole32}_CoCreateInstance@20.  Set the language combo box to C and click Ok.  The breakpoint should show up as resolved in the breakpoint window.  If you don't have symbols, you can get them from our public symbol server--see http://support.microsoft.com/kb/311503.  Once you have the breakpoint set,  try loading the Add-in.  You should hit the CoCreateInstance breakpoint.  Step over it and check the return code.  Verify that you got a failure and see if the HRESULT gives you an answer.  Otherwise, you'll need to do some assembly level debugging to figure out what is going on.  The CoCreateInstance implementation is fairly straightforward.  At a high level, it will locate the passed in CLSID in the registry, find the InProcServer32 key, load the server, call _DllGetClassObject to get the IClassFactory and then call IClassFactory::CreateInstance.   You will just need to figure out where in that sequence you are getting a failure.

    Alternatively, if the Add-in loader is getting loaded, then we are either unable to create the AppDomain or we couldn't load the assembly.  The first thing to check would be the fusion log.  Run fuslogvw.exe from %ProgramFiles%\Microsoft.Net\SDK\v2.0\bin, click Settings, select Log all binds to disk, and click Ok.  Try to load your Add-in.  Then click the refresh button in the Log Viewer.  Check the log to see where Fusion is looking for things and see if that gives you any hints.  More than likely though, you never got this far--otherwise you should have gotten exceptions from the loader.  That said, do enable Common Language Runtime, Win32, and C++ exceptions in the exceptions dialog (make sure you are attached for both managed and native debugging) and try loading your Add-in.  If there are any exceptions going on, doing that will catch them. 

    Well there you have it.  An advanced course in debugging Add-in startup problems.  Hopefully that will enable you to sort out the problem.

     

    >>>>>>>>>>>>>>>

     

    The other possibility could be that you have some other Add-In installed in Office that is causing the .Net FX 1.1 framework to load.  If that happens, VSTO add-ins aren't going to load.  If you can't attach the Visual Studio debugger at all, that may well be what is happening.  You should be able to confirm this by attaching WinDbg (since it doesn't have .Net FX dependencies) and checking to see if the version of mscoree.dll (or any mscor*.dll) is 1.1 something. The 'lm' command will dump loaded modules once you have attached.  You can download WinDbg here: http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx).  You would need to get around this by creating an app.config file for the Office application that includes a SupportedRuntime element specifying the .Net FX 2.0 or greater.  See: http://msdn2.microsoft.com/en-us/library/9w519wzk(VS.85).aspx

     

    If the above doesn't help, you are probably into something very strange.  You might have a look at the following thread to see if it helps:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1031326&SiteID=1

     

    Sincerely,

     

    Geoff Darst

    Microsoft VSTO Team

     

    Friday, April 4, 2008 4:01 PM
    Answerer
  •  

    Wow! Geoff -- way to turn on the info firehose... Smile

     

    I will plow through this and let you know how I make out...

     

     

    Thanks muchly,

     

    Andrew

    Friday, April 4, 2008 4:38 PM
  •  

    Geoff,

     

    So, I got through most of your post when I looked at the video tutorial on how to debug the unmanaged code in .net (shudder)

     

    Then I wondered to myself if I sent you my project to you if it would help...

     

    Then I noticed at the bottom of your post that you mentioned a conflict between versions of the .net runtimes.. So I checked my machine and I had version 1.1 of the framework on there. Also, That was the case on the test slice as well....

     

    SO,,, I pulled off the .NET 1.1 framework and VIOLA!!! it worked! (both COM & VSTO addins)

     

    So congrats! you win!

     

    Thank you all for your help!

     

    Regards,

     

    Andrew

    Friday, April 4, 2008 6:12 PM
  •  

    Hi Andrew,

     

    Glad to hear you figured out your problem.

     

    Just in case you missed it in my previous post, you can control the version of the runtime that gets loaded by creating a config file for the executable; i.e. Excel.exe.config and adding a SupportedRuntime element that redirects to the .Net FX v2.0 (as explained here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3106833&SiteID=1).  That way you can still keep the .Net FX 1.1 on your machine for any applications that specifically need it.

     

    Sincerely,

     

    Geoff Darst

    Microsoft VSTO Team

    Friday, April 4, 2008 9:09 PM
    Answerer
  • The link you supplied, points to this thread!

     

    pq

     

    Saturday, April 5, 2008 12:03 AM
  • Saturday, April 5, 2008 1:00 AM
    Answerer
  •  

    I guys.. I tried this as well and it didn't work since I only had .net v2 installed anyways, and now I have v3 too.

     

     

    Its really mind-numming why this isn't working.

     

     

    What exactly is required for any VSTO 2005 add-in to load and work properly...? Because it doesn't really make any sence setting up a setup-wizard in VS2005 and it doesn't pick up EVERYTHING required to make the VSTO add-in work.

     

     

     

    Thanks guys, I really appreciate it.

     

     

     

    cmTK

    Tuesday, May 13, 2008 8:17 AM
  • bom dia!

    I had strange error with word 2007 customization developed on vs 2008 sp1 on computer with Vista Business SP1 + VSTO 3.0+VSTO 3.0 SP1
    Customization not loaded with the exception:
    Customization could not be loaded because the application domain could not be created.

    ************** Exception Text **************
    Microsoft.VisualStudio.Tools.Applications.Runtime.CannotCreateCustomizationDomainException: Customization could not be loaded because the application domain could not be created. ---> System.Runtime.InteropServices.SEHException: External component has thrown an exception.
    at System.Drawing.SafeNativeMethods.Gdip.GdipMeasureString(HandleRef graphics, String textString, Int32 length, HandleRef font, GPRECTF& layoutRect, HandleRef stringFormat, GPRECTF& boundingBox, Int32& codepointsFitted, Int32& linesFilled)
    at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
    at System.Windows.Forms.Label.GetPreferredSizeCore(Size proposedConstraints)
    at System.Windows.Forms.Control.GetPreferredSize(Size proposedSize)
    at System.Windows.Forms.Label.GetPreferredSize(Size proposedSize)
    at System.Windows.Forms.Layout.TableLayout.InflateColumns(ContainerInfo containerInfo, Size proposedConstraints, Boolean measureOnly)
    at System.Windows.Forms.Layout.TableLayout.ApplyStyles(ContainerInfo containerInfo, Size proposedConstraints, Boolean measureOnly)
    at System.Windows.Forms.Layout.TableLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
    at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
    at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
    at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
    at System.Windows.Forms.TableLayoutPanel.OnLayout(LayoutEventArgs levent)
    at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
    at System.Windows.Forms.Control.PerformLayout()
    at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstallerDialog.InitializeComponent()
    at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstallerDialog.Initialize()
    at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstallerDialog.ShowDialog()
    at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstaller.Install(ClickOnceAddInDeploymentManager clickOnceAddInDeploymentManager, OfficeAddInDeploymentManager officeDeploymentManager, AddInInformation& info)
    at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstaller.ProcessInstallerOperation(ClickOnceAddInDeploymentManager clickOnceAddInDeploymentManager, OfficeAddInDeploymentManager officeAddInDeploymentManager, AddInInformation& info)
    at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstaller.ProcessInstallerOperation(ClickOnceAddInDeploymentManager clickOnceAddInDeploymentManager, OfficeAddInDeploymentManager officeAddInDeploymentManager, Boolean showUIDuringDeployment)
    at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.CreateCustomizationDomainInternal(String documentFullLocation, String documentName, String assemblyLocation, Boolean showUIDuringDeployment, IntPtr hostServiceProvider, IntPtr& executor)
    --- End of inner exception stack trace ---


    Also, I tried make simple empty word 2007 addin with click-once deployment and during setup i have almost same error:
    Customization URI: file:///C:/Users/Sony/Desktop/WordAddinTest_Setup/WordAddinTest.vsto
    Exception: External component has thrown an exception.


    ************** Exception Text **************
    System.Runtime.InteropServices.SEHException: External component has thrown an exception.
       at System.Drawing.SafeNativeMethods.Gdip.GdipMeasureString(HandleRef graphics, String textString, Int32 length, HandleRef font, GPRECTF& layoutRect, HandleRef stringFormat, GPRECTF& boundingBox, Int32& codepointsFitted, Int32& linesFilled)
       at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
       at System.Windows.Forms.Label.GetPreferredSizeCore(Size proposedConstraints)
       at System.Windows.Forms.Control.GetPreferredSize(Size proposedSize)
       at System.Windows.Forms.Label.GetPreferredSize(Size proposedSize)
       at System.Windows.Forms.Layout.TableLayout.InflateColumns(ContainerInfo containerInfo, Size proposedConstraints, Boolean measureOnly)
       at System.Windows.Forms.Layout.TableLayout.ApplyStyles(ContainerInfo containerInfo, Size proposedConstraints, Boolean measureOnly)
       at System.Windows.Forms.Layout.TableLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
       at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
       at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
       at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
       at System.Windows.Forms.TableLayoutPanel.OnLayout(LayoutEventArgs levent)
       at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
       at System.Windows.Forms.Control.PerformLayout()
       at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstallerDialog.InitializeComponent()
       at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstallerDialog.Initialize()
       at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstallerDialog.ShowDialog()
       at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstaller.Install(ClickOnceAddInDeploymentManager clickOnceAddInDeploymentManager, OfficeAddInDeploymentManager officeDeploymentManager, AddInInformation& info)
       at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstaller.ProcessInstallerOperation(ClickOnceAddInDeploymentManager clickOnceAddInDeploymentManager, OfficeAddInDeploymentManager officeAddInDeploymentManager, AddInInformation& info)
       at Microsoft.VisualStudio.Tools.Office.Runtime.SolutionInstaller.ProcessInstallerOperation(Boolean uninstall, Boolean silent, Uri manifest, Int32& errorCode, String& errorMessage)


    What could be wrong with GdipMeasureString?
    Tuesday, January 20, 2009 4:51 PM
  • I didn't find that adding MyAddin.dll.config had any effect, when SupportedRuntime was specified. However, we solved this issue in two ways:

    • Uninstalled .NET 1.1 (not really a solution, just a proof there's a problem!)
    • Converted from VSTO addin to Shared Office Addin (it doesn't involve AddinLoader.dll)

    When we converted the add-in to Shared Office addin, the deployment issue was gone, but now we have doubled our development time since migration of old code is complicated and time consuming.

    Friday, June 3, 2011 1:34 PM