RegistrationHelper.InstallAssembly and 64-bit

854 Views Asked by At

I got a winsvr2008r2 x64 which I've made the following observation on:

If I create a COM+ application manually and manually install all components through the Component Services GUI everything runs as 64-bit.

But if I install everything using code (System.EnterpriseServices.RegistrationHelper.InstallAssembly), the COM+ components run as 32bit.

Is it possible to get everything running as 64-bit when using InstallAssembly?

2

There are 2 best solutions below

1
On BEST ANSWER

When you call InstallAssembly, internally, a method ValidateBitness is called, which checks whether the assembly was already installed with the wrong bitness, in which case it reports an error and fails with RegistrationException. It determines what the "right" bitness is depending on the result of a call to IsWow64Process.

Looking further, it appears that there's one way of registering for 64 bit and 32. This seems to be correct, as the registration depends on the bitness of the running application (the one that calls InstallAssembly). Can you confirm that this is indeed running as 64 bit?

It is possible that you've run into a reported bug that is marked "will not be fixed anytime soon". I cannot judge whether this bug is fully applicable to your scenario, because I'm not certain whether the setup calls the same API functions internally. See this post on Microsoft Connect on register keys being stored in the wrong hive.

0
On

I don't know if it's a bug or not, but this is probably related to the "Bitness" COM+ component property: Components Collection

As stated in the doc, "Bitness" can be set to 1 (32-bit) or 2 (64-bit). You can read the Bitness value for a given component using this kind of C# code:

    COMAdminCatalog catalog = new COMAdminCatalogClass();

    ICatalogCollection appCollection = (ICatalogCollection)catalog.GetCollection("Applications");
    appCollection.Populate();

    // browse all apps
    foreach (COMAdminCatalogObject app in appCollection)
    {
        Console.WriteLine("application=" + app.Name);
        // browse all components
        ICatalogCollection compCollection = (ICatalogCollection)appCollection.GetCollection("Components", app.Key);
        compCollection.Populate();
        foreach (COMAdminCatalogObject comp in compCollection)
        {
            Console.WriteLine(" component=" + comp.Name);
            Console.WriteLine(" bitness=" + comp.get_Value("Bitness"));
        }

    }

Unfortunately, Bitness is a ReadOnly property. From what I understand, the underlying COM registration process uses the bitness of the process actually doing the registration to determine how to set this property.

This is implicitely explained in this article: Serviced Components in 32-bit and 64-bit Architectures

As you see in the table, 64 or 32 bit registration depends on the version of the tool you use. That's why a tool such as Regsvcs.exe comes in two flavors: 32 and 64 bits and how your component is registered simply depends on this. Also, pay attention to the fact things may be different if the COM+ application is empty or not.

I guess it means your running .EXE should be compiled in 64-bit.