Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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

share|improve this answer
    
Thanks! Now it works. –  ALB Jan 18 '12 at 15:32
    
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
    
Thanks again to all! –  ALB Jan 19 '12 at 8:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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