What can cause Outlook to change a COM-addin's LoadBehavior to 2 - other than unhandled exceptions?

前端 未结 5 2011
后悔当初
后悔当初 2020-12-28 17:14

For some weeks now we have been fighting with an issue where at a small number of customers our Outlook addin gets unloaded and disabled for yet undetermined reasons. By \"d

5条回答
  •  萌比男神i
    2020-12-28 17:48

    maybe you are a lockback policy victim. add a bypass key to registry, then it works. modern office versions or vsto creates the key while installation. the effect is: install a modern office too and the affffdin now are also loaded in older office. please take a look

    code snippet taken from NetOffice http://netoffice.codeplex.com

    public static void RegisterFunction(Type type)
    {
                try
                {
                    // add codebase value
                    Assembly thisAssembly = Assembly.GetAssembly(typeof(ExampleClassicAddin));
                    RegistryKey key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32\\1.0.0.0");
                    key.SetValue("CodeBase", thisAssembly.CodeBase);
                    key.Close();
    
                    key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32");
                    key.SetValue("CodeBase", thisAssembly.CodeBase);
                    key.Close();
    
                    // add bypass key
                    // http://support.microsoft.com/kb/948461
                    key = Registry.ClassesRoot.CreateSubKey("Interface\\{000C0601-0000-0000-C000-000000000046}");
                    string defaultValue = key.GetValue("") as string;
                    if (null == defaultValue)
                        key.SetValue("", "Office .NET Framework Lockback Bypass Key");
                    key.Close();
    
                    // add addin key
                    Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable");
                    Registry.CurrentUser.CreateSubKey(_addinRegistryKey + _prodId);
                    RegistryKey rk = Registry.CurrentUser.OpenSubKey(_addinRegistryKey + _prodId, true);
                    rk.SetValue("LoadBehavior", Convert.ToInt32(3));
                    rk.SetValue("FriendlyName", _addinName);
                    rk.SetValue("Description", "NetOffice COMAddinExample with classic UI");
                    rk.Close();
                }
                catch (Exception ex)
                {
                    string details = string.Format("{1}{1}Details:{1}{1}{0}", ex.Message, Environment.NewLine);
                    MessageBox.Show("An error occured." + details, "Register " + _addinName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
    }
    

提交回复
热议问题