GetObject method of transaction class gives exception

eranUZA53
Participant
Participant

GetObject method of transaction class gives exception

eranUZA53
Participant
Participant

1. Draw line.
2. Save objectId of line to file.

3. Close document.
4. Open document
5. Load ObjectId from file
6. Try to get line object by this objectId
7. Get System.AccessViolationException: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

 

GetObject method of transaction class gives exception (that writed above) when I'm trying to access object after reopening drawing. That's all

  

Entity ent = Transaction.GetObject(id, OpenMode.ForWrite) as Entity;

System.AccessViolationException: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

any idea why?

0 Likes
Reply
403 Views
1 Reply
Reply (1)

Keith.Brown
Advisor
Advisor

ObjectId’s are reassigned everytime the drawing is loaded so you cannot save them off in this way.  Instead save the entity handle as it will persist across each session.  You can get the  objectId from the handle.

 

         

          long ln = Convert.ToInt64(handleAsString, 16);

          Handle hn = new Handle(ln);

          ObjectId id = db.GetObjectId(false,hn,0);