Hello! I have an expression "var d = Dictionary('Accounting', $feature.AssessmentID)\r\nreturn d" and if the value is null, I get an exception:
Values = '((Esri.ArcGISRuntime.RuntimeDictionary<string, object>)result.Result).Values' threw an exception of type 'System.InvalidCastException'. The Arcade expression returns a Dictionary, but it seems like JS can't convert that.
I researched that I could write like this "$feature.AssessmentID +'' " and no exception.
My method:
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<KeyValuePair<string, object>> profileVariables = new List<KeyValuePair<string, object>>();
profileVariables.Add(new KeyValuePair<string, object>("$feature", feature));
ArcadeEvaluationResult result = await ArcadeEvaluator.EvaluateAsync(profileVariables);
Dictionary<string, object> retValues = JObject.FromObject(result.Result).ToObject<Dictionary<string, object>>();
if (retValues != null)
{
foreach (KeyValuePair<string, object> pair in retValues)
feature.SetAttributeValue(pair.Key, pair.Value);
}
}
Thanks.
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: https://community.esri.com/t5/arcgis-runtime-sdks/ct-p/arcgis-runtime-sdks