You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows Installer自定义安装器报错Error 1001求助

问题描述

我的Visual Studio 2022解决方案包含三个项目:

  • Miopro.Setup.Prerequisites:类库项目,.NET 7.0,目标平台x86;
  • Miopro.Suite.Wpf:WPF桌面应用项目,.NET 7.0,目标平台x86;
  • Miopro.Setup:Windows Installer安装项目,当前为Debug配置,配置管理器中所有项目平台设为Any CPU,已将Miopro.Setup.Prerequisites的主输出、发布项及Miopro.Suite.Wpf的发布项添加至目标机器的Application Folder,且在Install自定义操作中引用了Miopro.Setup.Prerequisites的主输出。

环境为Windows 11 (x64)。构建安装包并执行安装时,中途出现错误:

Error 1001. Unable to get installer types in the C:\Miopro\MS4\Miopro.Setup.Prerequisites.dll assembly. --> Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

CustomInstaller类代码如下:

using System;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;

namespace Miopro.Setup.Prerequisites
{
    [RunInstaller(true)]
    public class CustomInstaller : Installer
    {
        public CustomInstaller() : base()
        {
            this.Committed += new InstallEventHandler(CustomInstaller_Committed);
            this.Committing += new InstallEventHandler(CustomInstaller_Committing);
        }

        public static void Main()
        {
            WriteToEventLog("Install");
        }

        /// <summary>
        /// Event handler for 'Committing' event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CustomInstaller_Committing(object sender, InstallEventArgs e)
        {
            WriteToEventLog("Committing Event occurred.");
        }

        /// <summary>
        /// Event handler for 'Committed' event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CustomInstaller_Committed(object sender, InstallEventArgs e)
        {
            WriteToEventLog("Committed Event occurred.");
        }

        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="savedState"></param>
        public override void Commit(System.Collections.IDictionary savedState)
        {
            base.Commit(savedState);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="savedState"></param>
        public override void Rollback(System.Collections.IDictionary savedState)
        {
            base.Rollback(savedState);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="savedState"></param>
        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            base.Uninstall(savedState);
        }

        private static void WriteToEventLog(string message)
        {
            string source = "Miopro.Setup.Prerequisites.CustomInstaller";
            string log = "Application";

            if (!EventLog.SourceExists(source))
            {
                EventLog.CreateEventSource(source, log);
            }

            EventLog.WriteEntry(source, message, EventLogEntryType.Information);
        }
    }
}

已确认安装时该DLL已存在于目标目录,求问该错误的可能原因。

可能的原因分析
  • 平台架构不兼容:类库和WPF项目目标平台为x86,但安装项目配置管理器中所有项目设为Any CPU,x64系统下Windows Installer会默认用64位CLR加载x86程序集,导致架构不匹配,无法加载类型。
  • .NET版本适配问题:Windows Installer的自定义操作依赖.NET Framework的System.Configuration.Install体系,而你的项目使用.NET 7(跨平台.NET)。跨平台.NET程序集无法被传统的Windows Installer自定义操作直接加载,因为两者依赖的运行时环境不同。
  • 依赖项缺失:主DLL存在,但它依赖的.NET 7运行时组件或其他依赖库未被正确部署到目标目录,或者自定义操作执行时,CLR无法找到这些依赖项的路径,导致类型加载失败。
  • 执行顺序错误:如果自定义操作在InstallFiles步骤之前执行,此时程序集及其依赖还未完全部署到目标目录,自然无法加载。
  • 权限与初始化异常:创建事件日志源需要管理员权限,虽然安装包通常以管理员身份运行,但如果自定义操作上下文权限不足,初始化时的异常可能被包装为类型加载失败的错误。

内容的提问来源于stack exchange,提问作者Andrew Paes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 07:20:01