none
"Not loaded. A runtime error occurred during loading of COM add-in "

    Question

  • Hi

     

    I know there has been written quite a bit on this topic. But I have not found a suitable answer in the forums so far, and I have tried solving this problem for the last three days. So I hope someone can help me. (Besides, maybe this ought to be managed automatically by Visual Studio).

     

    I've tried

    * try/catch -blocks

    * Repairing the VSTO Runtime

    * kb908002

    * dependencywalker

    * I do not think that I am running Word in elevated mode

     

    I have Visual studio 2005 and Office 2007 running on Vista. I have created a Word Addin project, added a "ribbon support" and uncommented as required in ..ribbon.vb TODO. Exept for choice of names, the code is generated automatically by VS. This resulting add-in works like a dream when debugging in Visual Studio.

     

    And it is registered by VS and thus works fine when I start Word outside Visual studio.

     

    Then I build the setup-project, and install the add-in to a different directory on the same disk / same machine.

     

    If I then run Word, I get the error "Not loaded. A runtime error occurred during loading of COM add-in ".

     

    Entering Visual studio and running F5 or ctrl/F5 makes it function again.

     

    If I then go to registry and change "manifest" from

    C:\Users\BjornS\Documents\Visual Studio 2005\Projects\Stortinget\StortingXmlAddIn\StortingXmlAddInSetup\Debug\StortingXmlAddIn.dll.manifest

    to

    C:\Program Files\Structurum\StortingXmlAddIn\StortingXmlAddIn.dll.manifest

    then I get the same error. And if I reverse the process, then the error disappears,

     

    I've tried to do it the other direction after installation of the add-in but that does not help removing the error.

     

    The files in the directories are

    StortingXmlAddIn.dll
    StortingXmlAddIn.dll.manifest
    StortingXmlAddIn.pdb (debug information thrown in to make it identical)

     

    Seemingly

     * this is not about missing DLL's as it is the same files in the two directories, on the same machine and disk.

    *  there is information outside the registry that Visual Studio sets to right values, but that the setup-project do not.

    *  from other postings on the forum, this seems to be something concerning Vista.

     

    Do anyone have any suggestions?

     

    Regards

    Bjørn

    Thursday, December 06, 2007 6:47 PM

Answers

  • Hi Bjørn

     

    You need to use caspol to grant full trust to your assembly after deploying. And then load it manually in Word. I have already tested it in my Vista machine. It works fine.

    To grant full trust to your assembly, follow the following steps:

    1.       Start Menu->All Programs->Microsoft Visual Studio 2005->Visual Studio Tools->Visual Studio 2005 Command Prompt

    2.       In the Command Line, type as follows:

    caspol -u -ag All_Code -url "C:\Test\WordAddIn.dll" FullTrust -n "Test"

    (I install my Add-in in C:\Test. You need to replace "C:\Test\WordAddIn.dll" with your assembly’s full path)

     

     

    Thanks

    Ji

     

    Monday, December 10, 2007 5:21 AM
    Moderator
  • Thanks Ji,

     

    Code Access Security Policy Tool (Caspol.exe) worked fine.

     

    Of course: What I reallly wanted is to deploy the Add-in to a bunch of users, so the manual stuff isn't really my cup of tea. But it was nice to have confirmed that full trust was the problem, and it put me on track for the solution I needed:

     

    That is, use of setSecurity project as described in

    "Deploying Visual Studio 2005 Tools for Office Solutions Using Windows Installer: Walkthroughs (Part 2 of 2)"

    http://msdn2.microsoft.com/en-us/library/aa537179(office.11).aspx

    "Before a Visual Studio 2005 Tools for Office solution can run, the customization assembly must have FullTrust permissions. The sample custom action included in the source code accompanying this article demonstrates how to grant permissions to the assembly that is installed on the user's computer.

    To add the custom action project to the solution

    1.    Using Windows Explorer, copy the SetSecurity project from the {SamplesDir}\projects directory to the directory containing the ExcelApplication Solution.

    Tip:

    By default, the SamplesDir directory is C:\Program Files\Microsoft Visual Studio 2005 Tools for Office Resources\VSTO2005 Windows Installer Sample

    2.    In Solution Explorer, right-click the ExcelApplication node.

    3.    Point to Add on the shortcut menu, and then click Existing Project.

    4.    Select the SetSecurity project.

    5.    Click OK.

    6.    In Solution Explorer, right-click the SetSecurity project, and then click Build.

    7.    Add the primary output of the SetSecurity project to the Setup project.

    This enables the Windows Installer file to run the custom action that edits the security policy on the user's computer. "

     

    The sample setSecurity project can be found at:

    "Visual Studio 2005 Tools for Office Second Edition Sample: Deploying Office Solutions Using Windows Installer"

    http://www.microsoft.com/downloads/details.aspx?familyid=6991E869-8D5B-45F4-91E7-B527BD236F4C&displaylang=en

     

    The resulting setup project, also uses caspol internally, and creates a SetSecurity.dll that is deployed with the assembly.

     

    So again: Thanks, but ...

     

    Is there any better ways to do this? Or is this the standard solution when deploying?

    Is there another way of doing it in Visual Studio 2008? Or has the same practice been continued?

     

     

    Regards

     

    Bjørn

     

     

     

     

     

    Monday, December 10, 2007 1:26 PM
  • Yeah, using custom action to grant full trust is the standard deploying approach in VSTO and VSTO SE.

     

    If you are working with VSTO 2008, you can use the ability of ClickOnce. With ClickOnce, we can deploy our solution on a Website and download and install it in Local ClickOnce Cache. The permission and auto updating will be controlled by ClickOnce, we do not need to use caspol manually any more. Please refer the MSDN site:

    http://msdn2.microsoft.com/en-us/library/bb386095(VS.90).aspx

     

     

    Thanks

    Ji

     

    Tuesday, December 11, 2007 2:22 AM
    Moderator

All replies

  • Still struggling,

     

    But this time by using Orcas in order to see if debug is better in this new version of VS.

    By running a different project and trying to load a VS2005 add-in (this time also with default names), I get the following message:

    ---------------------------------------------

    Could not load file or assembly 'WordAddIn1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418)


    ************** Exception Text **************
    System.IO.FileLoadException: Could not load file or assembly 'WordAddIn1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418)
    File name: 'WordAddIn1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ---> System.Security.Policy.PolicyException: Execution permission cannot be acquired.
       at System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission)
       at System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission)

    ---------------------------------------------

    Nice !

     

    Though, of course in retrospect I see that I also get the same error message when starting Word if I only have changed the add-inn ThisAddIn_Startup method:

     

    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

    Environment.SetEnvironmentVariable("VSTO_SUPPRESSDISPLAYALERTS", 0, EnvironmentVariableTarget.User)

    End Sub

     

    Do anyone have any suggestions what to do next?

     

    Regards

    Bjørn

    Friday, December 07, 2007 2:44 PM
  • Hi Bjørn

     

    You need to use caspol to grant full trust to your assembly after deploying. And then load it manually in Word. I have already tested it in my Vista machine. It works fine.

    To grant full trust to your assembly, follow the following steps:

    1.       Start Menu->All Programs->Microsoft Visual Studio 2005->Visual Studio Tools->Visual Studio 2005 Command Prompt

    2.       In the Command Line, type as follows:

    caspol -u -ag All_Code -url "C:\Test\WordAddIn.dll" FullTrust -n "Test"

    (I install my Add-in in C:\Test. You need to replace "C:\Test\WordAddIn.dll" with your assembly’s full path)

     

     

    Thanks

    Ji

     

    Monday, December 10, 2007 5:21 AM
    Moderator
  • Thanks Ji,

     

    Code Access Security Policy Tool (Caspol.exe) worked fine.

     

    Of course: What I reallly wanted is to deploy the Add-in to a bunch of users, so the manual stuff isn't really my cup of tea. But it was nice to have confirmed that full trust was the problem, and it put me on track for the solution I needed:

     

    That is, use of setSecurity project as described in

    "Deploying Visual Studio 2005 Tools for Office Solutions Using Windows Installer: Walkthroughs (Part 2 of 2)"

    http://msdn2.microsoft.com/en-us/library/aa537179(office.11).aspx

    "Before a Visual Studio 2005 Tools for Office solution can run, the customization assembly must have FullTrust permissions. The sample custom action included in the source code accompanying this article demonstrates how to grant permissions to the assembly that is installed on the user's computer.

    To add the custom action project to the solution

    1.    Using Windows Explorer, copy the SetSecurity project from the {SamplesDir}\projects directory to the directory containing the ExcelApplication Solution.

    Tip:

    By default, the SamplesDir directory is C:\Program Files\Microsoft Visual Studio 2005 Tools for Office Resources\VSTO2005 Windows Installer Sample

    2.    In Solution Explorer, right-click the ExcelApplication node.

    3.    Point to Add on the shortcut menu, and then click Existing Project.

    4.    Select the SetSecurity project.

    5.    Click OK.

    6.    In Solution Explorer, right-click the SetSecurity project, and then click Build.

    7.    Add the primary output of the SetSecurity project to the Setup project.

    This enables the Windows Installer file to run the custom action that edits the security policy on the user's computer. "

     

    The sample setSecurity project can be found at:

    "Visual Studio 2005 Tools for Office Second Edition Sample: Deploying Office Solutions Using Windows Installer"

    http://www.microsoft.com/downloads/details.aspx?familyid=6991E869-8D5B-45F4-91E7-B527BD236F4C&displaylang=en

     

    The resulting setup project, also uses caspol internally, and creates a SetSecurity.dll that is deployed with the assembly.

     

    So again: Thanks, but ...

     

    Is there any better ways to do this? Or is this the standard solution when deploying?

    Is there another way of doing it in Visual Studio 2008? Or has the same practice been continued?

     

     

    Regards

     

    Bjørn

     

     

     

     

     

    Monday, December 10, 2007 1:26 PM
  • Yeah, using custom action to grant full trust is the standard deploying approach in VSTO and VSTO SE.

     

    If you are working with VSTO 2008, you can use the ability of ClickOnce. With ClickOnce, we can deploy our solution on a Website and download and install it in Local ClickOnce Cache. The permission and auto updating will be controlled by ClickOnce, we do not need to use caspol manually any more. Please refer the MSDN site:

    http://msdn2.microsoft.com/en-us/library/bb386095(VS.90).aspx

     

     

    Thanks

    Ji

     

    Tuesday, December 11, 2007 2:22 AM
    Moderator
  • hello..

    I have been trying to develop an addin to outlook and i have followed all the steps mentioned to deploying the same. I used the same SetSecurity project as you said and added it too to my primary output. But i face the following problems

     1) I find that the addin creates a button in my outlook and displays the message box that i put in the ThisAddIn_Startup() method. But it doesnt not perform the any action on click of the button. I have created the click event inside a start() function which i am callin inside the same ThisAddIn_Startup() method. On click of this button i am invoking another form which i have created inside a seperate project. This form never gets displayed. I get no error messages and no exceptions are logged. I also find that in the COM Add-ins (under options) is loaded and working fine. What could be the error?

    2) I have also added KB908002  - (shared add in fix )as a prerequisite check along with dot net 2.0 framework. But everytime i double click the setup.exe, the KB908002 always gets installed inspite of it already being installed. How do i get around this problem?


    //This is the code that i am using

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                try
                {
                    MessageBox.Show("STARTUP");
                    applicationObject = this.Application.Application;

                    activeExplorer = applicationObject.ActiveExplorer();
                    commandBars = activeExplorer.CommandBars;
                    this.Start();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

    private void Start()
            {
                //create a button on the main toolbar if it doesn't already exist
                try
                {
                    buttonCHMT = (CommandBarButton)commandBars["Standard"].Controls[buttonCheckContactsCaption];
                }
                catch
                {
                    buttonCHMT =
                            (CommandBarButton)commandBars["Standard"].Controls.Add
                            (MsoControlType.msoControlButton, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                    buttonCHMT.Caption = buttonCheckContactsCaption;
                    buttonCHMT.OnAction = "!<HMT_Addin.ThisAddIn>";
                    buttonCHMT.TooltipText = "Honeywell Meeting Tracker";
                    //buttonCheckContacts.Picture =
                }
                buttonCHMT.Click += new _CommandBarButtonEvents_ClickEventHandler(buttonCheckContacts_Click);
            }


    The same code works fine when i use the F5 or the cntr+F5

    Regards
    Navin
    Wednesday, January 30, 2008 10:52 AM
  • Hi Navin,

     

    Creating the button OK proves that codes you post work right. The issue should be in the button click event handle. Could you please let us to see that part of codes.

    I note that you say you are invoking another form in a different project. This may be potential reason. If you have any other assemblies deployed with your Add-in assembly, and you Add in add reference to them, they need to be granted full trust to let the Add-in work properly.

    I mean, in your scenario, if you add reference to another dll(which implement the form), you need to create a new copy of SetSecurity project, and create another CustomAction to grant full trust to that dll manually.

     

     

    Thanks

    Ji

     

    Thursday, January 31, 2008 2:42 AM
    Moderator
  • Also, buttonCHMT needs to be declared at the class level so that it doesn't go out of scope and cease firing events.
    Thursday, January 31, 2008 3:31 AM
    Moderator
  • This really does make sense to me.

     

    Thanks,

    Xie

     

    Saturday, April 05, 2008 8:14 PM
  •  

    Hi All,

    As per my requirement, I have to create 2 Add-ins (One for power point and another for word).

    I am using vsto 2008 with office 2007
    I successfully created the add-in for power point but when I am creating an add-in for word 2007 then I get following error on the development machine itself.  



    "an add-in could not be found or could not be loaded"

    Cannot access a disposed object.
    ************** Exception Text **************
    System.ObjectDisposedException: Cannot access a disposed object.
       at Microsoft.Office.Tools.SmartTagCollection.BeginInit()
       at WordAddIn.ThisAddIn.BeginInitialization() in C:\ThisAddIn.Designer.vb:line 128
       at WordAddIn.ThisAddIn.InitializeDataBindings() in C:\WordAddIn\ThisAddIn.Designer.vb:line 65
       at Microsoft.VisualStudio.Tools.Office.EntryPointComponentBase.Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint.InitializeDataBindings()
       at Microsoft.VisualStudio.Tools.Applications.AddInAdapter.ExecutePhase(ExecutionPhases executionPhases)
       at Microsoft.VisualStudio.Tools.Office.Internal.OfficeAddInAdapter.InitializeEntryPointsHelper()


    So just to test the cause of the above error I removed all the code and tried to run the add-in file (but I get the same error).

    Power point addin and word addin both are created on the same machine, then Why do I get an error for word addin.

    I tried to give full trust to this assembly using caspol.exe (this is mentioned in one of the blogs). But it did not help.

    What should I do to get this working. Please suggest

    Wednesday, February 25, 2009 5:56 AM