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

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 bortz, 11-06-2023, 08:04 AM
      47 responses
      1,606 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
      15 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X