<?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 Arcade - 'System.InvalidCastException' in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-system-invalidcastexception/m-p/1208041#M78520</link>
    <description>&lt;P&gt;Hello! I have an expression "var d = Dictionary('Accounting', $feature.AssessmentID)\r\nreturn d" and if the value is null, I get an exception:&lt;BR /&gt;Values = '((Esri.ArcGISRuntime.RuntimeDictionary&amp;lt;string, object&amp;gt;)result.Result).Values' threw an exception of type 'System.InvalidCastException'.&amp;nbsp;&lt;SPAN&gt;The Arcade expression returns a Dictionary, but it seems like JS can't convert that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I researched that I could write like this "$feature.AssessmentID +'' " and no exception.&lt;/P&gt;&lt;P&gt;My method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public override async Task ExecuteAsync(Feature feature)
{

Esri.ArcGISRuntime.ArcadeExpression ArcadeEvaluatorExpression = new Esri.ArcGISRuntime.ArcadeExpression("var d = Dictionary('Accounting1', $feature.AssessmentID)\r\nreturn d"); // AssessmentID = null

ArcadeEvaluator ArcadeEvaluator = new ArcadeEvaluator(ArcadeEvaluatorExpression, ArcadeProfile.FormCalculation);

List&amp;lt;KeyValuePair&amp;lt;string, object&amp;gt;&amp;gt; profileVariables = new List&amp;lt;KeyValuePair&amp;lt;string, object&amp;gt;&amp;gt;();

profileVariables.Add(new KeyValuePair&amp;lt;string, object&amp;gt;("$feature", feature));

ArcadeEvaluationResult result = await ArcadeEvaluator.EvaluateAsync(profileVariables);

Dictionary&amp;lt;string, object&amp;gt; retValues = JObject.FromObject(result.Result).ToObject&amp;lt;Dictionary&amp;lt;string, object&amp;gt;&amp;gt;();

if (retValues != null)
{
   foreach (KeyValuePair&amp;lt;string, object&amp;gt; pair in retValues)
   feature.SetAttributeValue(pair.Key, pair.Value);
}

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Aug 2022 07:21:46 GMT</pubDate>
    <dc:creator>girafee</dc:creator>
    <dc:date>2022-08-31T07:21:46Z</dc:date>
    <item>
      <title>Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-system-invalidcastexception/m-p/1208041#M78520</link>
      <description>&lt;P&gt;Hello! I have an expression "var d = Dictionary('Accounting', $feature.AssessmentID)\r\nreturn d" and if the value is null, I get an exception:&lt;BR /&gt;Values = '((Esri.ArcGISRuntime.RuntimeDictionary&amp;lt;string, object&amp;gt;)result.Result).Values' threw an exception of type 'System.InvalidCastException'.&amp;nbsp;&lt;SPAN&gt;The Arcade expression returns a Dictionary, but it seems like JS can't convert that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I researched that I could write like this "$feature.AssessmentID +'' " and no exception.&lt;/P&gt;&lt;P&gt;My method:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public override async Task ExecuteAsync(Feature feature)
{

Esri.ArcGISRuntime.ArcadeExpression ArcadeEvaluatorExpression = new Esri.ArcGISRuntime.ArcadeExpression("var d = Dictionary('Accounting1', $feature.AssessmentID)\r\nreturn d"); // AssessmentID = null

ArcadeEvaluator ArcadeEvaluator = new ArcadeEvaluator(ArcadeEvaluatorExpression, ArcadeProfile.FormCalculation);

List&amp;lt;KeyValuePair&amp;lt;string, object&amp;gt;&amp;gt; profileVariables = new List&amp;lt;KeyValuePair&amp;lt;string, object&amp;gt;&amp;gt;();

profileVariables.Add(new KeyValuePair&amp;lt;string, object&amp;gt;("$feature", feature));

ArcadeEvaluationResult result = await ArcadeEvaluator.EvaluateAsync(profileVariables);

Dictionary&amp;lt;string, object&amp;gt; retValues = JObject.FromObject(result.Result).ToObject&amp;lt;Dictionary&amp;lt;string, object&amp;gt;&amp;gt;();

if (retValues != null)
{
   foreach (KeyValuePair&amp;lt;string, object&amp;gt; pair in retValues)
   feature.SetAttributeValue(pair.Key, pair.Value);
}

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 07:21:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-system-invalidcastexception/m-p/1208041#M78520</guid>
      <dc:creator>girafee</dc:creator>
      <dc:date>2022-08-31T07:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade - 'System.InvalidCastException'</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-system-invalidcastexception/m-p/1208275#M78527</link>
      <description>&lt;P&gt;It looks like this is posted in the wrong community since this is a Runtime snippet and not a JavaScript one. I suggest posting in one of these:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-runtime-sdks/ct-p/arcgis-runtime-sdks" target="_blank"&gt;https://community.esri.com/t5/arcgis-runtime-sdks/ct-p/arcgis-runtime-sdks&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2022 16:17:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-system-invalidcastexception/m-p/1208275#M78527</guid>
      <dc:creator>KristianEkenes</dc:creator>
      <dc:date>2022-08-31T16:17:05Z</dc:date>
    </item>
  </channel>
</rss>

