views:

40

answers:

3

C# console app with a reference to c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\DataCollectors\x86\Microsoft.VisualStudio.Coverage.Monitor.dll:

using Microsoft.VisualStudio.CodeCoverage;

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

The object creation line throws a FileNotFoundException with the message Could not load file or assembly 'Microsoft.VisualStudio.Coverage.Monitor.dll' or one of its dependencies. The specified module could not be found.

Any idea why is this happening and how can be fixed?

+3  A: 

or one of its dependencies

Which is the relevant part of the error message. It has a dependency on vspmsg.dll from that same directory, you'll have to copy it by hand into your bin\Debug folder. Using private assemblies, exclusive to Visual Studio, is fairly courageous.

Hans Passant
How is it that does not show in the ILDASM?
Aliostad
@Aliostad, probably because the library is not statically linked but dynamically loaded with `LoadLibrary` at runtime.
Darin Dimitrov
It is an assembly written in the C++/CLI language. It contains unmanaged code. The reason it needs the x86 target. You can see the unmanaged dependencies it has with Dumpbin.exe /imports. One for vspmsg.dll, named GetErrorMessageModule. You're not allowed to distribute it, but if you'd do anyway then you need to have the C++ runtime DLLs deployed as well.
Hans Passant
@Darin I ran reflector and it wasn't there...
Aliostad
@Aliostad: Reflector doesn't show unmanaged dependencies.
Hans Passant
@Hans: True! Thanks. +1
Aliostad
+1  A: 

There are 4 references in this DLL (Here is what you find in 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
}

The first two are used as C DLL and the other two as .NET reference. Have a look to make sure you have Microsoft.Visual (in the GAC) and MSVCR100.dll (somewhere on your machine which is also a Path).

Aliostad
A: 

http://www.dependencywalker.com/ use this to find which resources your files depends on!

HPT