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

风流意气都作罢 提交于 2019-11-28 09:04:51

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.

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.

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.

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".

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!