<?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: System.AccessViolationException using C# in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197099#M5143</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Can you provide details on how many features get added or updated before you get this error? Also are you using recycling cursor or non-recycling cursor?&lt;BR /&gt;&lt;BR /&gt;Try releasing cursor after 40,000 or 50,000 iterations and see if that makes any difference.&lt;BR /&gt;&lt;BR /&gt;Cheers!!&lt;BR /&gt;&lt;BR /&gt;Sumit&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for answering.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried that in other situations, and it helped. But not here. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Only a few hundred features are inserted before the crash. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I will reexamine cursor usage. See also example code in above answer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Jun 2012 06:30:14 GMT</pubDate>
    <dc:creator>OlaRennemo</dc:creator>
    <dc:date>2012-06-06T06:30:14Z</dc:date>
    <item>
      <title>System.AccessViolationException using C#</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197095#M5139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am developing a toolbar for ArcMap with C#, which can import features from external geodatabases.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For each feature to import, receiving featureclass is searched for existing values using objectid and cursors. (Cursors are closed using "Marshal.ReleaseComObject(cur);" after use.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and the feature is inserted if needed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This seems to work well as long as the receiving featureclass holds a small number of features, but when the number grows (ex. 100.000), I get a System.AccessViolationException after e few hundred inserts.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks as if the exception is thrown during FeatureClass.CreateFeature. But it is difficult to examine in the debugger, since it looks as if there is no specific number of inserts before the crash occurs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using GDB file geodatabase for storage.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ArcMap 10.0 SP3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;VisualStudio 2010 SP1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Win7-64&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Have a missed some limitations here? Any known bugs? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;TIA&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ola&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2012 08:25:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197095#M5139</guid>
      <dc:creator>OlaRennemo</dc:creator>
      <dc:date>2012-06-05T08:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: System.AccessViolationException using C#</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197096#M5140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can you post the code for import features? Also, Did you monitor the memory usage in taskmgr while running insert features?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2012 13:55:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197096#M5140</guid>
      <dc:creator>sapnas</dc:creator>
      <dc:date>2012-06-05T13:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: System.AccessViolationException using C#</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197097#M5141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can you provide details on how many features get added or updated before you get this error? Also are you using recycling cursor or non-recycling cursor?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try releasing cursor after 40,000 or 50,000 iterations and see if that makes any difference.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sumit&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2012 20:02:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197097#M5141</guid>
      <dc:creator>SumitSharma</dc:creator>
      <dc:date>2012-06-05T20:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: System.AccessViolationException using C#</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197098#M5142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Can you post the code for import features? Also, Did you monitor the memory usage in taskmgr while running insert features?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Memory usage seem to be normal, with plenty left.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is unpractical to post the entire routine (many layers), but to give an idea of what is going on, here is the main operations:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;//
// Initiate:
IFeatureclass fcSource = ..
IFeatureClass fcTarget = ...
IWorspaceEdit wsTarget = ...
List sourceIdList = ...
//
// Start transaction:
wsTarget.StartEditing(false);
wsTarget.StartEditOperation();
//
// Do import:
foreach(int sourceOid in sourceIdList)
{ 
 IFeature fSource = fcSource.GetFeature(sourceOid);
 ...
 int a = fSource.get_value(..);
 int b = fSource.get_value(...); 
 //
 // Examine values in target fc if necessary:
 if(boundsHaveChanged)
 {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String whereRestriction = "(a&amp;gt;"+a.ToString() + ") and (b&amp;lt;"+b.ToString()+")";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IQueryFilter qf = new QueryFilterClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; qf.WhereClause = whereRestriction;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; qf.AddField(fieldName);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IFeatureCursor fcur = fl.FeatureClass.Search(qf, false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDataStatistics dstat = new DataStatisticsClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dstat.Cursor = (ICursor)fcur;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dstat.Field = fieldName;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IStatisticsResults res = dstat.Statistics;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int maxFound = System.Convert.ToInt32(res.Maximum);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Marshal.ReleaseComObject(fcur);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Marshal.ReleaseComObject(dstat);
 }
 
 IFeature fTargetNew = fcTarget.CreateFeature();
 IPoint p = new PointClass();
 ...
 fTargetNew.Shape = p;
 ...&amp;nbsp; 
 fTargetNew.set_value(i, f.get_value(j) );
 ...
 fTargetNew.Store();
}
wsTarget.StopEditOperation();
wsTarget.StopEditing(true);
...
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:50:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197098#M5142</guid>
      <dc:creator>OlaRennemo</dc:creator>
      <dc:date>2021-12-11T09:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: System.AccessViolationException using C#</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197099#M5143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Can you provide details on how many features get added or updated before you get this error? Also are you using recycling cursor or non-recycling cursor?&lt;BR /&gt;&lt;BR /&gt;Try releasing cursor after 40,000 or 50,000 iterations and see if that makes any difference.&lt;BR /&gt;&lt;BR /&gt;Cheers!!&lt;BR /&gt;&lt;BR /&gt;Sumit&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for answering.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have tried that in other situations, and it helped. But not here. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Only a few hundred features are inserted before the crash. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I will reexamine cursor usage. See also example code in above answer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2012 06:30:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197099#M5143</guid>
      <dc:creator>OlaRennemo</dc:creator>
      <dc:date>2012-06-06T06:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: System.AccessViolationException using C#</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197100#M5144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should release the feature objects you're using inside the loop in each loop iteration.&amp;nbsp; The ones I see are fSource, fTargetNew and f (at least it looks like f is a feature object).&amp;nbsp; Call ReleaseComObject on these feature objects inside the loop just as soon as you're done with them just like you do for cursor objects.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2012 12:36:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197100#M5144</guid>
      <dc:creator>NeilClemmons</dc:creator>
      <dc:date>2012-06-06T12:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: System.AccessViolationException using C#</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197101#M5145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You should release the feature objects you're using inside the loop in each loop iteration.&amp;nbsp; The ones I see are fSource, fTargetNew and f (at least it looks like f is a feature object).&amp;nbsp; Call ReleaseComObject on these feature objects inside the loop just as soon as you're done with them just like you do for cursor objects.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have done that, but unfortunately the problem is still there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a feeling that there is a fundamental error here that I have overlooked...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jun 2012 11:46:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/system-accessviolationexception-using-c/m-p/197101#M5145</guid>
      <dc:creator>OlaRennemo</dc:creator>
      <dc:date>2012-06-07T11:46:14Z</dc:date>
    </item>
  </channel>
</rss>

