Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CsScript loading DLL throws error
Hi -

I can run the example CsScript programs just fine. But when I attempt to load a DLL that I believe is a x86 DLL on a 64 bit machine under Windows 7 I get the following error:

Quote:Error (RT) in LeapMotion: 0x80131600,
(0,0): error CS0009: Metadata file 'c:\Program Files (x86)\Quick Macros 2\Leap.dll' could not be opened -- 'An attempt was made to load a program with an incorrect format. '.

The QuickMacros code starts like this:
Copy      Help
CsScript x.AddCode("")
IDispatch o=x.CreateObject("SampleListener")

//C# code
using System;
using System.Threading;
using Leap;
In the CsScript documentation it claims that this could happen if you're trying to load an x64 dll
and their fix is to compile as an external application. I don't want to do this because the library is going to be feeding user gestures from the LeapMotion sensor into QuickMacros and I don't want the latency.

The only alternative I can think of is to make a COM interface that glues everthing together. Is there a simpler way?


To test, I created a .NET dll in Visual Studio, for 3 platforms: "x86", "x64" and "Any CPU".
Tried to load the dll with this macro. You see results.
Macro Macro2129
Copy      Help
;CsScript x.Load("$my qm$\test\ClassLibrary1\ClassLibrary1\bin\x86\Debug\ClassLibrary1.dll") ;;platform "x86", works on Win7 32 and 64 bit
CsScript x.Load("$my qm$\test\ClassLibrary1\ClassLibrary1\bin\x64\Debug\ClassLibrary1.dll") ;;platform "x64", error on Win7 32 and 64 bit: "An attempt was made to load a program with an incorrect format"
;CsScript x.Load("$my qm$\test\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll") ;;platform "Any CPU", works on Win7 32 and 64 bit
out x.Call("ClassLibrary1.Class1.Test")
Then tried to load indirectly. Results are similar.
Macro Macro2129
Copy      Help
CsScript x
;x.SetOptions("searchDirs=$my qm$\test\ClassLibrary1\ClassLibrary1\bin\x86\Debug[]references=ClassLibrary1.dll")
x.SetOptions("searchDirs=$my qm$\test\ClassLibrary1\ClassLibrary1\bin\x64\Debug[]references=ClassLibrary1.dll")
;x.SetOptions("searchDirs=$my qm$\test\ClassLibrary1\ClassLibrary1\bin\Debug[]references=ClassLibrary1.dll")

using System;
using ClassLibrary1;
public class A{static void Main(){Console.Write(ClassLibrary1.Class1.Test());}}
QM creates x86 assemblies. Can load x86 and "Any CPU" assemblies, directly and indirectly. Cannot load x64 assemblies. Same on Windows 32 and 64 bit.
QM works almost like C# script ( In this case the difference is that C# script is compiled for "Any CPU" platform. QM - for x86. It means that C# script on Windows 64 runs as x64 and therefore cannot load x86 assemblies. QM assemblies always run as x86 and always can load x86 assemblies, never x64.

When testing same assembly compiled for different platforms, restart QM, or it may use the already loaded assembly regardless what is specified.

Forum Jump:

Users browsing this thread: 1 Guest(s)