<?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: Running geoprocessing tool using memory feature class works the first time, but fails the next time in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1247862#M9281</link>
    <description>&lt;P&gt;Yes it did. I was waiting to accept the answer before getting clarification on this. What would be the proper code for 3.0.x?&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jan 2023 22:09:18 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2023-01-12T22:09:18Z</dc:date>
    <item>
      <title>Running geoprocessing tool using memory feature class works the first time, but fails the next time</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1242529#M9199</link>
      <description>&lt;P&gt;In my add-in, I'm creating random points using a constraining feature class with the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/create-random-points.htm" target="_self"&gt;Create Random Points&lt;/A&gt; tool. However, since the tool creates the number of points for each feature in the constraining feature class, I first dissolve the feature class and use that as the constraining feature class. I use a temporary file name for the dissolved feature class and delete it after creating the points.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private Geodatabase MemoryGeodatabase; //set elsewhere
private SchemaBuilder MemorySchemaBuilder; //set elsewhere

MemoryConnectionProperties memoryConnectionProperties = new();
string tempFileName = Path.GetFileNameWithoutExtension(Path.GetTempFileName());
using (MemoryGeodatabase ??= SchemaBuilder.CreateGeodatabase(memoryConnectionProperties))
{
  MemorySchemaBuilder ??= new(MemoryGeodatabase);
  StatusMessage = $"Dissolving {SelectedFrameFeatureLayer.Name}...";
  IGPResult dissolveResult = await DissolveFeatures(frameFeatureClass, "", "", $"memory\\{tempFileName}", GPExecuteToolFlags.AddToHistory);
  if (dissolveResult.IsFailed)
  {
    Show_Status_Bar = false;
    StatusMessage = "";
    MessageBox.Show("Dissolving feature class failed");
    return;
  }
  using (FeatureClass dissolveFC = MemoryGeodatabase.OpenDataset&amp;lt;FeatureClass&amp;gt;(tempFileName))
  {
    string Distance = "";
    if (Use_Minimum_Distance &amp;amp;&amp;amp; Minimum_Distance &amp;gt; 0) Distance = $"{Minimum_Distance} {SR.Unit.ToString().ToLower()}";
    StatusMessage = "Generating points...";
    IGPResult CreateRandomPointsResult = await CreateRandomPoints($"memory\\{tempFileName}", Path.GetDirectoryName(outputFileName), Path.GetFileName(outputFileName), SimpleRandomCount, Distance, GPExecuteToolFlags.AddOutputsToMap);

    FeatureClassDescription DissolveFCDescription = new(dissolveFC.GetDefinition());
    MemorySchemaBuilder.Delete(DissolveFCDescription);
    MemorySchemaBuilder.Build();
  }
}&lt;/LI-CODE&gt;&lt;P&gt;This runs properly the first time, but if I run it again, it throws an error on line 16 when it gets the temporary layer. The layer is created according to the history, but I get the error&lt;/P&gt;&lt;P&gt;&amp;nbsp;"Could not open the dataset 'tmp5EB3' of type FeatureClass. Please make sure a valid geodatabase or data store has been opened first."&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dissolve.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/58916iAA545241ACC34BEA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dissolve.png" alt="dissolve.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Why isn't this working on the second attempt?&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2022 21:11:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1242529#M9199</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-12-19T21:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Running geoprocessing tool using memory feature class works the first time, but fails the next time</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1243861#M9207</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/2839"&gt;@KenBuja&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot replicate the issue on my machine, and the following code snippets work for me. See if it works for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;    protected override void OnClick()
    {
      QueuedTask.Run(async () =&amp;gt;
      {
        MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties();
        using (Geodatabase memoryGeodatabase = new Geodatabase(memoryConnectionProperties))
        {
          SchemaBuilder schemaBuilder = new SchemaBuilder(memoryGeodatabase);

          IReadOnlyList&amp;lt;string&amp;gt; dissolveParamsValueArray = Geoprocessing.MakeValueArray(@"C:\Default.gdb\FrameFeatureClass", @"memory\FrameFeatureClass_Dissolved", null, null, "MULTI_PART", "DISSOLVE_LINES", null);
          IGPResult dissolveResult = await Geoprocessing.ExecuteToolAsync("management.Dissolve", dissolveParamsValueArray, null, CancelableProgressor.None, GPExecuteToolFlags.AddToHistory);

          if (dissolveResult.IsFailed)
          {
            System.Diagnostics.Debug.WriteLine("Dissolve errors");
          }

          using (FeatureClass dissolveFc = memoryGeodatabase.OpenDataset&amp;lt;FeatureClass&amp;gt;("FrameFeatureClass_Dissolved"))
          using (FeatureClassDefinition dissolveDefn = dissolveFc.GetDefinition())
          {
            IReadOnlyList&amp;lt;string&amp;gt; createPointsParamsValueArray = Geoprocessing.MakeValueArray(@"memory", "RandomPointsFC", @"memory\FrameFeatureClass_Dissolved", new List&amp;lt;dynamic&amp;gt;() { 0, 0, 250, 250 }, 100, "5 Meters", "POINT", 10);
            IGPResult createRandomPointsMessage = await Geoprocessing.ExecuteToolAsync("management.CreateRandomPoints", createPointsParamsValueArray, null, CancelableProgressor.None, GPExecuteToolFlags.AddOutputsToMap);

            if (createRandomPointsMessage.IsFailed)
            {
              System.Diagnostics.Debug.WriteLine("Create random points errors");
            }

            schemaBuilder.Delete(new FeatureClassDescription(dissolveDefn));
            bool deleteStatus = schemaBuilder.Build();
            if (!deleteStatus)
            {
              System.Diagnostics.Debug.WriteLine("Delete feature class failed");
            }
          }
        }
      });
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Dec 2022 20:01:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1243861#M9207</guid>
      <dc:creator>Aashis</dc:creator>
      <dc:date>2022-12-27T20:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: Running geoprocessing tool using memory feature class works the first time, but fails the next time</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1247757#M9277</link>
      <description>&lt;P&gt;I tried using this code in my add-in, but could not use it as-is. I would get this error on line 6 of your snippet.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="error.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60309iADA81ED0EECC72F5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="error.png" alt="error.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In order to make this work, I had to add in a line (line 2) from my code to create another MemoryGeodatabase:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties();
using (MemoryGeodatabase ??= SchemaBuilder.CreateGeodatabase(memoryConnectionProperties))
using (Geodatabase memoryGeodatabase = new Geodatabase(memoryConnectionProperties))
{
  SchemaBuilder schemaBuilder = new SchemaBuilder(memoryGeodatabase);&lt;/LI-CODE&gt;&lt;P&gt;I'm curious about how you were able to get this to work in your application and why I have to add in the additional line.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 19:38:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1247757#M9277</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-01-12T19:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Running geoprocessing tool using memory feature class works the first time, but fails the next time</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1247837#M9280</link>
      <description>&lt;P&gt;Good catch; that was the enhancement in 3.1. I was testing on the 3.1 beta and forgot to revert the code.&lt;/P&gt;&lt;P&gt;BTW, did the GP workflow run successfully after your change?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 21:18:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1247837#M9280</guid>
      <dc:creator>Aashis</dc:creator>
      <dc:date>2023-01-12T21:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Running geoprocessing tool using memory feature class works the first time, but fails the next time</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1247862#M9281</link>
      <description>&lt;P&gt;Yes it did. I was waiting to accept the answer before getting clarification on this. What would be the proper code for 3.0.x?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 22:09:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1247862#M9281</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-01-12T22:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Running geoprocessing tool using memory feature class works the first time, but fails the next time</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1248059#M9282</link>
      <description>&lt;P&gt;Creating a memory geodatabase and connecting to it in two steps, as&amp;nbsp;you did, is the preferred way for 3.0.x.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 15:10:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/running-geoprocessing-tool-using-memory-feature/m-p/1248059#M9282</guid>
      <dc:creator>Aashis</dc:creator>
      <dc:date>2023-01-13T15:10:09Z</dc:date>
    </item>
  </channel>
</rss>

