C# custom action in Wix
Asked Answered
S

2

11

When my application is uninstalled, the server needs to be notified so that it can free up the license key assigned to the client. This is done via a web service call.

I created a C# custom action that does this. The problem is, the uninstaller is quitting saying that it couldnt find a dll.

The error log for the msi contains the following error:

Error 1723. There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor. Action ReadLicenseKeyFromFile, entry: ReadLicenseKey, library: C:\Windows\Installer\MSI4F42.tmp

I have the function ReadLicenseKey marked as a custom action. The custom action is named ReadLicenseKeyFromFile.

<Custom Action="ReadLicenseKeyFromFile" After="InstallInitialize">
    REMOVE~="ALL" AND NOT UPGRADINGPRODUCTCODE
</Custom>

<CustomAction Id="ReadLicenseKeyFromFile" BinaryKey="UnInstallCA.CA.dll" DllEntry="ReadLicenseKey" Execute="immediate" Return="check" />

<Binary Id="UnInstallCA.CA.dll" SourceFile="$(var.UnInstallCA.TargetDir)UnInstallCA.CA.dll" />

The custom action project is outputting the .CA.dll file. I have tried installing the file as a part of the setup, manually copy pasted the file, done nothing to the file... basically tried all possible combinations.

There must be something that I am missing, so please help.

Subdual answered 31/7, 2009 at 17:53 Comment(0)
S
11

Am sorry to have wasted everyone's time over this.

The solution was something rather too simple. I had forgotten to place the [CustomAction] attribute on this particular method. So even though it was the last action which I had written in my CustomAction.cs file, it was the first one to be called in the InstallExecuteSequence. And because of that, I got misled in to thinking that it couldnt find the file. Well, that as well as the fact that I must have been really sleepy...

Anyway, while searching for the answer I did manage to come across lots of nice resources, especially Alex Shevchuks series on Wix. Another thing I realised was that I dont have to install the custom action dll file. I just have reference it from my Wix project and provide the path to it. The dll gets embedded in the setup and is streamed from there when the uninstall custom actions is to be called.

Subdual answered 2/8, 2009 at 23:16 Comment(2)
When I have caused myself the same issue I have used depends to look at the DLL and check the right symbols are really exported. /LGrefe
Thank you for posting your answer, I just made the same (simple) mistake without realising it, such a cryptic error message!Galvanism
S
0

Is your UnInstallCA.CA.dll copied to the target machine during install? It seems that it's not there at uninstall.

If it got there - can it run? ( try running it from the target machine to see if it can do what it's supposed to do - maybe you need to ship some other dll you're using from this one - or maybe some redistributable package )

Spracklen answered 31/7, 2009 at 18:19 Comment(3)
yes, the install dll is copied on install. no, i dont know how to simulate the using of the dll. if you mean by creating a new project that references the dll and then invoking the function, yeah that happens.Subdual
@Anton Tykhyy - i was notified that you have posted an answer to my question an hour ago, but i cannot see that answer. From my profile, i could only see a part of the answer. the custom action project is running the required utility from the DTF which converts the managed dll to unmanaged .CA.dll . and this .CA.dll is what i am installing along with my setup. is there anyway by which i can check what path is the setup looking at to find the dll?Subdual
one problem could be the variable path. I've never used it like that :) - hardcode the real path to see if things work.Spracklen

© 2022 - 2024 — McMap. All rights reserved.