Problem: Unexpected results using Visual Basic's debugger
When debugging a Visual Basic DLL, one of the following problems occurs:
- The bitmap defined in the implementation of ICommand does not appear on the toolbar while in debug mode.
- Trying to QueryInterface to a valid interface fails.
- An error is returned when executing IFeatureClass::Select against SDE data.
- ArcMap hangs in debug mode.
When the application is run in debug mode, Visual Basic exchanges the CLSID of the component and ArcMap loads the VB6Debug.dll into memory instead of the component. The debugger forwards requests to the ActiveX DLL projects, allowing the user to debug interactively with Visual Basic. Since VB6Debug.dll is running in a different process space than ArcMap, a special marshalling code is required to pass objects across boundaries. This special marshalling is the cause of the debug problems.
Solution or Workaround
- Use the ESRI Error Handler and Line Number Generator AddIns from ArcObjectsOnline when creating the application. See the link in Related Information, below.
- Debug the Visual Basic application using C++ debugger.
To debug ArcObjects code written in Visual Basic, use either ESRI add-ins (ESRI ErrorHandler & ESRI Line Number Generator) or run their VB code in C++'s debugger.
More information about ESRI add-ins is available in the Utilities folder of ArcObjects Developer Help.
Procedure:Follow these steps to use Visual C++ to debug a Visual Basic ActiveX DLL ArcObjects application.
Note: Steps 1-3 apply to the Visual Basic project; the remaining steps apply to Visual C++.
- In the Visual Basic ActiveX DLL project, click Project > Properties > Compile.
- Check Create Symbolic Debug Info.
- Click File > Make xxxx.dll, to recompile the DLL and create the PDB file.
- Start VC++. Close any open workspaces.
Warning: You must have Visual C++ installed in order to continue.
- Click File > Open and navigate to the Visual Basic class file (.cls) of your Visual Basic ActiveX DLL project.
- Press F5 to run the program (Build > Start Debug > Go).
- Click Yes to create a project.
- Click No; you do not want to create an EXE.
- Click Project > Settings > Debug.
- Click Category General. Set 'Executable for debug session' to ..\arcexe82\bin\ArcMap.exe.
- From the Category dropdown list, click Additional DLLs. Navigate to your Visual Basic DLL and click OK.
- Set break points in the code by going to the line where you want to start, and press F9.
- Press F5 to run the program.
- Check the box ..\arcgis\arcexe82\bin\ArcMap.exe and click OK.
- Press F10/F11 to step through the code.
Note: When you step through the code and the debugger reaches a line that has a problem, it will not let you step over to the next line.