x64 COM Addin registration is working only for x86 Excel

137 Views Asked by At

I am struggling to register a C# class library dll to be used in Excel 64 bit, and i have checked every single spot in internet talking about this until now. My class library is simple, having one method (for tests now) to be used as Excel Addin.

1) When my class library is compiled to AnyCPU, i do see my Addin in the Windows registry, and it is visible and working fine but only for Excel 32 bit version, and not visible for Excel 64 bit. Here's a screenshot of the registry generated files:

Registry screenshot when my library is compiled to AnyCPU

2) When my class library is compiled to x64 (without doing any changes to the code), i do not see my Addin in the Windows registry, it's like the registration is failing or something. Here's a screenshot of what is generated in the register when compiled to x64:

Registry screenshot when my library is compiled to x64

So here you can see that my Class is not at all registred like when compiled to AnyCPU.

Here's the simple class i am using, where you can check the registration code am using:

interface IAutomationAddin
{
    string GetTest();
}

[Guid("249618F9-A4A0-4999-9712-280D2A1493FB")]
[ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
public class AutomationAddin : IAutomationAddin
{
    #region Constructors

    public AutomationAddin()
    {

    }

    #endregion Constructors

    #region Initialization (Register/Unregister functions)

    /// <summary>
    /// Specifies the method to call when you register an assembly for use from COM; 
    /// this allows for the execution of user-written code during the registration process.
    /// </summary>
    /// <param name="type"></param>
    [ComRegisterFunction]
    public static void RegisterFunction(Type type)
    {
        string s = @"Wow6432Node\\CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable";

        Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("Wow6432Node\\CLSID\\{" +
                                                                                            type.GUID.ToString().ToUpper() + "}\\InprocServer32");

        if (key != null)
        {
            key.SetValue("", System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) +
                             @"\mscoree.dll");
        }

        Registry.ClassesRoot.CreateSubKey(s);
    }

    ///// <summary>
    ///// Specifies the method to call when you unregister an assembly for use from COM; 
    ///// this allows for the execution of user-written code during the unregistration process.
    ///// </summary>
    ///// <param name="type"></param>
    [ComUnregisterFunction]
    public static void UnregisterFunction(Type type)
    {
        string s = @"Wow6432Node\\CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable";

        Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("Wow6432Node\\CLSID\\{" +
                                                                                            type.GUID.ToString().ToUpper() + "}\\InprocServer32");

        if (key != null)
        {
            key.SetValue("", System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) +
                             @"\mscoree.dll");
        }

        Registry.ClassesRoot.DeleteSubKey(s, false);
    }

    #endregion Initialization (Register/Unregister functions)

    public string GetTest()
    {
        return "x64 Simple Test";
    }
}

I need to mention that "Register for COM Interop" is checked in my project preperties (which is evident, since it is working for 32bit).

Does anyone have any clue why the x64 is not being registred ? or why the AnyCPU is being registred only for 32 bit Excel ??

0

There are 0 best solutions below