We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

WesCutting
Posts: 14
Joined: Wed Jul 23, 2014 5:07 pm

Run Custom Action with Resorces

I've read several other forum posts about running a C#(WIX) Custom Action from Advanced Installer and have found them helpful but only to a point. Currently I'm consuming the ***.CA.dll that is built from the Custom Action project I have in Visual Studio as an Attached Native DLL. The method stub in the DLL's source is public static ActionResult Execute(Session session) so the function I've chosen is Execute; finally I am running it immediately. This configuration has been the baseline for running a WIX Custom Action from the digging I've done.

The source for the Attached DLL consumes several other class libraries (other projects in the Visual Studio solution) as well as resource files (.sql files to be specific, also included in the project). This custom action dynamically runs SQL scripts on our DB based on conditions established in a prebuilt plugin/other class libraries. Meaning not all SQL scripts get run on every installation, only those needed for the environment it is installed into.

Below is the stack trace in the verbose logs from Advanced Installer

CustomEvolverException message:Function could not be executed.
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.Deployment.WindowsInstaller.InstallerException: Function could not be executed.
at *****.CustomAction.DatabaseEvolveAction.Execute(Session session)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean skipVisibilityChecks)
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)
CustomAction *****.CustomAction.CA.dll returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 15:34:52: *****..CustomAction.CA.dll. Return value 3.

My Question: How do I run a custom action in Advanced Installer to execute SQL scripts using a prebuilt plugin?

Please let me know if there are any points I need to clarify.
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Run Custom Action with Resorces

Hello,

If your custom action require other files to be present on the target machine, then you can add your files as a temporary files. You can take a look on the Temporary Files Operations in the Files and Folders Page article which may be useful to you.
Please note that the Temporary Files are copied during the CostFinalize standard action, at the beginning of the setup and removed during the InstallFinalize standard action.

By the way, did you noticed our SQL Databases support? It allows you to configure SQL scripts, queries or SSRS reports that will be executed during installation.

Please let us know if that helped, otherwise give us more details about your specific scenario, maybe exemplify.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
WesCutting
Posts: 14
Joined: Wed Jul 23, 2014 5:07 pm

Re: Run Custom Action with Resorces

Custom Action Info
The solution consists of several projects, including WIX projects for the legacy installer, though the custom actions I'm looking to carry over into Advanced Installer are only two Visual Studio projects. One is a class library of sorts that holds the SQL scripts and the logic to execute them, the only input the library needs is a session logging object and the SQL connection string set in the installer dialogues. The second projects acts as the middle man, this project is kicked off from WIX custom actions and is passed the installer session. The session is used to pick out the connection string and create a logger which is passed to the first library to create a class to handle the SQL execution logic and log progress.

Advanced Installer Info
As I stated in the original post I attempted to call a function from a attached native dll, the dll I choose to attach was the output dll from the second project with the file name ending in CA.dll. It shows that Execute (the function name I wish to call) is a valid option in the Function drop down dialogue. From my understanding the Action Data is supposed to be left blank and the Execution Time set to the Immediately option in order for that function to be passed the Session object. Is this understanding false?

Does help define the scope a bit better?
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Run Custom Action with Resorces

Hi,
From my understanding the Action Data is supposed to be left blank and the Execution Time set to the Immediately option in order for that function to be passed the Session object.
This is correct. Now, when your immediate custom action will run, the DLL will be actually extracted to Temp folder, with a randomly generated name (this is done by Windows Installer).

So, for your DLL to find the resources it needs (i.e. the SQL scripts and rest of the output from the first VS project), you need to make sure those are present in the Temp folder when the installer is running. To do that you need to add the files as "Temporary Files" in the project, in Files and Folders page, as my colleague said in the first post. This will make the installer extract the files in the same folder as the DLL of your immediate custom action, so when you try to load them (using a relative path) the DLL will be able to find the required files.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
WesCutting
Posts: 14
Joined: Wed Jul 23, 2014 5:07 pm

Re: Run Custom Action with Resorces

I appreciate the input. That final clarification hammered it home :)
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Run Custom Action with Resorces

Glad we could help.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”