<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: eAtMaxReaders on Database.Insert - objects not being closed? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7575477#M28814</link>
    <description>&lt;OL&gt;&lt;LI&gt;Oops, sorry!&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;&lt;LI&gt;Yes, but I read that the Transaction will handle the closing for me, correct? I need help understanding what is actually happening here. When I return an opened DBObject within a transaction, will the returned object be kept open? I assume this is the case, since it actually works. But why doesn't the using statement close the DBObject before it gets returned?&lt;/LI&gt;&lt;/OL&gt;</description>
    <pubDate>Mon, 27 Nov 2017 15:37:18 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-11-27T15:37:18Z</dc:date>
    <item>
      <title>eAtMaxReaders on Database.Insert - objects not being closed?</title>
      <link>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7574819#M28812</link>
      <description>&lt;P&gt;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:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;using (Database sourceDb = new Database(false, false))
{
    sourceDb.ReadDwgFile(sourceDwg, FileOpenMode.OpenForReadAndAllShare, true, "");
    return targetDb.Insert(blockName, sourceDb, false);
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seemingly at random, &lt;FONT face="courier new,courier"&gt;targetDb.Insert&lt;/FONT&gt; throws an &lt;EM&gt;eAtMaxReaders&lt;/EM&gt; 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 &lt;FONT face="courier new,courier"&gt;Database.Insert&lt;/FONT&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All around my code I am heavily relying on &lt;A href="https://github.com/luanshixia/AutoCADCodePack" target="_blank"&gt;AutoCADCodePack&lt;/A&gt;, which wraps read-only operations into this neat &lt;A href="https://github.com/luanshixia/AutoCADCodePack/blob/master/AutoCADCommands/QuickSelection.cs" target="_blank"&gt;little method&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static DBObject QOpenForRead(this ObjectId dboId, Database db)
{
    using (Transaction trans = db.TransactionManager.StartOpenCloseTransaction())
    {
        return trans.GetObject(dboId, OpenMode.ForRead);
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use this everywhere like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;var dbObj = objId.QOpenForWrite&amp;lt;DBObject&amp;gt;();

// various read operations on the DBObject&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Can the issue here be that the object is not being properly closed&amp;nbsp; 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 &lt;FONT face="courier new,courier"&gt;using&lt;/FONT&gt; statement before returning the object?&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 12:50:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7574819#M28812</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-11-27T12:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: eAtMaxReaders on Database.Insert - objects not being closed?</title>
      <link>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7574827#M28813</link>
      <description>&lt;P&gt;1. You select wrong forum. Right forum is &amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/net/bd-p/152" target="_blank"&gt;https://forums.autodesk.com/t5/net/bd-p/152&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;2. It looks like you forget to close an opened object. It is possible to open the object without closing only 255 times.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 12:57:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7574827#M28813</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2017-11-27T12:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: eAtMaxReaders on Database.Insert - objects not being closed?</title>
      <link>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7575477#M28814</link>
      <description>&lt;OL&gt;&lt;LI&gt;Oops, sorry!&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;&lt;LI&gt;Yes, but I read that the Transaction will handle the closing for me, correct? I need help understanding what is actually happening here. When I return an opened DBObject within a transaction, will the returned object be kept open? I assume this is the case, since it actually works. But why doesn't the using statement close the DBObject before it gets returned?&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Mon, 27 Nov 2017 15:37:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7575477#M28814</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-11-27T15:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: eAtMaxReaders on Database.Insert - objects not being closed?</title>
      <link>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7575678#M28815</link>
      <description>&lt;P&gt;The method you show below (QOpenForRead) returns a DBObject after aborting the transaction that it was opened with. The returned DBObject is closed when the transaction is aborted, so it's returning an already-closed DBObject. The fact that a closed DBObject may still be usable is not something you should rely on. Whatever 'code pack' you got that from you should probably not rely too heavily on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While it's&amp;nbsp;possible that the third argument to Insert() (preserveSourceDatabase) could have something to do with it, I suspect the issue may be somewhere else, in code you didn't include in your post. Try passing true for the third argument to Insert().&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;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:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;using (Database sourceDb = new Database(false, false))
{
    sourceDb.ReadDwgFile(sourceDwg, FileOpenMode.OpenForReadAndAllShare, true, "");
    return targetDb.Insert(blockName, sourceDb, false);
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seemingly at random, &lt;FONT face="courier new,courier"&gt;targetDb.Insert&lt;/FONT&gt; throws an &lt;EM&gt;eAtMaxReaders&lt;/EM&gt; 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 &lt;FONT face="courier new,courier"&gt;Database.Insert&lt;/FONT&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All around my code I am heavily relying on &lt;A href="https://github.com/luanshixia/AutoCADCodePack" target="_blank"&gt;AutoCADCodePack&lt;/A&gt;, which wraps read-only operations into this neat &lt;A href="https://github.com/luanshixia/AutoCADCodePack/blob/master/AutoCADCommands/QuickSelection.cs" target="_blank"&gt;little method&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public static DBObject QOpenForRead(this ObjectId dboId, Database db)
{
    using (Transaction trans = db.TransactionManager.StartOpenCloseTransaction())
    {
        return trans.GetObject(dboId, OpenMode.ForRead);
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use this everywhere like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;var dbObj = objId.QOpenForWrite&amp;lt;DBObject&amp;gt;();

// various read operations on the DBObject&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Can the issue here be that the object is not being properly closed&amp;nbsp; 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 &lt;FONT face="courier new,courier"&gt;using&lt;/FONT&gt; statement before returning the object?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2017 16:32:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7575678#M28815</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-11-27T16:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: eAtMaxReaders on Database.Insert - objects not being closed?</title>
      <link>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7582143#M28816</link>
      <description>&lt;P&gt;I changed the QOpenForRead to take an action parameter instead:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public static void QOpenForRead&amp;lt;T&amp;gt;(this ObjectId dboId, Action&amp;lt;T&amp;gt; action) where T : DBObject // newly 20130122
        {
            using (Transaction trans = dboId.Database.TransactionManager.StartOpenCloseTransaction())
            {
                action(trans.GetObject(dboId, OpenMode.ForRead) as T);
            }
        }&lt;/PRE&gt;&lt;P&gt;I changed my function calls accordingly, so now they all only read open objects. But the problem persists. I also tried setting the third parameter in the &lt;FONT face="courier new,courier"&gt;Database.Insert&lt;/FONT&gt; call to true, but no luck.&lt;BR /&gt;&lt;BR /&gt;Instead, I found another candidate. I copy properties from one block to another using these methods; for reading:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;        public static object GetBlockProperty(this ObjectId block, string name)
        {
            object value = null;
            block.QOpenForWrite&amp;lt;BlockReference&amp;gt;(br =&amp;gt;
            {
                DynamicBlockReferencePropertyCollection props = br.DynamicBlockReferencePropertyCollection;

                foreach (DynamicBlockReferenceProperty prop in props)
                    if (prop.PropertyName == name) {
                        value = prop.Value;
                        break;
                    }

            });

            return value;
        }&lt;/PRE&gt;&lt;P&gt;and exactly the same procedure for setting:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;        public static void SetBlockProperty(this ObjectId block, string name, object value)
        {
            block.QOpenForWrite&amp;lt;BlockReference&amp;gt;(br =&amp;gt;
            {
                DynamicBlockReferencePropertyCollection props = br.DynamicBlockReferencePropertyCollection;

                foreach (DynamicBlockReferenceProperty prop in props)
                    if (prop.PropertyName == name)
                    {
                        Debug.WriteLine("Setting block parameter " + name + "=" + value.ToString());
                        prop.Value = value;
                        break;
                    }

            });
        }&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;QOpenForWrite works just like QOpenForRead:&lt;/P&gt;&lt;PRE&gt;        public static void QOpenForWrite&amp;lt;T&amp;gt;(this ObjectId dboId, Action&amp;lt;T&amp;gt; action) where T : DBObject
        {
            using (Transaction trans = dboId.Database.TransactionManager.StartTransaction())
            {
                action(trans.GetObject(dboId, OpenMode.ForWrite) as T);
                trans.Commit();
            }
        }&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I copy one parameter value from one block to another like this:&lt;/P&gt;&lt;PRE&gt;var value = block1.GetBlockProperty("parameter");

block2.SetBlockProperty("parameter", value);&lt;/PRE&gt;&lt;P&gt;If &lt;FONT face="courier new,courier"&gt;DynamicBlockRefrenceProperty.Value&lt;/FONT&gt; returns a direct reference to the Value, we will end up with two blocks with parameters pointing to the same value. I can see how this can cause problems. But how would I proceed to copy the value instead? The &lt;FONT face="courier new,courier"&gt;Value&lt;/FONT&gt; is an&lt;FONT face="courier new,courier"&gt; object&lt;/FONT&gt;, which cannot be cloned. Any neat trick for this?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 13:55:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7582143#M28816</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-11-29T13:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: eAtMaxReaders on Database.Insert - objects not being closed?</title>
      <link>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7582791#M28817</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I copy one parameter value from one block to another like this:&lt;/P&gt;&lt;PRE&gt;var value = block1.GetBlockProperty("parameter");

block2.SetBlockProperty("parameter", value);&lt;/PRE&gt;&lt;P&gt;If &lt;FONT face="courier new,courier"&gt;DynamicBlockRefrenceProperty.Value&lt;/FONT&gt; returns a direct reference to the Value, we will end up with two blocks with parameters pointing to the same value. I can see how this can cause problems. But how would I proceed to copy the value instead? The &lt;FONT face="courier new,courier"&gt;Value&lt;/FONT&gt; is an&lt;FONT face="courier new,courier"&gt; object&lt;/FONT&gt;, which cannot be cloned. Any neat trick for this?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The value you pass when you set a dynamic block property's Value property is copied internally. AutoCAD doesn't store references to managed objects in its database, so that isn't an issue.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 16:52:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/eatmaxreaders-on-database-insert-objects-not-being-closed/m-p/7582791#M28817</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-11-29T16:52:52Z</dc:date>
    </item>
  </channel>
</rss>

