Reputation: 135
Background is I have an old addin which i use to install other addin and remove the old one on ThisAddIn_Startup . Everything seemed to work fine,but found one Computer where solution didn't work.
I install and remove the addins successfully, but addin doesn't load on first load.
private static void EnableNewPlugin()
{
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
object index = "NewAddin";
Office.COMAddIn addin = null;
addin = app.COMAddIns.Item(ref index);
addin.Connect = false;
addin.Connect = true;
}
So this method works on all other computers but the problem is on this one pc it doesn't seem to find it in app.COMAddIns list. So my question is how to programmatically restart the COMAddIns list?
Upvotes: 0
Views: 795
Reputation: 49455
The Update method of the COMAddins collection is used to refresh the list of COM add-ins from the Windows registry.
But why do you need to create a new Outlook application instance in the code? Do you develop an Outlook add-in? If so, you can use the Application property of the add-in class. Or you may get an instance of the running Outlook instance at runtime using GetActiveObject method of the Marshal class. See How to: Get and Log On to an Instance of Outlook for more information.
Also I'd suggest breaking the chain of calls and declaring each property or method call on a separate line of code. Thus, you will be able to release all underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about that in the Systematically Releasing Objects article in MSDN.
Upvotes: 1
Reputation: 135
If anyone faces same issue this seemed to work for me.
COMAddIns.Update();
Upvotes: 2