WiX 自定义操作项目 - BadImageFormatException
我正在开发我的第一个自定义操作,但无法加载生成的 .CA.dll 文件。这是最简单的过程和结果:
我创建了一个自定义操作项目并保留所有默认值。该类如下所示:
using Microsoft.Deployment.WindowsInstaller;
namespace CustomAction
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session.Log("Begin CustomAction1");
return ActionResult.Success;
}
}
}
然后我构建程序集(在调试或发布中),这将创建一个 CustomAction.CA.dll 文件。然后我尝试运行此测试:
[TestMethod]
public void LoadAssembly()
{
Assembly.LoadFrom(@"D:\CustomAction\bin\Debug\CustomAction.CA.dll");
}
并收到错误: System.BadImageFormatException:无法加载文件或程序集“file:///D:\CustomAction\bin\Debug\CustomAction.CA.dll”或其依赖项之一。该模块预计包含一个程序集清单。
我也无法引用 WiX 项目中的自定义操作。真的很沮丧!
编辑: 看了一下,当我运行 VS 测试管理器时,我在应用程序事件日志中收到以下内容:
TmiDataManager.TryConvertPropertyValueToDisplayText:无法使用属性描述符的类型转换器转换属性值。 System.FormatException:输入字符串的格式不正确。
在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
在 System.Number.ParseInt32(String s, NumberStyles 样式, NumberFormatInfo 信息)
在 System.String.System.IConvertible.ToInt32(IFormatProvider 提供程序)
在 System.Convert.DefaultToType(IConvertible 值,类型 targetType,IFormatProvider 提供程序)
在 System.String.System.IConvertible.ToType(类型类型,IFormatProvider 提供程序)
在 System.ComponentModel.EnumConverter.ConvertTo(ITypeDescriptorContext 上下文、CultureInfo 区域性、对象值、类型目标类型)
在 System.ComponentModel.TypeConverter.ConvertToString(Object value)"
进一步编辑:我可以通过 Assembly.LoadFrom 加载正常的 CustomAction.dll,所以这可能是与 BadImageFormat 问题不同的问题?是否有任何原因导致空白操作没有更多的依赖项不会加载到我的 WiX 项目中吗?
I'm developing my first custom action but I can't get the resulting .CA.dll file to load. Heres the process at its simplest, and the result:
I create a custom action project and keep all the defaults. The class looks like this:
using Microsoft.Deployment.WindowsInstaller;
namespace CustomAction
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session.Log("Begin CustomAction1");
return ActionResult.Success;
}
}
}
I then build the assembly (either in debug or release) which creates me a CustomAction.CA.dll file. I then try to run this test:
[TestMethod]
public void LoadAssembly()
{
Assembly.LoadFrom(@"D:\CustomAction\bin\Debug\CustomAction.CA.dll");
}
And get the error:
System.BadImageFormatException: Could not load file or assembly 'file:///D:\CustomAction\bin\Debug\CustomAction.CA.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
Neither can I reference the custom action from my WiX project. Getting really frustrated!
Edit:
Had a look and when I run through VS test manager I'm getting the following in the application event log:
TmiDataManager.TryConvertPropertyValueToDisplayText: Failed to convert property value using the property descriptor's type converter. System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider Provider)
at System.String.System.IConvertible.ToType(Type type, IFormatProvider provider)
at System.ComponentModel.EnumConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType)
at System.ComponentModel.TypeConverter.ConvertToString(Object value)"
Further edit: I can load the normal CustomAction.dll via Assembly.LoadFrom, so maybe this is a different issue to the BadImageFormat thing? Could there be any reason a blank action with no further dependencies wouldn't load into my WiX project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CustomAction.CA.dll 是一个本机代码 DLL,包含托管代码程序集,并知道如何在 MSI 内作为自定义操作运行。托管代码程序集是“CustomAction.dll”。
CustomAction.CA.dll is a native-code DLL that contains the managed-code assembly and knows how to run as a custom action inside MSI. The managed-code assembly is "CustomAction.dll."