Message 1 of 4
NullReferenceException while Initializing Database Object in C#
Not applicable
10-19-2004
09:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to read the Document Properties.
I get "System.NullReferenceException : Object reference not set to an instance of an object" error when i create a new instance of Database class.
oAutoCADDB = new Database(false, true);
I would really appreciate if anyone can help me my mistakes here?
private void DisplayProperties()
{
Database oAutoCADDB = null;
try
{
oAutoCADDB = new Database(false, true);
oAutoCADDB.ReadDwgFile(@"D:\\Sample Files\09-03-0006-00.dwg", System.IO.FileShare.Read, false, "");
MessageBox.Show("LastSavedAsVersion:" + oAutoCADDB.LastSavedAsVersion.ToString());
DatabaseSummaryInfo oDBSummaryInfo = oAutoCADDB.SummaryInfo;
MessageBox.Show("Author:" + oDBSummaryInfo.Author);
MessageBox.Show("Comments:" + oDBSummaryInfo.Comments);
MessageBox.Show("Keywords:" + oDBSummaryInfo.Keywords);
MessageBox.Show("LastSavedBy:" + oDBSummaryInfo.LastSavedBy);
MessageBox.Show("RevisionNumber:" + oDBSummaryInfo.RevisionNumber);
MessageBox.Show("Subject:" + oDBSummaryInfo.Subject);
MessageBox.Show("Title:" + oDBSummaryInfo.Title);
MessageBox.Show("HyperlinkBase:" + oDBSummaryInfo.HyperlinkBase);
StringDictionary oStrDictionary = oDBSummaryInfo.CustomProperties;
foreach ( DictionaryEntry de in oStrDictionary)
MessageBox.Show("" + de.Key + ":" + de.Value);
oAutoCADDB.CloseInput(true);
}
catch(Exception ex)
{
if(oAutoCADDB != null)oAutoCADDB.CloseInput(true);
MessageBox.Show(ex.ToString());
}
}
I get "System.NullReferenceException : Object reference not set to an instance of an object" error when i create a new instance of Database class.
oAutoCADDB = new Database(false, true);
I would really appreciate if anyone can help me my mistakes here?
private void DisplayProperties()
{
Database oAutoCADDB = null;
try
{
oAutoCADDB = new Database(false, true);
oAutoCADDB.ReadDwgFile(@"D:\\Sample Files\09-03-0006-00.dwg", System.IO.FileShare.Read, false, "");
MessageBox.Show("LastSavedAsVersion:" + oAutoCADDB.LastSavedAsVersion.ToString());
DatabaseSummaryInfo oDBSummaryInfo = oAutoCADDB.SummaryInfo;
MessageBox.Show("Author:" + oDBSummaryInfo.Author);
MessageBox.Show("Comments:" + oDBSummaryInfo.Comments);
MessageBox.Show("Keywords:" + oDBSummaryInfo.Keywords);
MessageBox.Show("LastSavedBy:" + oDBSummaryInfo.LastSavedBy);
MessageBox.Show("RevisionNumber:" + oDBSummaryInfo.RevisionNumber);
MessageBox.Show("Subject:" + oDBSummaryInfo.Subject);
MessageBox.Show("Title:" + oDBSummaryInfo.Title);
MessageBox.Show("HyperlinkBase:" + oDBSummaryInfo.HyperlinkBase);
StringDictionary oStrDictionary = oDBSummaryInfo.CustomProperties;
foreach ( DictionaryEntry de in oStrDictionary)
MessageBox.Show("" + de.Key + ":" + de.Value);
oAutoCADDB.CloseInput(true);
}
catch(Exception ex)
{
if(oAutoCADDB != null)oAutoCADDB.CloseInput(true);
MessageBox.Show(ex.ToString());
}
}