i am getting a System.InvalidProgramException

i am getting a System.InvalidProgramException

Anonymous
Not applicable
2,029 Views
2 Replies
Message 1 of 3

i am getting a System.InvalidProgramException

Anonymous
Not applicable

I’m actually getting an error

System.InvalidProgramException occurred

  HResult=   0x8013153A Common Language Runtime detected an invalid program.

  Source=<Cannot evaluate the exception source>

  StackTrace: at Autodesk.AutoCAD.DatabaseServices.Database.get_TransactionManager()

 

While running this below piece of code

 

                    Database sourceDb = new Database(false, true); //Temporary database to hold data for block we want to import

                    try

                    {

                        sourceDb.ReadDwgFile(dwgPath, System.IO.FileShare.Read, true, ""); //Read the DWG into a side database

                        ObjectIdCollection blockIds = new ObjectIdCollection(); // Create a variable to store the list of block identifiers

 

                        Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sourceDb.TransactionManager; using (Transaction myT = tm.StartTransaction())

                        {

                            // Open the block table

                            BlockTable bt = (BlockTable)tm.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, false);

 

                            // Check each block in the block table

                            foreach (ObjectId btrId in bt)

                            {

                                BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId, OpenMode.ForRead, false);

                                // Only add named & non-layout blocks to the copy list

                                if (!btr.IsAnonymous && !btr.IsLayout)

                                {

                                    blockIds.Add(btrId);

                                }

                                btr.Dispose();

                            }

                        }

                        // Copy blocks from source to destination database

                        //IdMapping mapping = new IdMapping(); sourceDb.WblockCloneObjects(blockIds, _database.BlockTableId, mapping, DuplicateRecordCloning.Replace, false); _editor.WriteMessage("\nCopied " + blockIds.Count.ToString() + " block definitions from " + blockToImport + " to the current drawing.");

  }

0 Likes
Accepted solutions (1)
2,030 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

From your other posts, it seems you're trying to directly use the AutoCAD .NET API from a standalone executable.

Read this topic about out-of-process vs in-process applications.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

vsraman85
Explorer
Explorer

Hi, any solution for this? How to resolve this issue? I am also having the same issue

0 Likes