Question

Problem in short: How to call a function from DLL A.dll using p/invoke when A.dll depends on another SXS-lib (in my case MSVCR90.DLL)?

I'd like to call a function within a DLL using pinvoke. pinvoke itself works fine for other libs. Calling the function in the DLL from unmanaged C++ works fine, too.

The problem is that the DLL has a reference to MSVCR90.DLL which resides in some SXS folders.

Using LoadLibrary in C++ the library can be used as mentioned. Using C# I don't know how to get the library loaded. I always get an error that MSVCR90.DLL was missing on the computer.

This is what loading the library looks like:

[DllImport("C:\\work\\dllhell\\sample\\sample.dll", 
    EntryPoint = "sample", CallingConvention = CallingConvention.Cdecl)]
public static extern int sample();

When calling the function sample, I only get the following error: HRESULT: 0x8007007E saying that the library would not have been found. Actually, the library exists in various versions in SXS directories.

I tried using Dependency Walker (depends) but it also has not been able to locate the right version of the library, so far.

There is also a manifest shipped with the library containing the following entry:

The following statement is included within the manifest:

<assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8'
    processorArchi    tecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />

The version requested exists on my machine, I'm using VS 2010 which ships newer versions of that library but that shouldn't be a problem, I guess.

I found a lot of threads discussing similar problems. I know, I have a dependency issue but I could nowhere find a solution. I know my missing dependency, I have a manifest but should that do it for C#, too? Not only for unmanaged C++?

Was it helpful?

Solution

In case anyone searches for that issue: of course, David Heffernan has solved the issue, the dependency has to be added to the application's manifest, i.e. the file app.manifest, create it as new manifest in your projekt if there is no such file, yet.

The following entry is sufficient:

  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>

This entry goes directly to the root node assembly in the XML file.

Thanks to David Heffernan, forget about my last comment, it has been the solution to my question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top