简体   繁体   中英

C# Dll Import failure: “The application has failed to start because its side-by-side configuration is incorrect”

I have ac# .net 4 app , using vs 2010. Im trying to import a c++ dll (built on vs 2005).

 [DllImport("Card.dll")]

I get the failure:

Unable to load DLL 'Card.dll': The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. (Exception from HRESULT: 0x800736B1)

using sxstrace.exe I get:

ERROR: Cannot resolve reference Microsoft.VC80.DebugMFC,processorArchitecture="x86"

I also found out that:

MFC80D.DLL and MSVCR80D.DLL are missing

Notice this is not DebugCRT, as this problem was caused by using a Debug compiled DLL instead of Release. I now use the Release compiled dll and the problem is DebugMFC.

I've tried anything I could find online. In order to save time I will introduce what I tried, so I won't get this advises again:

1- I have installed Microsoft Visual C++ 2010 Redistributable Package + SP1 + Security updates

2- I have installed Microsoft Visual C++ 2008 Redistributable Package

3 - I have installed Microsoft Visual C++ 2005 Redistributable Package

4 - I tried running this app as "Release" and not as "Debug"

5 - I tried to set entryPoint to the DllImport

Non helped. I still get the same error. I didn't see any other advise online instead of the one listed above. Can anyone help me?

因为它说“无法解析引用Microsoft.VC80.DebugCRT,processorArchitecture =”x86“,这意味着您缺少对VC 8.0的调试crt运行时的依赖。这意味着您需要构建一个版本,而不是调试版本的卡.dll。微软没有为调试CRT运行时提供可再发行的软件包。这些软件包只附带visual studio。因此构建一个发布版本的card.dll,这应该有助于你的情况。

Do you have control over building Card.dll ? If yes, have a look at how it is built. It must be built with proper version of VC++ (the one delivered with VS 2005) with manifest enabled. Then, installing the 2005 Redist. package must solve the problem. In case you cannot build Card.dll yourself, you will have to analyse the embedded manifest (if any) and contact the authors to remedy the problem cooperatively.

A static library by default links to the dynamic runtime.

If you re-build the dll in VS2005, change your Configuration Properties | C/C++ | Code Generation | Runtime Library setting to static runtime to avoid that problem.

You can use Dependency Walker to try to figure out what dependencies your dll pulls. If it says it wants *d.dll , then it looks like it is not a release version. Ask your colleague to check build configuration.

To use debug version you can try the following:

  1. Go to the c:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\Debug_NonRedist\\x86\\ (this is for Visual Studio 2008, x86, adjust the path according to your system).
  2. Copy the Microsoft.VC90.DebugCRT and Microsoft.VC90.DebugMFC directories to the directory with your executable.
  3. Adjust the assembly version in the manifest files in the copied directories (the declaration looks like: <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.30729.6161" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity> , change the 9.0.30729.6161 according to what your dll needs.
  4. Try to run the application.

The needed assembly version can be found in the output of sxstrace or in the in the *.intermediate.manifest file alongside the dll in its build directory. Sorry, I do not have Visual Studio 2005 and can not give the exact number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM