VS C# application crashes with IB TWS

Discussion in 'App Development' started by QuantWizard, Feb 24, 2016.

  1. What I will do is probably to uninstall TWS and install latest (or same version as on local machine), install the C++/J# runtimes etc. and see if that does the trick, must be some sort of incompatibility issue somewhere...
     
    #11     Feb 24, 2016
  2. botpro

    botpro

    Not sure, but I think you should use the "original" Java instead of the MS thing...
     
    #12     Feb 24, 2016
  3. Ok I just developed a minimal TWS API application, and now got this error report - could it mean that there is incompatibility between the TWS API versions on my local machine vs. server?

    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.Reflection.TargetParameterCountException: Number of parameters specified does not match the expected number.
    at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
    at TWSLib._DTws.connect(String host, Int32 port, Int32 clientId, Int32 extraAuth)
    at AxTWSLib.AxTws.connect(String host, Int32 port, Int32 clientId)
    at Test3.Form1.Form1_Shown(Object sender, EventArgs e)
    at System.Windows.Forms.Form.OnShown(EventArgs e)
    at System.Windows.Forms.Form.CallShownEvent()
    at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
    at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
    at System.Windows.Forms.Control.InvokeMarshaledCallbacks()


    ************** Loaded Assemblies **************
    mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
    ----------------------------------------
    Test3
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Trading/Algorithms/Test3.exe
    ----------------------------------------
    System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    AxInterop.TWSLib
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Trading/Algorithms/AxInterop.TWSLib.DLL
    ----------------------------------------
    Interop.TWSLib
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Trading/Algorithms/Interop.TWSLib.DLL
    ----------------------------------------
    Accessibility
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.17929 built by: FX45RTMREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
    ----------------------------------------

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    <configuration>
    <system.windows.forms jitDebugging="true" />
    </configuration>

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.
     
    #13     Feb 25, 2016
  4. vicirek

    vicirek

    It reports wrong number of function arguments for connect method. It expects 4 arguments and you are supplying 3. Try adding false (bool) as the 4 argument (last) to connect function call. The actual argument being forwarded to ActiveX will be translated to 0 since it expects int32 instead of bool because bool most probably cannot be forwarded directly to COM objects.

    Make sure that both machines have the same API version installed because your old app was developed with old connect method and now you trying to do the same with newer API version installed.
     
    #14     Feb 25, 2016
  5. This is bizarre. I tried to create a minimal F# application just connecting to IB TWS, and now also got the same error message even on my local machine. It seems like AxTWSLib has a connect version with 3 arguments while TWSLib has one with 4 so there is some sort of conflict between the two - both of which are needed so no idea how to resolve this...any ideas? Your suggestion was not accepted by F# but in C# it was - still threw an exception though so no change...
     
    #15     Feb 26, 2016
  6. vicirek

    vicirek

    I do not even know which API version you are using. Did you upgrade your API on the computer but did not change references in your application? If you upgrade API it is better to delete old dll manually in Windows system folder. Is the exception different this time? If you are using Visual Studio too tips will show you correct signature. If you have this problem the best way to do this is to have clean install of IB API and then try minimal application. Keep in mind that ActiveX is no longer supported with the newest API versions.
     
    #16     Feb 26, 2016
  7. Heis

    Heis

    Imho, the craftsman should not make his own tools unless they will be distinctly better than what is avaliable.
    If you want to make a trade engine, please enjoy, but if you want to algo trade, it would be much easier to use a free platform like quantconnect. Which already has everything you have on your spec list. Happy coding.
     
    #17     Feb 26, 2016
  8. It worked last week, hence my bewilderment...anyway will reinstall and see if that helps. Why is ActiveX no longer supported?
     
    #18     Feb 26, 2016
  9. vicirek

    vicirek

    ActiveX is an old technology requiring extra steps to communicate between .Net and COM objects. Latest IB API is built using .Net making it more compatible with modern technologies. You can still use ActiveX by installing older API version.
     
    #19     Feb 26, 2016
  10. Ok got it. Btw, I just resolved the issue! Here's how I did it: In the application folder, VS generated two dll files called AxInterop.TWSLib.dll and Interop.TWSLib.dll - I simply removed the former TWS dll files from my project and added these instead, and then it worked! So somehow the issue was in the interface between the dll's and the TWS COM component. Good for others to know for the future I guess so happy to share this knowledge.
     
    #20     Feb 27, 2016