Ed.
Ed.

Reputation: 966

C# application with C DLL crash at first access to DLL

I have a C# application and a C DLL both of which I wrote and both of which work on a few W7 (64-bit) and XP (32) machines I've tried it on. Today I installed the app/dll set on yet another machine (XP) and it crashes on the first call to the DLL. I've replaced the code in the DLL that gets called with return(0) and it still crashes. I've been using this app/dll set for a few days on a few machines without a glitch, but now I'm stumped 'cause it dies just accessing the DLL. Any ideas?

Added note since my original post: I've learned some things based on suggestions below... 1. the exception error message is "... side-by-side configuration is incorrect...". Googling seems to indicate that this is an issue related to the PC not having the correct (compatible) environment; however, note that this C# app has run on this PC just fine in the past (difference being that the DLL is now built with VS2008 rather than Cygwin/MinGW/GCC). 2. dependency walker tells me that the file IESHIMS.DLL cannot be found. I have no idea what this file is for, but apparently I need it.

Upvotes: 1

Views: 1369

Answers (2)

Justin
Justin

Reputation: 86729

The IESHIMS.DLL dependency appears for pretty much every file I open in dependency walker and its never been the source of any problems - you can almost certainly ignore that.

You should check to make sure that you have the correct version of the Visual C++ Redistributable, and you might also want to check this question - Side-by-side configuration error (Microsoft.VC80.CRT v8.0.50608.0) to make sure that this is not applicable to you.

Finally, you should make sure that your C# application targets a specific architecture (the one that the native dll was built against) rather than "Any CPU", as uisng "Any CPU" will mean that the program will run either as a 64 bit or 32 bit application depending on what machine you run it on, which will cause problems on 64 bit machines attemtping to load 32 bit native dlls.

If your app previously worked when compiled with a different runtime then it sounds like the Visual C++ runtime is simply not installed on that specific machine - you should never assume that it is, however on many machines it has already been installed by another application.

Update: Here is a link to the Microsoft Visual C++ 2008 Redistributable Package (x86).

Upvotes: 1

Andreas Paulsson
Andreas Paulsson

Reputation: 7803

Perhaps there is a missing dependency (dll) for the C dll (perhaps a C++ runtime?)? Can you run depends.exe : http://www.dependencywalker.com/ on the dll on the machine where your application crashes and see if there are any missing dependencies.

Could you also add exception handling around your first call to the C dll to catch and display any exceptions?

Upvotes: 1

Related Questions