About ZOSAPI Error: Object reference not set to an instance of an object

  • 20 January 2021
  • 0 replies
  • 52 views

Userlevel 6
Badge +2

When we see the following error using C# for ZOS API User Extension, the most common reason is we opened a tool and didn't well close it before open it again.



 


For example, in the second built-in sample code, we can see there is a line that calls the funciton close() to close the ray trace tool. The same applies to many other tools like ILocalOptimization, IHammerOptimization, IGlobalOptimization, INSCRayTrace, ITolerancing, IConvertToNSCGroup ... etc.



If we try to open the RayTrace tool again before close the previous one, the error will show.



 


The other similar reason this may happen is we terminate the application, for example using the [x] button, unusually before the tool is closed.



 


Note there is a property called TheSystem.Tools.CurrentTool. It's convenient if we can check it and close if needed when finished the API code like below.



0 replies

Be the first to reply!

Reply