<?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 Argument error: Converting from Task to string in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/argument-error-converting-from-task-to-string/m-p/1147416#M7835</link>
    <description>&lt;P&gt;I am not sure why I keep getting the conversion error that states, "Cannot convert from 'System.Threading.Task.Task&amp;lt;string&amp;gt; to string" when I tried to return a list of string values as a argument parameter for another method. Please see my script below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Looking up a list of string values, mukeys&amp;nbsp;&lt;/P&gt;&lt;P&gt;public async Task&amp;lt;List&amp;lt;string&amp;gt;&amp;gt; LookupMukey()&lt;BR /&gt;{&lt;BR /&gt;var mukeys = new List&amp;lt;string&amp;gt;();&lt;BR /&gt;var MV = MapView.Active;&lt;BR /&gt;int mukeyCount = 0;&lt;BR /&gt;var SelectionLayer = MV.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().Where(fl =&amp;gt; fl.Name.Contains("SelectionLayer")).FirstOrDefault();&lt;/P&gt;&lt;P&gt;await QueuedTask.Run(() =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;using (var SelectionTable = SelectionLayer.GetTable())&lt;BR /&gt;{&lt;BR /&gt;using (var rowCursor = SelectionTable.Search())&lt;BR /&gt;{&lt;BR /&gt;while (rowCursor.MoveNext())&lt;BR /&gt;{&lt;BR /&gt;using (Row row = rowCursor.Current)&lt;BR /&gt;{&lt;BR /&gt;var mukey = Convert.ToString(row["mukey"]);&lt;BR /&gt;mukeys.Add(mukey);&lt;BR /&gt;mukeyCount++;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;});&lt;BR /&gt;return mukeys;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//calling the list of mukeys&amp;nbsp; and outputting the values into a text file (performed by the function, //OutputTextFiles() )&lt;/P&gt;&lt;P&gt;Utilities helperclass = new Utilities();&lt;BR /&gt;var strOutput = helperclass.LookupMukey();&lt;BR /&gt;helperclass.OutputTextFiles(strOutput, "TestFile");&amp;nbsp; &amp;nbsp; //error occurs at strOutput&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Feb 2022 06:40:55 GMT</pubDate>
    <dc:creator>tzz_12</dc:creator>
    <dc:date>2022-02-24T06:40:55Z</dc:date>
    <item>
      <title>Argument error: Converting from Task to string</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/argument-error-converting-from-task-to-string/m-p/1147416#M7835</link>
      <description>&lt;P&gt;I am not sure why I keep getting the conversion error that states, "Cannot convert from 'System.Threading.Task.Task&amp;lt;string&amp;gt; to string" when I tried to return a list of string values as a argument parameter for another method. Please see my script below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Looking up a list of string values, mukeys&amp;nbsp;&lt;/P&gt;&lt;P&gt;public async Task&amp;lt;List&amp;lt;string&amp;gt;&amp;gt; LookupMukey()&lt;BR /&gt;{&lt;BR /&gt;var mukeys = new List&amp;lt;string&amp;gt;();&lt;BR /&gt;var MV = MapView.Active;&lt;BR /&gt;int mukeyCount = 0;&lt;BR /&gt;var SelectionLayer = MV.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().Where(fl =&amp;gt; fl.Name.Contains("SelectionLayer")).FirstOrDefault();&lt;/P&gt;&lt;P&gt;await QueuedTask.Run(() =&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;using (var SelectionTable = SelectionLayer.GetTable())&lt;BR /&gt;{&lt;BR /&gt;using (var rowCursor = SelectionTable.Search())&lt;BR /&gt;{&lt;BR /&gt;while (rowCursor.MoveNext())&lt;BR /&gt;{&lt;BR /&gt;using (Row row = rowCursor.Current)&lt;BR /&gt;{&lt;BR /&gt;var mukey = Convert.ToString(row["mukey"]);&lt;BR /&gt;mukeys.Add(mukey);&lt;BR /&gt;mukeyCount++;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;});&lt;BR /&gt;return mukeys;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//calling the list of mukeys&amp;nbsp; and outputting the values into a text file (performed by the function, //OutputTextFiles() )&lt;/P&gt;&lt;P&gt;Utilities helperclass = new Utilities();&lt;BR /&gt;var strOutput = helperclass.LookupMukey();&lt;BR /&gt;helperclass.OutputTextFiles(strOutput, "TestFile");&amp;nbsp; &amp;nbsp; //error occurs at strOutput&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 06:40:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/argument-error-converting-from-task-to-string/m-p/1147416#M7835</guid>
      <dc:creator>tzz_12</dc:creator>
      <dc:date>2022-02-24T06:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Argument error: Converting from Task to string</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/argument-error-converting-from-task-to-string/m-p/1147520#M7838</link>
      <description>&lt;P&gt;You have to use the await when calling returning a Task&amp;lt;TResult&amp;gt;. See this &lt;A href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/async-return-types#tasktresult-return-type" target="_self"&gt;documentation&lt;/A&gt;.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var strOutput = await helperclass.LookupMukey();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 14:41:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/argument-error-converting-from-task-to-string/m-p/1147520#M7838</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-02-24T14:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Argument error: Converting from Task to string</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/argument-error-converting-from-task-to-string/m-p/1147744#M7844</link>
      <description>&lt;P&gt;I am able to await for the method, LookupMukey and obtain a list of mukeys, but when I output the string of mukeys, there is an error that&amp;nbsp; states,&lt;SPAN&gt;"Cannot convert from 'System.Threading.Task.Task&amp;lt;string&amp;gt; to string."&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 21:42:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/argument-error-converting-from-task-to-string/m-p/1147744#M7844</guid>
      <dc:creator>ThiPham12</dc:creator>
      <dc:date>2022-02-24T21:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: Argument error: Converting from Task to string</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/argument-error-converting-from-task-to-string/m-p/1186552#M8296</link>
      <description>&lt;P&gt;Awaiting the&amp;nbsp; LookupMukey function returns a task not, what the function itself returns. In order to get the list that&amp;nbsp; LookupMukey produces you need&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;List&amp;lt;string&amp;gt; strOutput = await helperclass.LookupMukey().Result;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jun 2022 22:52:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/argument-error-converting-from-task-to-string/m-p/1186552#M8296</guid>
      <dc:creator>BerndtNording</dc:creator>
      <dc:date>2022-06-26T22:52:45Z</dc:date>
    </item>
  </channel>
</rss>

