<?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: Geoprocessing Async Error in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1278348#M9666</link>
    <description>&lt;P&gt;Your code snippet has a problem, this line doesn't make much sense when GPRun returns void, plus a closing ')' is missing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var Agg_para = Geoprocessing.MakeValueArray(intersectFC, intersectSortFC, GPRun("management.Sort", Agg_para, null,null,outputOnMapNone);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i would suggest setting a breakpoint before you call&amp;nbsp;Geoprocessing.ExecuteToolAsync and inspect the content of the parameters array to make sure the content looks correct.&amp;nbsp; If you run the same GP tool manually you can look at the corresponding python command to get the proper parameter sequence for the input parameters array.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2023 16:31:03 GMT</pubDate>
    <dc:creator>Wolf</dc:creator>
    <dc:date>2023-04-13T16:31:03Z</dc:date>
    <item>
      <title>Geoprocessing Async Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1278076#M9658</link>
      <description>&lt;P&gt;I am trying to run a few geoprocessing methods in the sequence they occur. It works fine if I just keep it simple, but I want to add some additional parameters, such as environment and GPExecuteToolFlags. There is an errors that states the "Object reference is not set to an instance of an object."&amp;nbsp; Please see my code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var in_features = new List&amp;lt;FeatureLayer&amp;gt;() { FC_Layer1, Layer2 };
var args = Geoprocessing.MakeValueArray(in_features, intersectFC);
GPExecuteToolFlags outputOnMapNone = GPExecuteToolFlags.None;
GPRun("analysis.Intersect", args,null,null,outputOnMapNone);

                        
var Agg_para = Geoprocessing.MakeValueArray(intersectFC, intersectSortFC, GPRun("management.Sort", Agg_para, null,null,outputOnMapNone);

                        
var in_features2 = new List&amp;lt;FeatureLayer&amp;gt;() { FCLayer, Layer2 };
var args2 = Geoprocessing.MakeValueArray(in_features2, layer);
GPExecuteToolFlags flag = GPExecuteToolFlags.GPThread;
GPRun("analysis.Intersect", args2,null,null,flag);

public async void GPRun(string GPTool, IReadOnlyList&amp;lt;string&amp;gt; parameters, IEnumerable&amp;lt;KeyValuePair&amp;lt;string, string&amp;gt;&amp;gt; env,CancelableProgressor prog,GPExecuteToolFlags flag)
{
   var gp_result = await Geoprocessing.ExecuteToolAsync(GPTool, parameters, env, prog, flag);
   Geoprocessing.ShowMessageBox(gp_result.Messages, "Geoprocessing Error 
      Messages",gp_result.IsFailed ? GPMessageBoxStyle.Error : 
      GPMessageBoxStyle.Default);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 17:01:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1278076#M9658</guid>
      <dc:creator>tzz_12</dc:creator>
      <dc:date>2023-04-13T17:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing Async Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1278119#M9661</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I think problem with line:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var Agg_para = Geoprocessing.MakeValueArray(intersectFC, intersectSortFC, GPRun("management.Sort", Agg_para, null,null,outputOnMapNone);&lt;/LI-CODE&gt;&lt;P&gt;You use Agg_para parameter without initialization in running management.Sort tool&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 06:29:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1278119#M9661</guid>
      <dc:creator>GKmieliauskas</dc:creator>
      <dc:date>2023-04-13T06:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing Async Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1278348#M9666</link>
      <description>&lt;P&gt;Your code snippet has a problem, this line doesn't make much sense when GPRun returns void, plus a closing ')' is missing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var Agg_para = Geoprocessing.MakeValueArray(intersectFC, intersectSortFC, GPRun("management.Sort", Agg_para, null,null,outputOnMapNone);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i would suggest setting a breakpoint before you call&amp;nbsp;Geoprocessing.ExecuteToolAsync and inspect the content of the parameters array to make sure the content looks correct.&amp;nbsp; If you run the same GP tool manually you can look at the corresponding python command to get the proper parameter sequence for the input parameters array.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 16:31:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1278348#M9666</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2023-04-13T16:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing Async Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1278385#M9668</link>
      <description>&lt;P&gt;Hi Wolf,&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I copy and paste the code into the post, I had to fix the formatting of the code, and&amp;nbsp; I accidently deleted some parts of the code by accident. Here is the code for the sort geoprocessing method below. The error, "NullReferenceException:&amp;nbsp;&lt;SPAN&gt;Object reference is not set to an instance of an object.",&lt;/SPAN&gt;&amp;nbsp;occurred in the GPRun method, when it calls the Geoprocessing.ExecuteToolAsync.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var Agg_para = Geoprocessing.MakeValueArray(intersectFC, intersectSortFC, AggregateField);
utility.GPRun("management.Sort", Agg_para);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 17:12:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1278385#M9668</guid>
      <dc:creator>tzz_12</dc:creator>
      <dc:date>2023-04-13T17:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Geoprocessing Async Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1283504#M9743</link>
      <description>&lt;P&gt;Sorry about the delay.&amp;nbsp; I noticed a problem with the variation of "&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic9385.html" target="_self"&gt;Geoprocessing.ExecuteToolAsync&lt;/A&gt;" that you are using.&amp;nbsp; It turns out that the 'progressor' parameter cannot be null.&lt;/P&gt;&lt;P&gt;You can create a Progressor using this snippet:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;CancelableProgressorSource cps = new CancelableProgressorSource("Run GP", "Canceled");
var progressor = cps.Progressor;&lt;/LI-CODE&gt;&lt;P&gt;This variation of your code worked for me:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected async override void OnClick()
{
  try
  {
    var intersectInputLyr1 = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().Where(fl =&amp;gt; fl.Name.Equals("TestPolygons")).FirstOrDefault();
    var intersectInputLyr2 = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().Where(fl =&amp;gt; fl.Name.Equals("TestLines")).FirstOrDefault();
    var intersectOutputFC = System.IO.Path.Combine(Project.Current.DefaultGeodatabasePath, "IntersectFc");
    var intersectOutputSortFC = System.IO.Path.Combine(Project.Current.DefaultGeodatabasePath, "IntersectSortFc");
    var AggregateField = "Description";
    CancelableProgressorSource cps = new CancelableProgressorSource("Run GP", "Canceled");
    var in_features = new List&amp;lt;FeatureLayer&amp;gt;() { intersectInputLyr1, intersectInputLyr2 };
    var argsSortedIntersect = Geoprocessing.MakeValueArray(in_features,
      intersectOutputFC,
      "ALL",//join_attributes = "ALL",
      null,//cluster_tolerance = None,
      "INPUT"//output_type = "INPUT"
    );
    GPExecuteToolFlags noMapOutput = GPExecuteToolFlags.None;
    // set overwrite flag           
    var env = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);

    await GPRun("analysis.Intersect", argsSortedIntersect, env, cps.Progressor, noMapOutput);

    var Agg_para = Geoprocessing.MakeValueArray(intersectOutputFC, intersectOutputSortFC, AggregateField);
    await GPRun("management.Sort", Agg_para, env, cps.Progressor);

    var intersectInputLyr3 = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().Where(fl =&amp;gt; fl.Name.Equals("TestPoints")).FirstOrDefault();
    var intersectOutputFc2 = System.IO.Path.Combine(Project.Current.DefaultGeodatabasePath, "IntersectPointFc");

    var in_features2 = new List&amp;lt;FeatureLayer&amp;gt;() { intersectInputLyr3, intersectInputLyr2 };
    var argsIntersect2 = Geoprocessing.MakeValueArray(in_features2, intersectOutputFc2);
    GPExecuteToolFlags flag = GPExecuteToolFlags.GPThread;
    await GPRun("analysis.Intersect", argsIntersect2, env, cps.Progressor, flag);
  }
  catch (Exception ex)
  {
    MessageBox.Show($@"Exception: {ex.ToString()}");
  }
}

public async Task GPRun(string GPTool, 
  IReadOnlyList&amp;lt;string&amp;gt; parameters, 
  IEnumerable&amp;lt;KeyValuePair&amp;lt;string, string&amp;gt;&amp;gt; env = null,
  CancelableProgressor prog = null,
  GPExecuteToolFlags flag = GPExecuteToolFlags.Default)
{
  try
  {
    var gp_result = await Geoprocessing.ExecuteToolAsync(GPTool, parameters, env, prog, flag);
    if (gp_result != null) Geoprocessing.ShowMessageBox(gp_result.Messages, "Geoprocessing Result",
      gp_result.IsFailed ? GPMessageBoxStyle.Error :
        GPMessageBoxStyle.Default);
  }
  catch
  {
    var gp_result = await Geoprocessing.OpenToolDialogAsync(GPTool, parameters, env);
    if (gp_result != null) Geoprocessing.ShowMessageBox(gp_result.Messages, "Geoprocessing Result",
      gp_result.IsFailed ? GPMessageBoxStyle.Error :
        GPMessageBoxStyle.Default);
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 17:52:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/geoprocessing-async-error/m-p/1283504#M9743</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2023-04-27T17:52:35Z</dc:date>
    </item>
  </channel>
</rss>

