简体   繁体   中英

Migrating down from .NET 2.0 to .NET 1.1 - DllImport no longer works

One of our apps is in C#/.NET 1.1/VS2003 and needs to remain as is :-(

I need to use code from another C# assembly that is in .NET 2.0: because of technical restrictions (.NET 1.1 mandatory, so direct use of .NET 2.0 impossible), I took code away from the .NET 2.0 project to try to adapt it to .NET 1.1 (not easy, since no generics, partial forbidden, etc).

My 1.1 code now compiles, but fails at execution time because of an EntryPointNotFoundException due to P/Invoke to an unmanaged DLL.

What's strange is that I tried to validate my changes first in .NET 2.0, and I don't have any problem importing the DLL:

[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromHandle")]
public static extern FREE_IMAGE_FORMAT GetFileTypeFromHandle(ref FreeImageIO io, fi_handle handle, int size);

The declaration is the same in both projects, of course the DLL is the same as well. dumpbin.exe gives for the signature:

_FreeImage_GetFileTypeFromHandle@12

I also tried to declare the entry point with this name, but that does not work either, as well as trying desperately to change CallingConvention , CharSet , ExactSpelling ... No way !

This may come either:

  • from a change in the way DllImport works between .NET 1.1 and 2.0, but I did not find anything that goes in this way

  • from an error in my code migration down to .NET 2.0 to 1.1, but I don't see how it could be the case for this point precisely (I even traced the code to see the sizes of the arguments, io and handle , they are the same in both cases)

  • ... something I can't think of !

Many thanks for your expertise !

Oh - I just became aware that I had a DLL name collision that raised this issue (.NET project and unmanaged DLL with the same name)... Ouch ! Sorry, my question's totally pointless then. Thanks for reading anyway !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM