Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a c# .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?

like image 208
Programer Avatar asked Sep 09 '12 09:09

Programer


3 Answers

Because it says "Cannot resolve reference Microsoft.VC80.DebugCRT,processorArchitecture="x86", that means you are missing a dependency on the debug crt runtimes for VC 8.0. This means you need to build a release, NOT debug, version of card.dll. Microsoft doesn't ship a redistributable package for debug CRT runtimes. Those only comes with visual studio. Therefore build a release version of card.dll, and that should help your situation.

like image 55
C Johnson Avatar answered Nov 20 '22 01:11

C Johnson


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.

like image 40
Paul Michalik Avatar answered Nov 20 '22 01:11

Paul Michalik


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.

like image 3
Frederic Avatar answered Nov 20 '22 01:11

Frederic