eAtMaxReaders on Database.Insert - objects not being closed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am automating an operation in which lots of block-DWG's (created using WBLOCK) is inserted into another drawing. I read the block-DWG and insert it into the BlockTable:
using (Database sourceDb = new Database(false, false))
{
sourceDb.ReadDwgFile(sourceDwg, FileOpenMode.OpenForReadAndAllShare, true, "");
return targetDb.Insert(blockName, sourceDb, false);
}
Seemingly at random, targetDb.Insert throws an eAtMaxReaders exception. I have figured out that I am probably opening an object more than 255 times, but which object can it possibly be that is being opened from Database.Insert?
All around my code I am heavily relying on AutoCADCodePack, which wraps read-only operations into this neat little method:
public static DBObject QOpenForRead(this ObjectId dboId, Database db)
{
using (Transaction trans = db.TransactionManager.StartOpenCloseTransaction())
{
return trans.GetObject(dboId, OpenMode.ForRead);
}
}
I use this everywhere like this:
var dbObj = objId.QOpenForWrite<DBObject>(); // various read operations on the DBObject
Can the issue here be that the object is not being properly closed using this method? I am not getting the hang of how this can even work; wouldn't all opened objects within a transaction get closed and disposed by the using statement before returning the object?

