njshaw2
Posts: 26
Joined: Fri Apr 19, 2013 10:36 am

Native DLL doesn't work when built with .NET 4 framework

I'm using a native C# installer DLL (built with the WiX toolset v3.7 and Visual Studio 2012) to call some custom functions from my installer. They work fine if I build them with .NET 3.5 framework, but if I use .NET 4.0 or 4.5, they fail immediately the function in question is called.

I'd really like to be able to use at least the .NET 4.0 framework as I need to enumerate the ODBC drivers in the registry to check for a MySQL ODBC driver. Doing this on a 32-bit PC is fine, but on a 64-bit machine, if the user installed the 64-bit driver the native DLL can only check the 64-bit area of the registry, when using .NET 3.5, by calling Win32 API registry functions. .NET 4.0 has RegistryKey.OpenBaseKey where you can specify the 32 or 64 bit hive, so it would be considerably less code (and less debugging) if I could use this.

Are there any known issues with using the WiX toolset with .NET 4.0/4.5 being called from an Advanced Installer installer?
njshaw2
Posts: 26
Joined: Fri Apr 19, 2013 10:36 am

Re: Native DLL doesn't work when built with .NET 4 framework

For other people's info, I managed to do the enumeration check using the very helpful code from http://dotnetgalactics.wordpress.com/20 ... t-process/, for .NET 3.5. Note that I had to query the 64-bit hive first, as querying the 32-bit hive (on a 64-bit machine) appeared to cause it to fail immediately. It worked either way on a 32-bit machine.
Eusebiu
Posts: 4959
Joined: Wed Nov 14, 2012 2:04 pm

Re: Native DLL doesn't work when built with .NET 4 framework

Hi,

I'm glad you got this working. Thank you for sharing with us your solution, I'm sure it will help other users in the future.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
njshaw2
Posts: 26
Joined: Fri Apr 19, 2013 10:36 am

Re: Native DLL doesn't work when built with .NET 4 framework

Hi Eusebiu,

I've got it working only by using some very complicated code, and it doesn't answer my actual question - why does my WiX DLL not work from the installer when compiled with .NET 4.0 or 4.5?

Thanks,
Nick.
Eusebiu
Posts: 4959
Joined: Wed Nov 14, 2012 2:04 pm

Re: Native DLL doesn't work when built with .NET 4 framework

Hi Nick,

I'm not sure why you encounter this behavior. We have tested a DLL custom action built with .NET Framework 4.0 and it worked well to us. Can you create a simple custom action with .NET 4.0 and see if this works?

Also, please make sure that the "Target Framework" is set to ".NET Framework 4 Client Profile" as shown in the attached image, and this .NET version is installed on the machine where you are testing the project.

Best regards,
Eusebiu
Attachments
Target Framework.jpg
Target Framework.jpg (38.42 KiB) Viewed 8348 times
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
njshaw2
Posts: 26
Joined: Fri Apr 19, 2013 10:36 am

Re: Native DLL doesn't work when built with .NET 4 framework

I've found the reason, whilst creating a new simple DLL to test as you suggested. My original project's CustomActions.config file in the VS project had the element <supportedRuntime> set only to <supportedRuntime version="v2.0.50727"/>, which supports only up to .NET 3.5. For .NET 4.0 or 4.5, you also need <supportedRuntime version="v4.0" />. Once I added that line, the DLL ran correctly from the installer.

I'm not sure why my original WiX DLL only had v2.0 set, but I think I may have created it in Visual Studio 2008, not VS2012 which I'm using now, and VS2008 can't target a C# project to anything above .NET 3.5.

So worth knowing for future .NET upgrades - you may need to add extra info to the CustomActions.config file to use the newer frameworks!

So all sorted now it looks like! Thanks as always for the prompt help.
Nick.
Eusebiu
Posts: 4959
Joined: Wed Nov 14, 2012 2:04 pm

Re: Native DLL doesn't work when built with .NET 4 framework

Hi Nick,

I'm glad you got this working. Thank you for the useful information.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”