I had written an application a few years ago using .net sdk 10.2.7. It was working fine a few years ago. i came back to trying to use it now,but when it try it now. it is giving an error of Value cannot be null. Parameter name: source when calling the Dim routeResult = Await routeTask.SolveAsync(routeParams)
Was something changed in the API?
My guess would be that something has changed with the service/data that you're using for the route task (or the inputs). If you share a bit of the offending code, I can give it a test on my end.
I even tried using previous data that i used before for testing when it was working with the same issue.
Here is the code
Dim routeGraphics = TryCast(MyMap.Layers("RouteResults"), GraphicsLayer)
If routeGraphics Is Nothing Then
Throw New Exception("A graphics layer named 'RouteResults' was not found in the map.")
End If
Dim uri = New Uri("http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World")
Dim routeTask = New OnlineRouteTask(uri)
Dim RouteRestrictions = New List(Of String)
RouteRestrictions.Add("Avoid Toll Roads")
Dim routeParams = Await routeTask.GetDefaultParametersAsync()
routeParams.OutSpatialReference = MyMapView.SpatialReference
routeParams.DirectionsLengthUnit = LinearUnits.Miles
routeParams.ReturnDirections = True
routeParams.DirectionsLanguage = New CultureInfo("en-Us")
routeParams.FindBestSequence = CBool(OptOptimized.IsChecked)
routeParams.PreserveFirstStop = CBool(PreserveStopsCbx.IsChecked)
routeParams.PreserveLastStop = CBool(PreserveStopsCbx.IsChecked)
routeParams.UseHierarchy = Not CBool(CbxAvoidHwy.IsChecked)
If (CbxAvoidToll.IsChecked) Then
routeParams.RestrictionAttributeNames = RouteRestrictions
End If
routeParams.ReturnStops = True
routeParams.SetStops(routeGraphics.Graphics)
Dim routeResult = Await routeTask.SolveAsync(routeParams)
It gives that error on the last line
Hey Murray.
I tested your code and saw the same thing. I tried using the following (San Diego) route service, and it worked as expected: Route (NAServer)
I think the problem might be with authenticating for the service ("Route_World" is a premium service that you must sign in for). I tried using world routing service in this sample: https://github.com/Esri/arcgis-runtime-samples-dotnet/tree/master/src/WPF/ArcGISRuntime.WPF.Viewer/S... and after authenticating with my ArcGIS Online account, the route was solved successfully.
I'm not sure what may have changed to cause your code to fail. A couple of guesses: perhaps you had authentication "baked in" to your app and those credentials are no longer valid or perhaps your app was originally using a different (openly available) route service.
If you need to add authentication to your app, this sample may help (sorry, C# only): https://github.com/Esri/arcgis-runtime-samples-dotnet/tree/10.2.7/src/Desktop/ArcGISRuntimeSamplesDe...
It does appear related to the authentication. I am using the code below.
Private ArcGISOnineUser As String = "xxx"
Private ArcGISOninePassword As String = "xxx"
Public Sub New()
Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ClientId = "xxx"
Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.Initialize()
InitializeComponent()
IdentityManager.Current.ChallengeHandler = New ChallengeHandler(AddressOf CreateHardCodedCredentialAsync)
end sub
Private Async Function CreateHardCodedCredentialAsync(requestInfo As CredentialRequestInfo) As Task(Of Credential)
Dim cred As Credential = Nothing
Try
Dim options = New GenerateTokenOptions()
options.TokenAuthenticationType = TokenAuthenticationType.ArcGISToken
cred = Await IdentityManager.Current.GenerateCredentialAsync(requestInfo.ServiceUri, ArcGISOnineUser, ArcGISOninePassword, options)
Catch webEx As ArcGISWebException
' couldn't generate a token, probably a bad login
MessageBox.Show("Unable to log in to ArcGIS Online: " + webEx.Message)
End Try
Return cred
End Function
After some investigation it seems that GenerateCredentialAsync never seems to return anything and the task seems to run indefinitely.
as a test it tried having it wait for the task completion
Dim cred As Task(Of Credential) = CreateHardCodedCredentialAsync2("https://www.arcgis.com/sharing/rest")
Try
cred.Wait()
Catch ex As Exception
MsgBox(ex.Message)
End Try
In this case it would just be stuck on cred.Wait() forever
CreateHardCodedCredentialAsync2 is just there to replace the requestInfo.ServiceUri
I tried running the sample in https://github.com/Esri/arcgis-runtime-samples-dotnet/tree/10.2.7/src/Desktop/ArcGISRuntimeSamplesDe..., but when i clicked sign in all it did is display a page saying
Is it because TLS1.2 was turned on recently and your app isn't set up to support it?
Transport Layer Security (TLS) best practices with the .NET Framework | Microsoft Docs
Forcing TLS 1.2 via
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 and switching the project to .Net Framework 4.7 doesn't seem to help.