kmauzoul
Posts: 11
Joined: Thu Jul 23, 2020 3:50 pm

Custom Action with 3rd party dll not loading

Hello,

I have been struggling to figure out why a 3rd party dll will not load during a Custom Action. I have a custom action that references a 3rd party DLL to create a "temporary" license when the install finishes and user clicks Finish. What I've tried:

Putting all custom action Dlls in the "Temporary Files", and telling the custom action to run from here

Putting all custom action Dlls in the application install directory, and telling the custom action to run from here (with the thought that I could run a clean up routine to delete the necessary files when it's done)

They all give the "File not found" error in the logs. However, if I run the custom action outside of the installer with all the DLLs in place, it creates it successfully.

Any help would be greatly appreciated (I am running version 16.5)

Thanks,
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: Custom Action with 3rd party dll not loading

Hello and welcome to our forums,

If the .DLL file is added as a "Temporary File", please note that, by default, temporary files are deleted at the end of the installation.

Most likely, when you are trying to execute the custom action from the "Finish" button, the .DLL file is no longer there. To avoid this, please go to "Files and Folders" page --> right click on your temporary file --> "Properties" --> check the "Do not delete the file when setup ends" option.
Putting all custom action Dlls in the application install directory, and telling the custom action to run from here (with the thought that I could run a clean up routine to delete the necessary files when it's done)
This, however, should be working as expected (if you are executing the custom action from the "Finish" button).

Could you please take a screenshot of the custom action's configuration so I can have a better look at this?

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
kmauzoul
Posts: 11
Joined: Thu Jul 23, 2020 3:50 pm

Re: Custom Action with 3rd party dll not loading

Catalin wrote: Wed Jul 29, 2020 5:38 pm Hello and welcome to our forums,

If the .DLL file is added as a "Temporary File", please note that, by default, temporary files are deleted at the end of the installation.

Most likely, when you are trying to execute the custom action from the "Finish" button, the .DLL file is no longer there. To avoid this, please go to "Files and Folders" page --> right click on your temporary file --> "Properties" --> check the "Do not delete the file when setup ends" option.
Putting all custom action Dlls in the application install directory, and telling the custom action to run from here (with the thought that I could run a clean up routine to delete the necessary files when it's done)
This, however, should be working as expected (if you are executing the custom action from the "Finish" button).

Could you please take a screenshot of the custom action's configuration so I can have a better look at this?

Best regards,
Catalin
Sorry for the delay (I didn't check off Notify when a reply is posted).

Here is the Custom Action screen:
FolderStructure.png
FolderStructure.png (179.11 KiB) Viewed 5606 times
Here are the files needed (it's highlighted)
FolderStructure2.png
FolderStructure2.png (248.63 KiB) Viewed 5606 times
When I run this on finish, I get the error:

SFXCA: Extracting custom action to temporary directory: D:\Smartviews\SmartViews360.InstallerCA.CA.dll-3\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action SmartViews360.InstallerCA!SmartViews360.InstallerCA.CustomActions.LoadTrialLicense
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'LogicNP.CryptoLicensing, Version=8.0.0.0, Culture=neutral, PublicKeyToken=4a3c0a4c668b48b4' or one of its dependencies. The system cannot find the file specified.
at SmartViews360.InstallerCA.CustomActions.LoadTrialLicense(Session session)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32 sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)


It's as if it's deploying the InstallerCA.CA.dll file to a temporary directory instead of just running it right out of
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: Custom Action with 3rd party dll not loading

Hello,

Thank you for the provided screenshots.

The custom action seems configured correctly.

However, judging by the error message, I'd say that your DLL file tries to access another DLL file and it is not able to find it:
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'LogicNP.CryptoLicensing
Most likely, I would say that the .DLL file you are calling is expecting the other .DLL file ("LogicNP.CryptoLicensing") in a specific location and it can not find it there.

Are you the developer of that .DLL file? If so, could you please double check it and see if is expecting the other .DLL in a predefined location?

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
kmauzoul
Posts: 11
Joined: Thu Jul 23, 2020 3:50 pm

Re: Custom Action with 3rd party dll not loading

I am not the developer of that dll

Though I don't think it has to be in a specific location. I would assume it would have to be found in the same location of wherever it's being invoked from as this DLL does not throw error(s) from my application itself (which also uses this dll to verify their license status).

If a custom action is being extracted to a temporary location (as shown in the logs) - it's likely Advanced Installer is only copying the custom action to that location and not any of it's references. Is there a way to force the custom action to run from where I specified it ?

SFXCA: Extracting custom action to temporary directory: D:\Smartviews\SmartViews360.InstallerCA.CA.dll-3\

Or is there a way to preemptively know where the custom action will be extracted to so I can copy any necessary DLL's to that folder?

Even when these files are stored in a Temporary Folder, it still seems to extract itself to a sub folder within that temp folder without moving anything else
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: Custom Action with 3rd party dll not loading

Hello,
I am not the developer of that dll
I see.

I am not quite sure this has to do with the extract location of your .DLL file.

In order for me to further investigate this, could you please forward me the following resources:

- a copy of your .AIP file

- a download link of the setup

- a test case which I can follow in order to reproduce the issue (for instance, what is the expected behavior when launching the DLL file?)

by e-mail at support at advancedinstaller dot com?

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
kmauzoul
Posts: 11
Joined: Thu Jul 23, 2020 3:50 pm

Re: Custom Action with 3rd party dll not loading

Just emailed (sorry for the delay)
kmauzoul
Posts: 11
Joined: Thu Jul 23, 2020 3:50 pm

Re: Custom Action with 3rd party dll not loading

Catalin wrote: Tue Aug 11, 2020 4:16 pm Hello,
I am not the developer of that dll
I see.

I am not quite sure this has to do with the extract location of your .DLL file.

In order for me to further investigate this, could you please forward me the following resources:

- a copy of your .AIP file

- a download link of the setup

- a test case which I can follow in order to reproduce the issue (for instance, what is the expected behavior when launching the DLL file?)

by e-mail at support at advancedinstaller dot com?

Best regards,
Catalin
Wasn't sure if you were able to view the e-mail - if all else fails, I'll remove this custom action and just create a simple dummy application to do it
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: Custom Action with 3rd party dll not loading

Hello Karl,

Please accept my apologies for such a delayed reply (I was off for a week).

Yes, I did receive the e-mail and I am downloading the resources as we speak.

I will start investigating this right away and will let you know about my findings.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: Custom Action with 3rd party dll not loading

Hello Karl,

Thank you for your patience on this.

After a lot of testing and investigations, I was finally able to find the root cause of this problem and a solution to it.

Long story short, the problem here is the fact that the custom action DLL is expecting the other DLL (CryptoLicensing) next to it.

At install time, when the custom action is executed, we extract it to a temporary location and execute it from there. When trying to access the function from the CryptoLicensing.dll, the custom action fails because the DLL is not placed next to it.

After having a look over the source code of your custom action's DLL file, it looked like the CryptoLicensing.dll should be contained by the main DLL, since it is added as a reference. However, this does not seem to happen (not sure why - I'd say that this is happening because you are using an older version of WiX).

The solution I've found here is to install the assembly in the Global Assembly Cache (GAC) so it is available machine-wide.

To do so, please go to "Assemblies" page --> "Add Assembly" --> select the "LogicNP.CryptoLicensing.dll":

GAC.png
GAC.png (56.75 KiB) Viewed 5322 times

After doing so, everything should be working as expected:
MSI (c) (D4:0C) [09:11:22:951]: Doing action: LoadTrialLicense
Action start 9:11:22: LoadTrialLicense.
MSI (c) (D4:64) [09:11:23:061]: Invoking remote custom action. DLL: C:\Smartviews\SmartViews360.InstallerCA.CA.dll, Entrypoint: LoadTrialLicense
SFXCA: Extracting custom action to temporary directory: C:\Smartviews\SmartViews360.InstallerCA.CA.dll-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action SmartViews360.InstallerCA!SmartViews360.InstallerCA.CustomActions.LoadTrialLicense
Action ended 9:11:24: LoadTrialLicense. Return value 1.
trial.png
trial.png (22.82 KiB) Viewed 5322 times


In addition to that, the VBS custom action may also fail.

Code: Select all

DeleteAFile(Session.Property("APPDIR") & "\Microsoft.Deployment.WindowsInstaller.dll")
DeleteAFile(Session.Property("APPDIR") & "\SmartViews360.InstallerCA.CA.dll")
DeleteAFile(Session.Property("APPDIR") & "\SmartViews360.InstallerCA.dll"
Sub DeleteAFile(filespec)
   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")
   fso.DeleteFile(filespec)
End Sub
First of all, a ")" is missing here:

Code: Select all

DeleteAFile(Session.Property("APPDIR") & "\SmartViews360.InstallerCA.dll"
Secondly, please note that the APPDIR property already ends with the "\" character, therefore you may not need to add one more:

Code: Select all

"\Microsoft.Deployment.WindowsInstaller.dll"
"\SmartViews360.InstallerCA.CA.dll"
"\SmartViews360.InstallerCA.dll"
Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
kmauzoul
Posts: 11
Joined: Thu Jul 23, 2020 3:50 pm

Re: Custom Action with 3rd party dll not loading

Catalin wrote: Wed Sep 02, 2020 5:23 pm Hello Karl,

Thank you for your patience on this.

After a lot of testing and investigations, I was finally able to find the root cause of this problem and a solution to it.

Long story short, the problem here is the fact that the custom action DLL is expecting the other DLL (CryptoLicensing) next to it.

At install time, when the custom action is executed, we extract it to a temporary location and execute it from there. When trying to access the function from the CryptoLicensing.dll, the custom action fails because the DLL is not placed next to it.

After having a look over the source code of your custom action's DLL file, it looked like the CryptoLicensing.dll should be contained by the main DLL, since it is added as a reference. However, this does not seem to happen (not sure why - I'd say that this is happening because you are using an older version of WiX).

The solution I've found here is to install the assembly in the Global Assembly Cache (GAC) so it is available machine-wide.

To do so, please go to "Assemblies" page --> "Add Assembly" --> select the "LogicNP.CryptoLicensing.dll":


GAC.png


After doing so, everything should be working as expected:
MSI (c) (D4:0C) [09:11:22:951]: Doing action: LoadTrialLicense
Action start 9:11:22: LoadTrialLicense.
MSI (c) (D4:64) [09:11:23:061]: Invoking remote custom action. DLL: C:\Smartviews\SmartViews360.InstallerCA.CA.dll, Entrypoint: LoadTrialLicense
SFXCA: Extracting custom action to temporary directory: C:\Smartviews\SmartViews360.InstallerCA.CA.dll-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action SmartViews360.InstallerCA!SmartViews360.InstallerCA.CustomActions.LoadTrialLicense
Action ended 9:11:24: LoadTrialLicense. Return value 1.

trial.png



In addition to that, the VBS custom action may also fail.

Code: Select all

DeleteAFile(Session.Property("APPDIR") & "\Microsoft.Deployment.WindowsInstaller.dll")
DeleteAFile(Session.Property("APPDIR") & "\SmartViews360.InstallerCA.CA.dll")
DeleteAFile(Session.Property("APPDIR") & "\SmartViews360.InstallerCA.dll"
Sub DeleteAFile(filespec)
   Dim fso
   Set fso = CreateObject("Scripting.FileSystemObject")
   fso.DeleteFile(filespec)
End Sub
First of all, a ")" is missing here:

Code: Select all

DeleteAFile(Session.Property("APPDIR") & "\SmartViews360.InstallerCA.dll"
Secondly, please note that the APPDIR property already ends with the "\" character, therefore you may not need to add one more:

Code: Select all

"\Microsoft.Deployment.WindowsInstaller.dll"
"\SmartViews360.InstallerCA.CA.dll"
"\SmartViews360.InstallerCA.dll"
Hope this helps.

Best regards,
Catalin
Hi Catalin,

Thank you for this. I tried updating WiX to the latest version but that didn't work so I followed the GAC instructions and that worked as expected. Thank ou
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: Custom Action with 3rd party dll not loading

You are always welcome, Karl!

I am glad everything is working as expected now.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”