NullReferenceException while Initializing Database Object in C#

NullReferenceException while Initializing Database Object in C#

Anonymous
Not applicable
471 Views
3 Replies
Message 1 of 4

NullReferenceException while Initializing Database Object in C#

Anonymous
Not applicable
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());
}
}
0 Likes
472 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Your code looks correct to me, though I'm not sure about the "@" symbol in "oAutoCADDB.ReadDwgFile(@"D:\\Sample Files\09-03-0006-00.dwg", System.IO.FileShare.Read, false, "");". I would also think it would be a good idea to escape the second backslash.

At which line is the error generated?
If you comment out all other code would this work? :

Database oAutoCADDB; /*you do not need to set the object to null when you declare it*/
oAutoCADDB = new Database(false, true);
0 Likes
Message 3 of 4

Anonymous
Not applicable
Thanks for the Prompt Response.

I get an error at oAutoCADDB = new Database(false, true); itself. so i can't debug further to see if the code works.

I am running AutoCAD 2005. But i want to run this program as a Standalone Program using ObjectARX with no dependency of Invoking Heavy Weight AutoCAD 2005 UI Process. Righ now i am running the above mentioned code in a .NET Windows Forms Application for testing.

I thought ObjectARX is a Light Weight Alternative to build AutoCAD applications instead of using AutoCAD Software and Automation APIs. Is my statement Wrong?
0 Likes
Message 4 of 4

Anonymous
Not applicable
If you want to write a standalone application, you need to use ObjectDBX, to run ObjectARX programs you absolutely have to have AutoCAD running. ObjectARX API is a tool for customising AutoCAD, just like the API used in ADS, but is more powerful. Thus, you have to compile your project into a .dll, and load it in AutoCAD using the "netload" command.
With ObjectDBX you will not have to have AutoCAD present at all.
0 Likes