Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

calling 'OnStateChange' method. Object reference not set to an instance of an object

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

    calling 'OnStateChange' method. Object reference not set to an instance of an object

    I have an indicator that works with no issues but on the log and trace I get the error
    Error on calling 'OnStateChange' method. Object reference not set to an instance of an object

    This error is too vague but I Know it is in OnStateChange. I tried to debug it in Visual studio 2017 but I can not get the breakpoints activated to find where the issue is.

    When adding breakpoints The error I get is breakpoints will not be hit. No symbols have been loaded for this document.
    Does anyone know how to fix this in order to use the breakpoints?

    #2
    well I found the issue but I was wondering if there is a better way than just a regular try and catch

    try
    {
    ChartControl.MouseLeftButtonDown -= MouseClicked;
    }
    catch { }

    Comment


      #3
      Lastly if you want to use visual studio 2017 you have to compile in ninjatrader in order for the breakpoints to be recognized

      Comment


        #4
        Hello ballboy11,

        Thank you for the post.

        The error you are getting is a general C# error relating to using an object that is null. You can search online (google) for this error message ( Object reference not set to an instance of an object) to gather further details about it. OnStateChange is simply the location, however, there are multiple states so adding a Print(State) at the beginning of OnStateChange can help debug this type of situation.

        You have likely used ChartControl either in a state where it cannot be used, or the script is being used in a use case where ChartControl is not present. The solution is to just check if the object is null. I would never suggest using try/catch for general purpose cases like this I would only suggest using try/catch for targeted debugging when you know what exception should be raised.

        Code:
        if(ChartControl != null)
        {
           //do the logic here
        }

        In regard to visual studio, that would be correct, visual studio would require you to compile NinjaTrader in debug mode for breakpoints to be met. We have a guide on debugging with visual studio here: https://ninjatrader.com/support/help...=visual+studio

        Please let me know if I may be of additional assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        641 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X