Custom Action in C# used via WiX fails with error 1154
Asked Answered
W

8

21

I am using WiX 3.5.1930 in Visual Studio 2010, targeting the .NET Framework 3.5. (Later weekly builds of WiX seem to be very broken with respect to their custom action template, at least for now. 1930 is the most recent build that seems to make a buildable C# CA with working references.)

I have two custom action assemblies written in C#. One of them works fine. The other fails with the following error:

CustomActionnNameHere returned actual error code 1154 (note this may not be 100% accurate if translation happened inside sandbox)

I have compared the .csproj files and .wixproj files, and as best I can tell the differences are appropriate (e. g. list of included .cs files). I have changed the non-working .wxs to call the working custom action instead of the non-working custom action and it works as epxected.

What else can I look at to get this working?

Edit: Just to be complete 1154 refers to an invalid DLL - net helpmsg translates it (in English) to "One of the library files needed to run this application is damaged."

Second edit: ran peverify against the dll (grabbed a copy out of \windows\installer while the installer was running) and it says everything is fine in the dll. The DLL only has the custom action method with a "return success" so there's not a lot for it to verify, but it does confirm the DLL is not corrupt.

Third edit: The code in the broken custom action follows:

using Microsoft.Deployment.WindowsInstaller;

namespace Framework.Installer.Database {
    public class CustomActions {

        [CustomAction]
        public static ActionResult RunMigration(Session session) {

            return ActionResult.Success;
        }

    }
}

Not much to it. The relevant parts of the .wxs are as follows:

<InstallExecuteSequence>
  <Custom Action="DotNetMigratorCustomActionPreviousUp" After="SetMigrationPropertiesPreviousUp"><![CDATA[(&Database = 3)]]></Custom>
</InstallExecuteSequence>

<Binary Id="DotNetMigratorCustomActionDll"
        SourceFile="$(var.Framework.Installer.Database.CustomActions.TargetDir)\SoftwareAnswers.Framework.Installer.Database.CustomActions.dll" />

<CustomAction Id="DotNetMigratorCustomActionPreviousUp"
              Return="check"
              BinaryKey="DotNetMigratorCustomActionDll"
              DllEntry="RunMigration"
              Execute="deferred" />
Wystand answered 24/8, 2010 at 19:38 Comment(2)
How did you make this custom action? Are you using DTF?Betrothal
If I'm using the Deployment Tools Foundation (DTF - spelled out for future searchers - I didn't know what it was until I just looked it up) I don't know I am. As I suggested I'm using the Custom Action support in votive to get me to the built action. I believe that is using DTF underneath but that's not really directly exposed as best I can tell.Wystand
B
56

It sounds like you are using DTF. If you see:

using Microsoft.Deployment.WindowsInstaller;

then you certainly are. Be sure to read the following for how it all works:

Deployment Tools Foundation (DTF) Managed Custom Actions

Also you'll find a DTF help chm in the start menu under WiX.

Basically it sounds like to me you are wiring the .NET assembly into the installer instead of the unmanged wrapper dll. Read the above article for an overview of how to look at it in Depends and to know what to expect. The WiX | C# Custom Action project should output Foo.dll and Foo.CA.dll. You want the later in your installer.

For people who land on this page in the future (the answer was originally for the poster ) there is a whole list of things to check:

  1. Are you referencing the correct DLL in the Binary table?
  2. Are you referencing the correct exported function name?
  3. Is your class public?
  4. Is your method using the correct signature? I.e. is it:
  5. Marked with the correct CustomAction attribute
  6. Marked as public?
  7. Marked as static?
  8. Return ActionResult?
  9. Take Session as an Argument?
  10. Make sure you are using the WiX C# Custom Action Project type to ensure the postbuild event is called to create the native DLL wrapper. (See #1)

Any one of these can cause an 1154 error. This is the reason I wrote a comprehensive blog article on the subject and linked to it in this answer. It's important to fully understand how managed code is presented to the unmanaged Windows Installer service and to know how to use Depends to validate that the public static method is exported as a stdcall function in the resulting .CA.dll that WiX/DTF produces.

Betrothal answered 25/8, 2010 at 14:21 Comment(5)
OK this told me the answer - when I compared the working with non-working I saw that I was using .CA.DLL for the working and .DLL for the non-working one. I changed the Binary tag and I was good to go.Wystand
Great list. I'll add one thing that foxed me for a while. Make sure that the custom action project is of type 'C# Custom Action project' (visible under the Windows Installer XML project types) rather than a normal 'Class Library'. Might seem obvious but I missed it!Frond
Agreed. I just did a screen sharing session the other day with a developer who was just stuck trying to figure it out and that was his problem. He had created a class library and wrote the code but didn't realize he was missing the targets reference that pulls in the postbuild call to makesfxca.Betrothal
Upvoted way back in the past and came back to this list again. I wish there are way to re-upvote.Sesquicarbonate
@ShinT glad to help. Stack Overflow is our pensieve for things we once knew but have forgotten to learn new things.Betrothal
I
6

If you create your custom action in Visual Studio (Votive) be sure that you created a Wix Custon Action project and not a class library, otherwise you have to use MakeSfxCA tool to pack your custom action.

Imamate answered 30/9, 2010 at 18:25 Comment(0)
G
6

I just found the same issue (using the correct .CA.dll file) and in my case it was because I wasn't using a static method. I had this:

public ActionResult MyMethod(Session session)

Instead of this:

public static ActionResult MyMethod(Session session)

After changing the method it worked just fine.

Hope it helps someone.

Goldy answered 9/4, 2011 at 23:35 Comment(2)
I'm glad you found it useful!Goldy
That was #7 on my 2010 answer. :)Betrothal
F
4

I hit upon another very simple (and stupid) cause for error 1154: misspelling the DLL entry name in the CustomAction element...

Comparing various causes other people have found it seems to me that error 1154 means in most cases, "DLL entry not found".

Fante answered 31/1, 2012 at 12:21 Comment(0)
A
3

My answer is not directly related to this question. But in my case, I got stuck in the same error code 1154, because I created one more function in the same class but not marked that function as [CustomAction]

My code was looking like

namespace VerifyUserInfo {
    public class CustomActions {

        [CustomAction]
        public static ActionResult TryToLogin(Session session) {

            return ActionResult.Success;
        }

        public static ActionResult RegisterDevice(Session session) {

            return ActionResult.Success;
        }

    }
}

But then I fixed with the [CustomAction] added just above the new function and issue resolved

namespace VerifyUserInfo {
    public class CustomActions {

        [CustomAction]
        public static ActionResult TryToLogin(Session session) {

            return ActionResult.Success;
        }

        [CustomAction]
        public static ActionResult RegisterDevice(Session session) {

            return ActionResult.Success;
        }

    }
}
Assortment answered 13/11, 2019 at 7:4 Comment(0)
A
2

Another reason I saw this error was because I forgot to add the [CustomAction] attribute to the name of my c# function.

Appal answered 25/1, 2013 at 20:42 Comment(0)
T
1

In my case it was the function name length. It was 27 characters, and we were getting the error. We changed the function name to 24 characters, and it worked.

Tripalmitin answered 2/10, 2013 at 19:5 Comment(1)
I assume this is fixed in a later version of wix. I'm using wix 3.11 to call a 36 char method name.Outing
J
0

Try putting your custom action call in

<InstallExecuteSequence/>

in hopes of getting a better error message. I have received different error messages depending on how the action was called. Also, try using fuslogvw.exe. It might give you a pretty nice error message too.

Jerky answered 25/8, 2010 at 13:24 Comment(3)
Thanks for the answer. I saw some other posts here on StackOverflow about WiX issues and went down that road yesterday. (I should have said so in the question.) The call is actually in <InstallExecuteSequence/> already, and fuslogvw doesn't show any binds at all (which I admit to being confused about a little).Wystand
Are you referencing any additional dlls in your broken custom action? What is your method doing?Jerky
In the broken one right now, for the sake of troubleshooting, there is only one reference (Microsoft.Deployment.WindowsInstaller) that is in the working one, and only one method. I'll edit the question to show the code.Wystand

© 2022 - 2024 — McMap. All rights reserved.