Skip to content

Commit

Permalink
When address is not resolved there will be 0 results and code will fa…
Browse files Browse the repository at this point in the history
…il with null-reference pointer exception
  • Loading branch information
AndrewButenko committed Dec 10, 2018
1 parent 5507e9d commit ccb19d7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions CoreOperations/System/GeoCodeAddress.cs
@@ -1,6 +1,7 @@
using System;
using System.Activities;
using System.IO;
using System.Linq;
using System.Net;
using Newtonsoft.Json;
using Microsoft.Xrm.Sdk;
Expand Down Expand Up @@ -55,9 +56,18 @@ protected override void ExecuteWorkflowLogic()
throw new InvalidPluginExecutionException($"BingMaps Endpoint call failed - {string.Join(Environment.NewLine, response.ErrorDetails)}{Environment.NewLine}{response.StatusDescription}");
}

var geocodePoint = response.ResourceSets.FirstOrDefault()?.Resources.FirstOrDefault()?.GeocodePoints
.FirstOrDefault();

if (geocodePoint == null)
{
IsResolved.Set(Context.ExecutionContext, false);
return;
}

IsResolved.Set(Context.ExecutionContext, true);
Latitude.Set(Context.ExecutionContext, Convert.ToDecimal(response.ResourceSets[0].Resources[0].GeocodePoints[0].Coordinates[0]));
Longitude.Set(Context.ExecutionContext, Convert.ToDecimal(response.ResourceSets[0].Resources[0].GeocodePoints[0].Coordinates[1]));
Latitude.Set(Context.ExecutionContext, Convert.ToDecimal(geocodePoint.Coordinates[0]));
Longitude.Set(Context.ExecutionContext, Convert.ToDecimal(geocodePoint.Coordinates[1]));
}
}

Expand Down

0 comments on commit ccb19d7

Please sign in to comment.