Archived Forum Post

Index of archived forum posts

Question:

Please Add 'Any CPU' support for C#/ .NET

Feb 08 '15 at 14:37

[Updated] Added clarifications based on chilkat's answer.

Suggestion: Instead of having 64-bit and 32-bit managed (.NET) Chilkat Mono dlls have one dll that targets 'Any CPU'.

Why: This will allow any .NET project that uses Chilkat Mono managed dll to be built and deployed independently on both 32-bit and 64-bit machines. E.g. it can be built on 32-bit machine and deployed on 64-bit or vise versa. Also, on 64-bit machine same set of managed dlls can be used in 32-bit and 64-bit processes. Basically, the decision which dll to load is moved from compile-time or install time to run time. That's what 'DLL' abbreviation stands for actually :)

Bonus: You won't have to answer the question about "incorrect format exception" EVER AGAIN.

How: Instead of using DllImport attribute to load unmanaged dll use LoadLibrary and GetProcAddress to bind managed methods to unmanaged calls. In a nutshell, this is the code: http://stackoverflow.com/a/1896685

People did that for many managed/ unmanaged projects, for example ZeroMQ: https://github.com/zeromq/clrzmq/issues/15 https://github.com/zeromq/clrzmq/blob/master/src/ZeroMQ/Interop/UnmanagedLibrary.cs

All the cool kids do that :)

Thanks, Ross


Answer

Thanks Ross,

I'm copying the information below from another post. The Chilkat .NET assembly does not use DllImport -- it is a mixed-mode assembly that contains a native inner core. The Chilkat for Mono .NET assembly however, does use DllImport. See below:

Try using the "Chilkat Mono" .NET assembly instead.

The difference between "Chilkat Mono" and "Chilkat .NET" is that the Mono implementation is a 100% managed .NET assembly that references a native DLL (or shared lib) for it's implementation, whereas the "Chilkat .NET assembly" is a mixed-mode assembly that is composed of a managed outer-layer API with a native inner core.

It is possible to use "Chilkat Mono" with Visual Studio C# and VB.NET applications, in exactly the same way as using the "Chilkat .NET" mixed-mode assembly -- except that at runtime the Chilkat Mono assembly needs to find and load the native DLL. The name of the native DLL to load is contained in the "ChilkatConst.cs" source file in the Chilkat Mono download. See http://www.mono-project.com/Interop_with_Native_Libraries for information about how the runtime finds the DLL specified by DllImport.