Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NullReferenceException on a conditional null check?

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

    NullReferenceException on a conditional null check?

    I'm trying to fix a bug that I cannot reproduce (yipeee!). I have the stack trace that was copied by the user that originally discovered the issue, and it shows the code throwing a null reference exception (which is unhandled) on a line that is checking the object for null..like this:

    Code:
     private void someFunction() {     radioButton1.CheckedChanged -= checkedChangedEventHandler     radioButton2.CheckedChanged -= checkedChangedEventHandler      if (someObject != null)  // throws NullReferenceException...allegedly     {          if (someObject.Property == something)          {             // set properties on some UI components          }     } }
    What kind of conditions could cause this?

    UPDATE

    Added some more code. SomeFunction method gets called by the checkedChanged event handlers.

    UPDATE 2

    The stack trace must be wrong as several of you have suggested. There are no operator overloads, and the method only references four objects that are not UI components (labels and radio buttons), and all of those objects are assigned only once on initialization, and are referenced multiple times before ever getting to this mobdro code so any null references would have been caught way before this. I'll have to look more closely at the calling event handler function.

    #2
    Hello Nathan155,

    To confirm, your script is calling throw to create an exception?

    May we have a sample of the code causing the behavior?

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.


    Once exported, please attach the file as an attachment to your reply.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Nathan155,

      To confirm, your script is calling throw to create an exception?

      May we have a sample of the code causing the behavior?

      To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
      1. Click Tools -> Export -> NinjaScript...
      2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
      3. Click the 'Export' button
      4. Enter a unique name for the file in the value for 'File name:'
      5. Choose a save location -> click Save
      6. Click OK to clear the export location message mobdro
      By default your exported file will be in the following location:
      • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
      Below is a link to the help guide on Exporting NinjaScripts.


      Once exported, please attach the file as an attachment to your reply.
      This works really well for us, thank you!!!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      597 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      343 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      556 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      555 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X