Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (DocumentLock dl = doc.LockDocument())
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
string fullName = @"D:\1.dwg";
string name = Path.GetFileNameWithoutExtension(fullName);
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
ObjectId xRefId = db.AttachXref(fullName, name);//в этом месте ошибка eFileAccessErr
using (BlockReference blkRef = new BlockReference(Point3d.Origin, xRefId))
{
BlockTableRecord modelBtr = tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite) as BlockTableRecord;
modelBtr.AppendEntity(blkRef);
tr.AddNewlyCreatedDBObject(blkRef, true);
}
tr.Commit();
}
}