vbjeff
Posts: 23
Joined: Tue May 14, 2013 3:08 pm

C# custom action not working

I am trying to create fully fledged C# custom action, but can not get it to work. I am using AI 10.5.1 and WiX 3.6. I tried to test a simple example and can not get the directions to work. I found that if I select the custom action "Call function from attached native DLL", then my test case works, but if I try "Call function from installed DLL" and include my CustomAction1.CA.dll, it fails with an error "A DLL required for this install could not be run..." I tried including the Microsoft.Deployment.WindowsInstaller.dll file and it did not help. What other files do I need to include to get it to work?

The real custom action that I am trying to use is dependent on another DLL, and using the "Call function from attached native DLL" does not work. I am hoping if I can get "Call function from installed DLL" to work, then all I will need to add is my dependent DLL.
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: C# custom action not working

Hello,
if I try "Call function from installed DLL" and include my CustomAction1.CA.dll, it fails with an error "A DLL required for this install could not be run...
Please keep in mind that for the Call function from installed native DLL predefined custom action to work, the target DLL must be installed by your package and must exist on disk when this custom action is executed. So, please make sure that this requirement is fulfilled.

Also can you please select the "When the system is being modified (deferred)" and "Run under the LocalSystem account with full privileges (no impersonation)" options for your custom action and see if the behavior persists?

Please let us know if that helped.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
vbjeff
Posts: 23
Joined: Tue May 14, 2013 3:08 pm

Re: C# custom action not working

Thanks Dan, that did fix the problem for my test case.

It could be helpful if AI notified me during the build process that using "Call function from installed DLL" with the following settings:
Execution Time: Immediately
Execution Stage Condition: Install
Install Execution Stage: between Add Resources and Finish Execution
That the custom action may not work because the target DLL was not installed yet.
I mention these settings because they are the default setting that were selected when I chose "Call function from installed DLL" .

The next problem I ran into was following the directions for "How do I create fully fledged C# custom actions?" that my custom action DLL was referencing a COM object and the CustomAction1.CA.dll did not contain the DLL generated by Visual Studio for the COM object Interop.COMStuff.dll. I needed to copy the Interop.COMStuff.dll to a new folder and reference the binary dll instead of the COM reference to get the CustomAction1.CA.dll to include the Interop.COMStuff.dll. This is not an AI issue, rather a Visual Studio and/or WiX issue, but may still happen to other users.

I did finally get my C# custom action to work by either using "Call function from installed DLL" or ".NET Installer Class action" is one method the preferred way?

When using ".NET Installer Class action" I noticed that 2 custom actions were created for 64-bit and not 64-bit.
Do I need to keep both, or can I keep just one and remove the VersionNT64 Condition?

A minor note, I noticed when using "Call function from installed DLL" with CustomAction1.CA.dll, that a folder is created CustomAction1.CA.dll- that contains the contents of the CustomAction1.CA.dll file, and the contents of the CustomAction1.CA.dll- folder are deleted, but the folder CustomAction1.CA.dll- is never removed. After installing several updates I see several empty folders CustomAction1.CA.dll-1, CustomAction1.CA.dll-2 remaining. Should these folders get deleted during the install process after their contents are removed?
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: C# custom action not working

Hello,
It could be helpful if AI notified me during the build process that using "Call function from installed DLL" with the following settings:
Execution Time: Immediately
Execution Stage Condition: Install
Install Execution Stage: between Add Resources and Finish Execution
That the custom action may not work because the target DLL was not installed yet.
I mention these settings because they are the default setting that were selected when I chose "Call function from installed DLL" .
We already have this on our TODO list and this feature will be available in a future version of Advanced Installer.
Thank you for your suggestion.
The next problem I ran into was following the directions for "How do I create fully fledged C# custom actions?" that my custom action DLL was referencing a COM object and the CustomAction1.CA.dll did not contain the DLL generated by Visual Studio for the COM object Interop.COMStuff.dll. I needed to copy the Interop.COMStuff.dll to a new folder and reference the binary dll instead of the COM reference to get the CustomAction1.CA.dll to include the Interop.COMStuff.dll. This is not an AI issue, rather a Visual Studio and/or WiX issue, but may still happen to other users.
Thank you for sharing this with us. This certainly will help future users in the same situation.
I did finally get my C# custom action to work by either using "Call function from installed DLL" or ".NET Installer Class action" is one method the preferred way?
There is no method preferred instead of the other one. It depends about your specific scenario, which one suit you most.
When using ".NET Installer Class action" I noticed that 2 custom actions were created for 64-bit and not 64-bit.
Do I need to keep both, or can I keep just one and remove the VersionNT64 Condition?
This is happening when an assembly is set to “Any CPU”. You can delete one of them but you need to reconfigure the remaining custom action(e.g. execution condition and custom action parameters) so it can run on all platforms.
A minor note, I noticed when using "Call function from installed DLL" with CustomAction1.CA.dll, that a folder is created CustomAction1.CA.dll- that contains the contents of the CustomAction1.CA.dll file, and the contents of the CustomAction1.CA.dll- folder are deleted, but the folder CustomAction1.CA.dll- is never removed. After installing several updates I see several empty folders CustomAction1.CA.dll-1, CustomAction1.CA.dll-2 remaining. Should these folders get deleted during the install process after their contents are removed?
I'm not sure why you encountered this behavior. Can you please send us the .AIP (project file) and a verbose log of the installation to support at advancedinstaller dot com so we can investigate it? If it contains confidential information you can send us a small test project which reproduce this behavior.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”