1

Testing my VB.NET 2010 app in ArcMap an exception occurs when ICommandBars is instantiated.

' zoom to selected
Dim mxApp As ESRI.ArcGIS.Framework.IApplication
Dim numUID As UID = New ESRI.ArcGIS.esriSystem.UID
numUID.Value = "{AB073B49-DE5E-11D1-AA80-00C04FA37860}"
Dim commandBars As ICommandBars = mxApp.Document.CommandBars   '>>> error here!!!!!!!!
Dim cmdItem As ICommandItem = CommandBars.Find(numUID, False, False)
If Not (cmdItem Is Nothing) Then
    cmdItem.Execute()
End If

Message: Exception first-chance type 'System.NullReferenceException' in LUCAS.dll.

P.S. ArcGIS 10 SP1 on Windows 7, VS2010.

5

You've declared mxApp, but you haven't actually set it to anything. If you're using an addin, you can set that with the line

mxApp = My.ArcMap.Application

| improve this answer | |
  • Great! You should mark the question as being answered. – kenbuja Jan 18 '12 at 16:09
  • +1 Also note accessing Document.Commandbars before the document has loaded (e.g. within IExtension.Startup) has been known to cause Arcmap to crash. Hopefully that is fixed, in which case it might now throw a null reference exception too. – Kirk Kuykendall Jan 18 '12 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.