6

I'm calling the following from c#:

[DllImport("u3dapi10.dll", CharSet=CharSet.Auto)]
public static extern uint dapiCreateSession(out uint hSession);

Where is .NET looking for the u3dapi10.dll file? This was working previously but now I'm getting a DLLNotFoundException.

The u3dapi10.dll file is in the root directory of the project. I tried copying it to the bin/debug directory just to see what happens, but it couldn't find it there either.

Possible cause: Could this be caused by the u3dapi10.dll not being 64-bit compatible? e.g. Is a DllNotFoundException thrown if you try to access a 32-bit dll from a 64-bit machine? Or would it throw a BadImageFormatException as suggested by BadImageFormatException when loading 32 bit DLL, target is x86

Community
  • 1
  • 1
Jason
  • 8,400
  • 10
  • 56
  • 69
  • 1
    Seems to be a duplicate: http://stackoverflow.com/questions/2411736/p-invoke-dynamic-dll-search-path – Mark Wilkins May 11 '11 at 21:12
  • That question does answer the first part of my question, could it also be caused by the 32-bit/64-bit issue? – Jason May 11 '11 at 21:14
  • I just encountered the error caused by the wrong bitness in the DLL just a few days in a test I was running .... and, sadly, I cannot for the life of me remember which exception it caused. I *think* it was some kind of "badimage" style exception, but I would not make any decisions on that poor recollection attempt. I need a memory upgrade. – Mark Wilkins May 11 '11 at 21:54
  • Thanks for the help. After locating the dlls, I had the 32/64-bit problem. In that case, it does throw a BadImageFormatException. – Jason May 11 '11 at 23:28

1 Answers1

3

See: Specify the search path for DllImport in .NET

and

http://msdn.microsoft.com/en-us/library/ms682586%28VS.85%29.aspx

Community
  • 1
  • 1
John Ruiz
  • 2,371
  • 3
  • 20
  • 29