Select to view content in your preferred language

Invalid Operation Exception was unhandled by user code

981
3
06-07-2011 10:47 AM
JoannaLaroussi
Emerging Contributor
My map application has ability to do different queries on different layers. I have one button to create query on selected layer and other one to clear query results. For all layers but one Clear button works fine. If I query PED layer and press Clear after this, it gives me an error:
Invalid Operation Exception was unhandled by user code. URL is not set.
pointing out to the following line of code:
queryTask.ExecuteAsync(query);

If I query different layer ??? for example Street and press Clear button, I can query again Streets, but not PED (I receive the same error like above).  If I query PED and use Delete button from keyboard to delete entered value, I can query new value without any problem. It looks like Clear button permanently disables my query on PED layer and I have no idea why.

Bellow is corresponding code. Any ideas highly appreciated

private void CreateQuery()
{
//varibles to use in case
string strQueryTaskURL = "";
string strQueryWhereClause = "";
           
switch (_strLayerQuery)
{
case "PED":

if (InputPED.Text.StartsWith("01") || InputPED.Text.StartsWith("02"))
{
strQueryTaskURL = _strPEDmnQueryService;
}

else if (InputPED.Text.StartsWith("07") || InputPED.Text.StartsWith("08???))
{
strQueryTaskURL = _strPEDbxQueryService;
}
strQueryWhereClause = "S_" + InputPED.Text + " = 'A' OR S_" + InputPED.Text + " = 'B'OR S_" + InputPED.Text + " = 'C'";
break;

case "Street":
strQueryTaskURL = _strStreetQueryService;
strQueryWhereClause = "Street LIKE '%" + InputStreetLion.Text + "%'";
break;
}

ESRI.ArcGIS.Client.Tasks.QueryTask queryTask = new QueryTask(strQueryTaskURL);
queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
queryTask.Failed += QueryTask_Failed;
ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
query.ReturnGeometry = true;
query.OutFields.Add("*");
query.Where = strQueryWhereClause;
queryTask.ExecuteAsync(query);
}


private void PEDClearButton_Click(object sender, RoutedEventArgs e)
{
//clear PED textbox
InputPED.Text = " ";
// Clear previous results
GraphicsLayer graphicsLayer = Map.Layers["PEDGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
}

private void StreetClearButton_Click(object sender, RoutedEventArgs e)
{
//clear the data grid
StreetQueryNewDataGrid.ItemsSource = null;
StreetQueryResultPanelGrid.Visibility = Visibility.Collapsed;
//clear search text box
InputStreetLion.Text = "";
// Clear previous results
GraphicsLayer graphicsLayer = Map.Layers["LionGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
}
0 Kudos
3 Replies
TerryGiles
Frequent Contributor
A couple of quick things to check based on the code below -

In PEDClearButton_Click it looks like you are setting the text of PED textbox to a space, not an empty string.  Try using String.Empty instead as when the user clicks in the box to enter a new value, it may be appending it to that space and the logic of InputPED.Text.StartsWith() might not work since the 1st 2 characters are actually "<space>0".  Using InputPED.Text.Trim().StartsWith() might work too.

If that's not it 2 other things might be happening -

Is it possible that _strLayerQuery is empty?  If not does the case match that in your switch statement (it is case sensitive).

Is the user entering something other than a 01,02,07, or 08 in the input box? 

TG
0 Kudos
JenniferNery
Esri Regular Contributor
What does the stack trace say? You create and subscribe to a new QueryTask all the time?
0 Kudos
JoannaLaroussi
Emerging Contributor
You were right Terry: it was extra space added by Clear button. I took it off and everything works fine. Thanks!
0 Kudos