views:

127

answers:

4

Hello, I’m having some difficulties while trying to consume an unmanaged-code dll from my application (Written in C# framework 4.0) I’m using the dll import as follows

[DllImport(@"C:\MGW_SDK.dll", EntryPoint = "fInicializaSDK")]
public static extern int fInicializaSDK();

The weird thing is that when called from my development environment(Windows XP) it works just fine, but when on the production server (Windows7) it generates the following exception:

System.DllNotFoundException: Unable to load DLL ' C:\MGW_SDK.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Comtpaq.AdminPack.SDKWrapper.fInicializaSDK() at Comtpaq.AdminPack.AdminPaqRepository.InitializeSDK() in C:\Work\AgroIn\AdminPaqRepository.cs:line 30

I already ran Dependency Walker That shows the following dependency as conflicted: C:\windows\system32\SHLWAPI.DLL I already tried copying that DLL to my deployment directory

The MGW_SDK.dll is on c:\ (as the path says)
I already installed C Runtime Library

I also noticed some interesting stuff… on the exception the development path is show “C:\Work\AgroIn\AdminPaqRepository.cs:line 30”

What else can be the problem here?

I really appreciate any help with this.

Edit

OK... a little update on this issue, so i build a very little console application with just one of the extern/dllimport methods that i use from MGW_SDK.dll... and ran it with no problem (no DllNotFoundException what so ever), so this seems to be related to the application that i'm building (WCF Service...). This service is hosted on the WAS, but still i'm not able to find what the issue is... Help!



Thanks

+1  A: 

Have you tried using Assembly Binding Log Viewer?

Assembly Binding Log Viewer

gaearon
Does that work for DllImport/PInvoke libraries? It looks like it is only for CLI assemblies.
Foole
Can't be sure. I googled around but I didn't find any entries specifying it either works or does not for P/Invoke libraries. Worth a try, I think.
gaearon
i ran it on where i have the service, but shows no information, however when i run it on the client it shows the processes... does it need a Window in order to log? how about WCFs?
Bongo Sharp
+1  A: 

Don't know if this will work for sure but have you tried registering MGW_SDK.DLL using regsrv32 or other installation package on Win7 box?

Also try to find out if the dependencies of MGW_SDK.DLL are also available on Win7 machine (either registered on system or in your application folder will work)

TheVillageIdiot
i tried registering the dll using regsvr32 but it didn't workThe Module "MGW_SDK.dll" failed to load Make sure the binary is stored at the specified path or debug it tp check problems with the binary or dependent .DLL files.The specified procedure could not be foundthe only dependency that i see here failing (dependency walker) is SHLWAPI.DLL
Bongo Sharp
most probably it is making use of XP specific version of Shell API. try right clicking and setting its compatibility mode to XP or contact owners/publishers of MGW_SDK.dll to get updated version.
TheVillageIdiot
i right clicked but i didn't found the Compatibility MOde
Bongo Sharp
+1  A: 

The root of C is one of the places UAC will not let you write. Sometimes unmanifested apps that ask to read from a protected area end up reading from the virtualized equivalent - and your DLL will not be there. Try moving the DLL to a different folder (not the root of C, not anything under Program Files) and see if that solves it. If it does, you can leave it there or (better) put a manifest on your app to prevent virtualization.

Kate Gregory
i tried another path as well (not in the root), and happend the same error
Bongo Sharp
A: 

Well... this was a very tricky problem, it was not related to dll dependencies... not related to the dll location either... it was not about how i was calling the dllimport.... it was a permissions problem... see the article bellow: http://www.stillhq.com/aus-dotnet/archives2/msg00033.html bassically this issue is solved by taking out and then back the permissions for execute on the folder where the dlls are... ah... now i can go to sleep...
thanks for all your help and i really hope this post helps other people get over this issue... as it was a pain in the back for me...

Bongo Sharp