Log in

View Full Version : NotSupportedException when Performing Platform Invoke


paulzazzarino
11-02-2005, 11:03 PM
This is the wierdest thing. I am using the hpcamlib.dll to collect photo snapshots. Calling a C# libary to platform invoke some functiions within a dll which HP provides (hpcammgr.dll). Running 2.0 CF on an HP device.

If I run the VB demo the dll locates the functions correctly. Note the VB app uses the same C# assembly as the C# app.

If I run the C# demo the dll is located but when I call the first function I get a NotSupportedException exception. This does work with the VB app.

Note: a native C++ app works fine, as does the VB demo. What am I missing here?
OK C++ --> hpcamapi.dll ---> who cares it works!!!
OK VB --> hpcamlib.dll --> hpcammgr.dll hpcamapi.dll
NOT! C# --> hpcamlib.dll --> hpcammgr.dll hpcamapi.dll

the VB and C# app each reference the same assembly, what am I missing here. (I thought C# was supposed to get rid of dll hell!)

GSmith
11-03-2005, 05:28 PM
Are you sure that the dll functions within the C# libary are declared correctly (both arguments and return value)? Or is that what you mean by "the VB and C# app each reference the same assembly" where "same assembly" means the same "C# library" which contains the DLL declarations.

(also, for generic P/Invoke help, see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfintrointerp.asp
but it seems you may already know all that)

paulzazzarino
11-03-2005, 06:35 PM
hmm...

thank you for the link to the article. Since the VB app works and the C# app does not I will assume that the bug is in the upper layer of C# code which I wrote. I rebuilt the middle layer C# dll/assembly and it works with the VB demo.

According to the doc you will get a missingmethod or notsupported exception if the args or retvals do not line up. Must be a return value as the f(x) called does not pass any values.

thanks, [still stumped, but I learned alot about exceptions which can occur when p'invoking]