【问题标题】:FileNotFoundException when using Microsoft.VisualStudio.Coverage.Monitor.dll使用 Microsoft.VisualStudio.Coverage.Monitor.dll 时出现 FileNotFoundException
【发布时间】:2010-09-12 16:12:11
【问题描述】:

引用c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\DataCollectors\x86\Microsoft.VisualStudio.Coverage.Monitor.dll的C#控制台应用:

using Microsoft.VisualStudio.CodeCoverage;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Monitor m = new Monitor();
        }
    }
}

对象创建行抛出FileNotFoundException 和消息Could not load file or assembly 'Microsoft.VisualStudio.Coverage.Monitor.dll' or one of its dependencies. The specified module could not be found.

知道为什么会发生这种情况以及如何解决吗?

【问题讨论】:

    标签: c# visual-studio-2010 code-coverage


    【解决方案1】:

    或其依赖项之一

    这是错误消息的相关部分。它依赖于同一目录中的 vspmsg.dll,您必须手动将其复制到您的 bin\Debug 文件夹中。使用 Visual Studio 独有的私有程序集是相当勇敢的。

    【讨论】:

    • @Aliostad,可能是因为库不是静态链接的,而是在运行时动态加载LoadLibrary
    • 它是一个用 C++/CLI 语言编写的程序集。它包含非托管代码。它需要 x86 目标的原因。您可以通过 Dumpbin.exe /imports 查看它具有的非托管依赖项。一个用于 vspmsg.dll,名为 GetErrorMessageModule。不允许您分发它,但如果您仍然这样做,那么您还需要部署 C++ 运行时 DLL。
    【解决方案2】:

    此 DLL 中有 4 个引用(以下是您在 ILDASM.exe 中找到的内容):

    .module extern **KERNEL32.dll**
    .module extern **MSVCR100.dll**
    .assembly extern **mscorlib**
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
      .hash = (AF 35 A4 2A B0 0E 9D FC 8A 27 B8 29 E5 56 7D 12   // .5.*.....'.).V}.
               18 84 3C 6B )                                     // ..<k
      .ver 4:0:0:0
    }
    .assembly extern **Microsoft.VisualC**
    {
      .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
      .hash = (1B D7 52 11 F8 FD 90 65 01 8A 53 AA 7F 87 91 6D   // ..R....e..S....m
               F8 E3 72 91 )                                     // ..r.
      .ver 10:0:0:0
    }
    

    前两个用作 C DLL,另外两个用作 .NET 引用。 看看确保你有 Microsoft.Visual(在 GAC 中)和 MSVCR100.dll(在你机器上的某个地方,也是一个路径)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      相关资源
      最近更新 更多