Author Topic: API Catastrophic Fail, No Reason -> Database tempDb = new Database(false, true);  (Read 1999 times)

0 Members and 1 Guest are viewing this topic.

tonofsteel

  • Guest
What I am using:
Windows 7 32 bit
AutoCAD 2012
Visual Studio 2010
ObjectARX .NET 2012 (Upgraded from 2011 when I started running into this error, and created new project with code below to ensure the most up to date files are being used)
.NET 4.0 (not client in build settings)

I am writing some software to automate some drawing processes based on information from a database and excel files.  I am finding that the AutoCAD .NET portion of the programming is taking about 99% of the design and troubleshooting time with its insane API and bizarre errors.  So I have narrowed my few thousand lines of code to one simple program, with only one line of code.  This is a completely stand alone project with nothing but the 2012 libraries referenced (copylocal is false) using the wizard.

Two questions that should not have to be asked in the first place: Why and how do I fix?  :realmad:

As far as the class goes I have tried every combination of static/non static and session flags with no difference on the result.

The error information:

tempDb = {Autodesk.AutoCAD.DatabaseServices.Database}
ApproxNumObjects = 'tempDb.ApproxNumObjects' threw an exception of type 'System.AccessViolationException'
base {System.SystemException} = {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}


Code: [Select]
// (C) Copyright 2011 by 
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(Test.MyCommands))]

namespace Test
{

    public class MyCommands
    {
        [CommandMethod("MyCommand")]
        public static void MyCommand()
        {
            Database tempDb = new Database(false, true);
        }
    }

}


TimBlanch

  • Guest
Try adding this to your acad.exe.config:

Code: [Select]
<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
</startup>

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>

Does the error only occur when you get the ApproxNumObjects property from an in memory Database that does not have a Document associated with it ??


Regards

ps:
welcome to theSwamp
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>

Can you confirm that the code you posted explodes ??

I can't see any reason why it should.

Regards
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>

I wouldn't be surprised if the problem IS related to there NOT being a Document associated with the Database.

As we can see from this debug listing of the propertys of tempDb the BlockTableID and others are also not available.

See the attached Piccy :
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

tonofsteel

  • Guest
Quote
I wouldn't be surprised if the problem IS related to there NOT being a Document associated with the Database.

Thanks for looking into this and after figuring out what the problem really was you are right and the above is the case.  This line was throwing exceptions but eventually when I went to open the dwg file I was trying to load programatically with autocad directly it told me the header was corrupt.  Made a new file and then everything worked.