So we predominantly use C# for development at TC Technology for many reasons which I will leave for a different post. During 64-bit testing though we found that it can be interesting when dealing with:
- 64-bit Windows
- ArcGIS 9.2
- .NET 2.0
at the same time. When trying to initialize AO using the following code
IAoInitialize init = new AoInitializeClass();
it fails with an error like this:
System.Runtime.InteropServices.COMException
Retrieving the COM class factory for component with CLSID {2237A429-E4AC-40D6-96A5-5B6CCF40D56B} failed due to the following error: 80040154.
We did some digging and, thankfully, someone has already figured it out. It turns out that if you build any .NET code with the ‘Any CPU’ option which is the default then ArcObjects based applications fail. This makes sense as the c++ dlls that are built for AO are 32-bit so the application/assemblies that are consuming them also need to be 32-bit.
Fixing the problem is pretty easy (although if you have a bunch of assemblies like we do tedious!).
First thing to do is select ‘Configuration Manager’ from the Solution Platforms drop down (the one with ‘Any CPU right now’):
It actually brings up the same configuration window as the Debug/Release configuration!
From the ‘Active solution platforms’ drop-down select ‘New’:
and from the resultant ‘New Solution Platform’ select x86. This is create a new configuration for x86 only. This way when it is run on a 64-bit environment the OS will know that it should be run as a 32-bit application.