Object reference not set to an instance of an object.

1654
2
02-08-2011 03:40 PM
Gautham_SChejarla
New Contributor
Hi All,

I am using C# for ArcObjects desktop. Kindly clarify me on the below to declarations

1.   IApplicatin app = IMxDocument.doc as IApplication;
      ----
-------
throws an exception (NUllReferenceException) when i use
app.OpenDocument(filename)------ where filename is a string in the openFileDialog1

2.    IApplication app = (IMxDocument.doc as IDocument).Parent
---
---
This does not throw an exception. My doubt is why does the first option throw an error while second option does not even though both IApplication & IDocument.Parent both refer to Application.

Thanks a lot in advance...!
0 Kudos
2 Replies
SteveFang
New Contributor III
IMxDocument is not the same as IApplication, they are in two different co-classes.  The document is derived from the application so you can't cast a document as application but you can cast the parent of the document as application because the parent of a document is the application.  Hopefully that explanation helps.
0 Kudos
Gautham_SChejarla
New Contributor
IMxDocument is not the same as IApplication, they are in two different co-classes.  The document is derived from the application so you can't cast a document as application but you can cast the parent of the document as application because the parent of a document is the application.  Hopefully that explanation helps.


Thanks a lot....
0 Kudos