none
C++/CLI dll will not load in C# project (repost, with more info )

    Question

  • I have written some code to create high dynamic range images in C++.  I need to call this code from C# now, so I've wrapped it using C++/CLI.  I've tested it, and it works well.  I sent it to my employer, and he got this error:

    ************** Exception Text **************

    System.IO.FileLoadException: Could not load file or assembly 'HDRLib, Version=1.0.2144.16487, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)

    File name: 'HDRLib, Version=1.0.2144.16487, Culture=neutral, PublicKeyToken=null' ---> System.Runtime.InteropServices.COMException (0x800736B1): This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)

    This error occurs when he clicks the menu item which calls the function that uses the dll, so I assume it gets loaded as it gets used.  I did some research and realised this was telling me that I needed to put the MFC and CRT dlls in my redistributable.  I don't know why, as I don't use either, but I have a dim memory of having to create my own manifest file, perhaps the manifest is claiming to use these two in error.  Anyhow, I run W2000 on a VM, and so I updated it to SP3, .NET 2.0, and got the same error.  Then I went to the x86 directories in Windows/WinSxS and copied across a total of 7 dlls.  The app now runs in my W2000 VM.  If I send those dlls to my boss ( using a tablet PC, XP tablet edition ), it does not work, same error.  I assume he has an x86 processor.  What else could be the problem here ?

    I've spent the evening trying to work this out ( I need to deliver this tomorrow ).  Running it on my XP Home notebook fails, although my W2000 Virtual machine with no dev tools ran it fine.  I also noticed that the manifest asks for a different version of MFC to the one I have installed ( the one frorm the beta, perhaps ) ? I rebuilt the dll again, it's not changed what it asks for.  I found the manifest details in the manifest folder and changed it.  Nothing works.  I've asked about this quite a few times now, but I'm asking one last time because without a solution, I cannot deliver on time.  I've googled and only found other people who have asked the same thing here and got no reply, or who suggested copying the dlls ( which I have done to no avail ).  Any help at all will be most appreciated.

    Tuesday, December 13, 2005 9:08 AM

Answers

  • Hi,

    You first need to understand dependencies of your DLL. It can be both VC++ DLLs and other Dlls of yours. If these are VC++ DLLs, a dependency on any of them is specified in the manifest. Could you post your manifest to this topic?  Is it embedded inside DLL or stored as an external file?  Have you followed steps desribed in http://msdn2.microsoft.com/en-us/library/ms235342(en-US,VS.80).aspx ? Do not manually edit manifest in either your DLL or in WinSxS.

    When you build your app, you may use /verbose switch of the linker (http://msdn2.microsoft.com/en-us/library/wdsk6as6.aspx) and this should give you an idea why MFC is pulled in. You cannot avoid dependency on CRT because it contains initialization code.

    Nikola
    VC++
    Tuesday, December 13, 2005 6:05 PM
  • There are two different merge modules. One with Debug, another one with Release version of CRT. When deploying release version of your program, are you using merge module with Release version of CRT? Also try using depends.exe after you deployed release version of your application to another computer to check if all dependencies are installed. Perhaps the problem is not related to the CRT dll at all.

    You may also contact Developer Support team, support.microsoft.com, to get more detailed help for your project.

    Nikola

     

    Wednesday, January 18, 2006 7:41 PM

All replies

  • I just sent an email to folks that might have more info and pointed them to the post.

    Thanks,
      Ayman Shoukry
      VC++ Team
    Tuesday, December 13, 2005 3:34 PM
  • Hi,

    You first need to understand dependencies of your DLL. It can be both VC++ DLLs and other Dlls of yours. If these are VC++ DLLs, a dependency on any of them is specified in the manifest. Could you post your manifest to this topic?  Is it embedded inside DLL or stored as an external file?  Have you followed steps desribed in http://msdn2.microsoft.com/en-us/library/ms235342(en-US,VS.80).aspx ? Do not manually edit manifest in either your DLL or in WinSxS.

    When you build your app, you may use /verbose switch of the linker (http://msdn2.microsoft.com/en-us/library/wdsk6as6.aspx) and this should give you an idea why MFC is pulled in. You cannot avoid dependency on CRT because it contains initialization code.

    Nikola
    VC++
    Tuesday, December 13, 2005 6:05 PM
  • Thanks very much.  I did actually figure this out last night.  I'd never heard of WinSxS until last night, and I'd suggest that if the error message mentioned it, it would have been a lot easier for me to get to the bottom of it all.
    Wednesday, December 14, 2005 2:22 AM
  • Thanks for your help.  Yes, it turned out that it works in W2000 because I have bundled the VC8 dlls I need with the exe, but in XP, it looks instead in the WinSxS folder, which did not contain all the dlls I needed ( specifically, I needed the MFC dll, for reasons that I still can't work out ).

    I will do a /verbose compile to see, because this is a C++/CLI port of code that definately did not use MFC.  That's a shame about CRT, I thought if I avoided stuff like C string handling, I would avoid that dependancy.
    Wednesday, December 14, 2005 2:24 AM
  • When doing a merge module with all the required SxS libraries, I am able to run the application, and managed C++ wrapper just fine.  If I recompile everything under release mode, I still get random Win32 exceptions before I reach the first line of my code.

    Any idea why this would only work in debug mode?

    I have tried every solution to the FileLoadException problem possible, packaging as shared assemblies, as private assemblies, followed every document on deployment, and nothing will work except shared SxS assemblies in Debug mode (which I cannot redistribute).

    Any help is greatly appreciated.

    -Shane
    Tuesday, January 10, 2006 3:28 PM
  • There are two different merge modules. One with Debug, another one with Release version of CRT. When deploying release version of your program, are you using merge module with Release version of CRT? Also try using depends.exe after you deployed release version of your application to another computer to check if all dependencies are installed. Perhaps the problem is not related to the CRT dll at all.

    You may also contact Developer Support team, support.microsoft.com, to get more detailed help for your project.

    Nikola

     

    Wednesday, January 18, 2006 7:41 PM
  • Hi

    I had the same problem until today (Exception from HRESULT: 0x800736B1).

    In my develop. box everything worked fine, but in the test machine that errors appears when a C# app called a DLL compiled with MSVC++2005.

    After reading the msdn documentation, this forum and other helpfull sites, I managed to fix it. Maybe this could help someone in the same situation.

    1) Install vcredist_x86.exe in the customer/test/deployment machine. It can be found on \Program Files\Microsoft Visual Studio8\Sdk\v2.0BootStrapper\Packages\vcredist_x86

    2) Make sure you are using the dll´s RELEASE version. For some reason the dll´s  DEBUG version keep getting the same error. (Maybe the MSVC++ 2005 redist does not install the DEBUG required files such as Microsoft.VC80.DebugCRT, didn´t check this, just a thought).

    With these two steps I´ve done it. Also you can check if your DLL has the Manifest embedded. Look inside the DLL with a bin editor/reader and look for the xml file with manifestVersion string. If the manifest is not embedded, check for the file in your output dir, something like yourdll.manifest and use the mt.exe tool from the bin dir of vc to include it inside the dll.

    Hope this helps someone, cheers.

     

     

    Friday, January 27, 2006 10:37 PM
  • Solved my problem as well with this post.

    Only thing I had to do was make sure the C++ project was compiled as Release instead of Debug. Error went away on client computer.

    Saturday, October 28, 2006 4:54 PM
  • In my case, having installed vcredist_x86 solved the problem.

    Thanks

    Wednesday, January 31, 2007 11:59 PM
  • In my case, in order to get my project to work on a deployment machine (it worked fine on my development machine), I had to make sure that :

    1. My project was compiled in RELEASE mode
    2. The DLLs on which my project depended were compiled in RELEASE mode (mine were in DEBUG mode, so they failed to load on deployment machine)

    depends.exe (default location : C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin) really helped in determining the dependencies of DLLs that failed to load on the deployment machine.

    Monday, February 12, 2007 9:36 AM
  • It also looks like VS2005 SP1 changed the version of the runtime libraries from 8.0.50727.42 to 8.0.50727.762, meaning that DLLs linked with the service pack will need a new runtime library installed.

     

    --Eric

    Tuesday, May 22, 2007 10:33 PM
  • We had the exact same problem. It turned out that VS2005 SP1 indeed installed a new version of the VC80 runtime (8.0.50727.762), so all binaries will be compiled against that version.

    The good news it that you can find the updated redistributable installation package in 'C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages' and the new runtime can be installed side-by-side with any previous version.

    ---------
    /Enrico

     GenericMoniker wrote:

    It also looks like VS2005 SP1 changed the version of the runtime libraries from 8.0.50727.42 to 8.0.50727.762, meaning that DLLs linked with the service pack will need a new runtime library installed.

    --Eric

    Friday, May 25, 2007 10:45 AM
  • I needed to add 2 merge modules into my MSI and now it works fine

    C:\Program Files\Common Files\Merge Modules\Microsoft_VC80_CRT_x86.msm
    C:\Program Files\Common Files\Merge Modules\policy_8_0_Microsoft_VC80_CRT_x86.msm
    Tuesday, June 12, 2007 2:52 PM
  • I meet a similar problem that I want to wrap a C++/CLI to DLL and use in the ASPX.

    In the past, I use VS2005 and compile it and use in the ASPX is OK.  But now, I compile with use CL.EXE but when I use in the application or website, it said that "The specified module could not be found. (Exception from HRESULT: 0x8007007E)".

    I have run 'C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86\vcredist_x86.exe' aldready.  This is content of my DLL manifest. (mylib.dll.manifest)

    <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
    <assembly xmlns='urnTongue Tiedchemas-microsoft-com:asm.v1' manifestVersion='1.0'>
      <dependency>
        <dependentAssembly>
          <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
        </dependentAssembly>
      </dependency>
    </assembly>

    Please help me. Thanks in advanced.

    TranThanh
    Friday, October 26, 2007 1:42 PM
  • installing vcredist_x86.exe helps still in year 2009!! (see reply of Mariano at Friday, January 27, 2006 10:37 PM)
    Wednesday, April 29, 2009 3:17 PM