Problem: Visual Studio crashes when ArcGIS Sample 'Custom Scene Navigation Commands' is added to a ToolbarControl
A System.NullReferenceException is thrown when using the the sceneTools.dll generated by the C# sample. The crash can be reproduced using the steps below:
1. The following sample is built to create the sceneTools.dll: <DeveloperKit install Location>\SamplesNET\Engine\ControlsCommandsSceneCommands.
2. Create an application that contains a ToolbarControl.
3. Add the ZoomIn and ZoomOut tools from the sample to the application’s ToolbarControl in Visual Studio designer, programmatically or by customizing the control at runtime.
The crash may occur when adding the tools, while building the application, or when exiting the application.
The Custom Scene Navigation Command sample has two commands that do not check for 'null' in the destructors. The Destructor methods are ~ZoomIn() and ~ZoomOut() These methods do not check for null m_pen and m_brush objects before calling the Dispose method. The Destructor method of ZoomIn and ZoomOut is as follows:
m_pSceneHookHelper = null;
m_pCursor = null;
Solution or Workaround
Use one of the solutions below to fix the ArcGIS Sample:
- Delete C# SceneTools.dll from all locations on the machine. Typically, it exists in <DeveloperKit install Location>\SamplesNET\Engine\ControlsCommandsSceneCommands\CSharp\obj\Debug.
Use the VB.NET sample instead.
- Remove the ~ZoomIn method from ZoomIn.cs and ~ZoomOut method from ZoomOut.cs; these methods are redundant. After they have been removed, rebuild the sample.
- Download the latest version of the sample from the ArcGIS Resource Center.