Using TurboActivate in NinjaTrader script

I am trying to use TurboActivate.dll in my strategy in NinjaTrader (NT).

NT allows custom strategy development in a C# "group compiled" (my term) environment. In other words, every strategy and indicator package, delivered as a C# assembly is compiled into one massive executable. As a result, I do not have much control over application execution - and no control over build options.

I added TurboActivate.cs to the compile directory, and it will be included in my assembly. I placed TurboActivate.dll in the folder where NT specifies for external DLLs.

When I compile my strategy (a C# class in its own .cs file derived from one of the NT built-in classes), I get the following error: Metadata file 'c:\Users\Mark\Documents\NinjaTrader 7\bin\Custom\TurboActivate.dll' could not be opened -- 'An attempt was made to load a program with an incorrect format. '

When I do a little research on that error on the net I found this reference that seems the most likely to be the problem: http://blogs.msdn.com/b/arvindsh/archive/2009/06/21/tip-of-the-day-an-attempt-was-made-to-load-a-program-with-an-incorrect-format-net-p-invoke-issue.aspx. The author states:"After some troubleshooting it turned out that this utility was trying to load a plain-old DLL presumably using P/Invoke. The DLL was built for 32-bit platforms. Now it turns out that by design a 64-bit process (the 3rd party utility would run as a 64-bit process owing to the 64-bit .NET runtime) would be prevented from loading a non-COM 32-bit DLL (32-bit COM DLLs are loaded in a DLLHOST.EXE surrogate when invoked from a 64-bit client process, BTW...) with the above exception."

The author provides a solution using the corflags utility. Is it possible that this is the problem/solution? If not, do you have any recommendations?

Thanks,

OK, your code is being compiled as "Any CPU". Meaning it runs as x64 on 64-bit versions of Windows and it runs as x86 on x86 versions of Windows. DOes NinjaTrader give the option to runs as x86? If not, the alternative is to include both the x86 and x64 versions of TurboActivate with your app. You'd have to modify the TurboActivate.cs file to choose which dll to load.

Email me at wyatt@wyday.com and I'll send you the TurboActivate.cs we'll be including in the next version of TurboActivate. This new *.cs file has the ability to use either the x86 or x64 version of TurboActivate -- choosing at runtime.

Thanks Wyatt - that works with my current installation. I will be checking the fix with both 32 and 64-bit versions of NinjaTrader over the next few weeks.

Great, I'm glad to help.