C# Installshield安装程序在尝试调用托管代码DLL时崩溃

C# Installshield安装程序在尝试调用托管代码DLL时崩溃,c#,installshield,C#,Installshield,我已经创建了一个installshield项目。因为我使用“在托管程序集中调用公共方法”创建了一个自定义操作。DLL中的代码是 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Management; namespace ClassLibrary1 { public class Class1 { public st

我已经创建了一个installshield项目。因为我使用“在托管程序集中调用公共方法”创建了一个自定义操作。DLL中的代码是

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace ClassLibrary1
{
    public class Class1
    {
         public string MyFunc(int flag)
        {


             System.Management.ManagementClass mangnmt = new ManagementClass("Win32_LogicalDisk");
             ManagementObjectCollection mcol = mangnmt.GetInstances();
             string result = "";
             foreach (ManagementObject strt in mcol)
                {
                 if (Convert.ToInt32(strt["MediaType"]) != 12) { continue; }
                 if (Convert.ToInt32(strt["DriveType"]) != 3) { continue; }
                 if (Convert.ToString(strt["Name"]).ToLower() != "c:") { continue; }
                 result += "VolumeSerialNumber   : " + Convert.ToString(strt["VolumeSerialNumber"]) + Environment.NewLine;
                 result = Convert.ToString(strt["VolumeSerialNumber"]);
                 if (!String.IsNullOrEmpty(result)) break;

                }

                return result;


        }
    }
}
每当installshield尝试调用此方法MyFunc时,它都无法找到依赖项System.management.dll,因此会崩溃。我验证了安装程序是否会因为这个问题而崩溃,就好像我对使用system.Management.dll的代码进行了注释,并简单地返回了一个硬编码字符串“一切正常”

在installshield中,我还添加了System.Management.dll作为在ISClrwap表中创建的自定义操作的依赖项。我还在下载的.Net Framework 4.0中添加了installshield先决条件


我搜索了很多表单,但无法找到解决此问题的方法。

也许可以尝试使用Fuslogvw.exe,看看它是否能告诉您为什么System.Management.dll未加载。当此代码不是安装的一部分时,是否在系统上运行?我怀疑WMI并非总是在所有系统上默认启用。例如,搜索-启用wmi server 2008-和其他操作系统版本(如果代码在普通交互式用户应用程序中失败)。