【发布时间】:2011-06-08 07:45:30
【问题描述】:
我正在开发我的第一个自定义操作,但我无法加载生成的 .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 文化,对象值,类型 destinationType)
在 System.ComponentModel.TypeConverter.ConvertToString(对象值)"
进一步编辑:我可以通过 Assembly.LoadFrom 加载普通的 CustomAction.dll,所以这可能是 BadImageFormat 的不同问题?没有其他依赖项的空白操作是否有任何原因不会加载到我的 WiX 项目中?
【问题讨论】:
-
您的 CustomAction.CA.dll 是否包含嵌入式清单?查看 Windows 应用程序日志,将有一个条目详细说明无法加载 DLL 的原因。
-
在上面添加了我的堆栈跟踪,对我来说并没有多大意义。我只是使用默认值,所以看不到我在哪里使用字符串而不是配置文件中的数字或类似的东西
标签: deployment installation wix custom-action