InstallShield Error -2147219705 with .NET 4.0 and DotNetCoCreateObject() in InstallScript

We have a product that runs on .NET 4.0 and our InstallShield installer for the product uses the DotNetCoCreateObject() method to run some installation actions in an InstallScript custom action. The DotNetCoCreateObject() method works fine in our .NET 2.0 (and 3.0/3.5 by extension) products but we kept getting a run-time exception (-2147219705) when trying the same InstallScript with our .NET 4.0 project.

I messed with this issue for a while and found a great post that helped break open the case. We use InstallShield 2009 (yes, it’s time to upgrade to InstallShield 2012 or 2013…that will happen soon) for our installer builds. The article comments mention that “DotNetCoCreateObject does not work if your dll has been built with .Net Framework 4.0 with Installshield 2010 and below.” Aha! That’s exactly what we were doing. So how do we address the issue other than upgrading to a version of InstallShield after 2010?

We worked around the DotNetCoCreateObject() method issue in .NET 4.0 by adding a .NET 2.0 project to our solution and isolating our installer actions in that project. You also need to ensure that the assembly’s ComVisible attribute is set to true either through the AssemblyInfo.cs properties or in the project property sheet for the advanced assembly options. Then you can build your solution in Visual Studio, add the new .NET 2.0 assembly to your InstallShield project and call the .NET 2.0 assembly with the  DotNetCoCreateObject() method. This should avoid the -2147219705 error and execute your custom action properly.

Comments are closed.

Sign in
Forgot password?
Sign up

(*) Required fields

I agree with OptimaSales Terms & Privacy Policy