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

Unhandled exception: Exception has been thrown by the target of an invocation.

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

    Unhandled exception: Exception has been thrown by the target of an invocation.

    I'm getting this error

    Unhandled exception: Exception has been thrown by the target of an invocation.

    and it seems it is coming from this code...

    else if (State == State.Realtime)
    {
    ChartControl.Dispatcher.InvokeAsync((() =>
    {
    chartWindow = Window.GetWindow(ChartControl.Parent) as Gui.Chart.Chart;

    if (chartWindow == null)
    return;

    accountSelector = chartWindow.FindFirst("ChartTraderControlAccountSe lector") as AccountSelector;
    accountSelector.SelectionChanged += accountSelectorChanged;
    }));

    }

    this started happening recently...don't know what changed?

    from what I remember the AccountSelector object is not instantiated before Stata.Realtime

    and if the Dispatcher is not used, there is a thread error

    how to fix?

    ??.


    #2
    When this happens the Account Selector on ChartTrader has no Account. It is blank.

    Comment


      #3
      this happens when the workspace is open before the connection is made

      when I boot ninja normally all the workspaces I need are opened before the connection happens

      if I open the workspaces after the connection is made, then I don't get this error

      Comment


        #4
        I have three Apex accounts and two SIM accounts...

        Comment


          #5
          the apex accounts have just one login userid /password

          Comment


            #6
            Hello llanqui,

            With some small changes I'm not able to reproduce when testing this code.

            Below is a link to a video demonstrating.


            You may find the example linked below helpful.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I will move the code to State.Dataloaded like in the example and see what happens...but if I remember the AccountSelector is null before the Accounts are connected...

              ??

              Comment


                #8
                Hello llanqui,

                The AccountSelector should not be null if the ChartControl is not null as this is the WPF Control in the window.

                The AccountSelector.SelectedAccount will be null if there is no account selected.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I found the problem.

                  In the Trace file the dump showed I was referencing a null object (of my own) in the AccountSelectorChanged script

                  that method apparently is triggered when the account selected goes from null to the default account when a connection is established

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NeoTraderBot, Yesterday, 10:55 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post NeoTraderBot  
                  Started by OliverWaters, Yesterday, 10:35 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post OliverWaters  
                  Started by Graci117, 07-06-2024, 09:32 AM
                  6 responses
                  37 views
                  0 likes
                  Last Post Graci117  
                  Started by AdamDJ8, 07-01-2024, 06:50 PM
                  2 responses
                  122 views
                  0 likes
                  Last Post AdamDJ8
                  by AdamDJ8
                   
                  Started by AdamDJ8, 07-01-2024, 05:55 PM
                  3 responses
                  32 views
                  0 likes
                  Last Post AdamDJ8
                  by AdamDJ8
                   
                  Working...
                  X