Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

NinjaTrader Crashes When Connecting to Data Provider With Indicator Loaded On Chart

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    NinjaTrader Crashes When Connecting to Data Provider With Indicator Loaded On Chart

    Hi,
    I have a custom indicator that uses an external DLL call.

    When I load NT7 and connect to a datafeed then open a chart and run the indicator it is fine.
    (works on startup if this is saved as a preference as well).

    If I start NT7 and load a chart (using data from the disk cache) (no datafeed) and run the indicator it displays results no problem.

    If I then connect a datafeed (Kinectick, AMP, ESignal, etc.) the terminal hard crashes with these results:

    [4672] 2012-08-09 18:43:29:921 (Unknown) Cbi.Connection.Connect0 Disconnected assembly=7.0.1000.9 date=8/9/2012
    [4672] 2012-08-09 18:43:29:921 (Unknown) Cbi.Connection.Connect1
    [4672] 2012-08-09 18:43:30:109 (Kinetick – End Of Day (Free)) Cbi.Connection.Connect9
    [4672] 2012-08-09 18:43:30:250 (Kinetick – End Of Day (Free)) Cbi.Connection.ProcessEventArgs.ConnectionStatusEv entArgs Connecting Connecting NoError
    [4672] 2012-08-09 18:43:30:265 (Kinetick – End Of Day (Free)) Cbi.Connection.ConnectNow1: DataConnection=True
    [4672] 2012-08-09 18:43:30:265 (Kinetick – End Of Day (Free)) Cbi.Connection.ConnectNow2
    [4672] 2012-08-09 18:43:30:453 (Kinetick – End Of Day (Free)) Cbi.Connection.ConnectNow8: System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
    [4672] at System.Runtime.CompilerServices.RuntimeHelpers.Pre pareDelegate(Delegate d)
    [4672] at System.AppDomain.add_DomainUnload(EventHandler value)
    [4672] at <CliSecureRT>.Initialize()
    [4672] at .cctor()
    [4672] --- End of inner exception stack trace ---
    [4672] at System.RuntimeTypeHandle.CreateInstance(RuntimeTyp e type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
    [4672] at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
    [4672] at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
    [4672] at System.Activator.CreateInstance(Type type, Boolean nonPublic)
    [4672] at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
    [4672] at System.Reflection.Assembly.CreateInstance(String typeName)
    [4672] at NinjaTrader.Cbi.Connection.ConnectNow()
    [4672] 2012-08-09 18:43:30:453 (Kinetick – End Of Day (Free)) Cbi.Connection.ProcessEventArgs.ConnectionStatusEv entArgs Disconnected Disconnected Panic Cbi.Connection.ConnectNow: Failed to call IAdapter.Connect: The type initializer for '<Module>' threw an exception.
    [4672] 2012-08-09 18:43:30:453 ERROR: Kinetick – End Of Day (Free): Cbi.Connection.ConnectNow: Failed to call IAdapter.Connect: The type initializer for '<Module>' threw an exception.(Panic)

    #2
    What is the external DLL you are calling? Do you know what version of .NET it requires?

    Are you sure your installation has references to all required DLLs?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Answers to your questions...

      The External DLL is a .NET 3.5 DLL. (C++ CLR with some managed and unmanaged code)
      All references are present since the indicator loads/unloads/executes just fine. The only time an issue crops up is when you run the indicator on a chart and then connect to a datafeed.
      BTW you can close the chart with the indicator on it and connect to the datafeed and still see the NT7 terminal crash.

      Let me know if you want me to send you the installer for the package. Works on 32 and 64 bit versions of NinjaTrader.
      Last edited by sckid; 08-09-2012, 08:10 PM.

      Comment


        #4
        When you connect using AMP or eSignal, does it result in the same exact stack? Or are there other errors that generated from another connection technology?

        Do you have any issues if you remove the external DLL?
        MatthewNinjaTrader Product Management

        Comment


          #5
          Apologies: NT7 Version 7.0.1000.9

          If I remove the external DLLs the indicator does not run at all since it cannot reference functions it needs.

          The simulated data feed does not crash.

          Here is the stack trace for AMP:
          [6464] 2012-08-09 19:18:24:796 (Amp/CQG) Cbi.Connection.ConnectNow8: System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
          [6464] at System.Runtime.CompilerServices.RuntimeHelpers.Pre pareDelegate(Delegate d)
          [6464] at System.AppDomain.add_DomainUnload(EventHandler value)
          [6464] at <CliSecureRT>.Initialize()
          [6464] at .cctor()
          [6464] --- End of inner exception stack trace ---
          [6464] at System.RuntimeTypeHandle.CreateInstance(RuntimeTyp e type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
          [6464] at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
          [6464] at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
          [6464] at System.Activator.CreateInstance(Type type, Boolean nonPublic)
          [6464] at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
          [6464] at System.Reflection.Assembly.CreateInstance(String typeName)
          [6464] at NinjaTrader.Cbi.Connection.ConnectNow()

          Comment


            #6
            Thanks for the clarification.

            I'd suggest making sure that the target framework is not set to anything other than .NET 3.5. For example if the target framework was set to .NET 4.0, this error could be generated.

            Here is more information from MSDN on the BadImageFormatException:

            The exception that is thrown when the file image of a dynamic link library (DLL) or an executable program is invalid.


            You can also do further debugging via Visual Studio - http://www.ninjatrader.com/support/f...ad.php?t=33383
            MatthewNinjaTrader Product Management

            Comment


              #7
              How to fix this issue

              Hey Matt,
              Thank you for your help, NT7 support is much better than your competitors.

              OK, here is how to make sure the problem does not occur:

              1) We are using a mixed mode (managed and unmanaged code C++ CLR) in our DLLs.
              2) There are 2 DLLs (64bit and 32 bit versions).
              3) NinjaScript detects if NT7 is a 32 or 64 bit process and loads the appropriate dll.

              Now when you connect a data feed, it seems like NT7 dynamically reloads all its dlls in the current process. This reload seems to work differently than the DLL loader when indicators are plotting on the chart. In other words, on datafeed connect you have to unload dlls that may have been loaded.

              If they are malformed then the loader may step on something.

              So, here is what caused the bad image error message:

              We build the dlls with VS2010 .NET35 with V10 of the compiler toolset. We had a statically linked library that was built with V9. So the images were mixed. After running through a bunch of tests we were able to make sure that all dlls were built under V9. And voila, works.

              In the future the correct setup for NT7 DLLs would be VS2008 or VS2010 under .NET35 built with the V9 tools.

              Thanks

              Comment


                #8
                Hello sckid,

                Thank you for that information, I am glad you were able to resolve this matter.

                Please let us know if we may be of further assistance.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bortz, 11-06-2023, 08:04 AM
                47 responses
                1,610 views
                0 likes
                Last Post aligator  
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                9 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                19 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                6 views
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                16 views
                0 likes
                Last Post Javierw.ok  
                Working...
                X