Debug help: Value does not fall within the expected range

4428
1
Jump to solution
07-24-2015 04:27 PM
LanceGoens
New Contributor III

I'm currently working on a project that allows the user to add graphics to a map. The graphics are symbolized as SimpleTextSymbols. Since this is a labeling tool and we have multiple types of labels, I create an extra Graphic attribute (key value pair) to distinguish them in code. This all works fine and I am able to add multiple graphics to one GraphicsLayer. I noticed though, when I tried to use the hi-resolution print service that the extra attribute would cause the print to fail as the attribute key that I added is not a part of the Graphic's schema. So, to remedy this, I temporarily strip the attribute off any Graphic in the GraphicsLayer that has it and notate it's point location so that I can add it back later.

At this point, the print service does it's thing and I have a pdf that I can print and all of my Graphic text labels are in the pdf. Now, I add the attributes back to the graphics. This completes successfully.

Here is where things go bad. I need the ability to edit (move / edit font size / rotate) the graphics at any time. Prior to printing I can do this by using an editor control to select the Graphics and perform the desired edit. However, after printing them, I cannot move the Graphics. I can rotate or change the font size without a problem, but the second I click on a selected graphic(s) and drag, it throws the "Value does not fall within the expected range" exception and the app crashes. Below is the stack trace it generates:

   at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)

   at MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)

   at MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element, UIElement visual)

   at System.Windows.UIElement.TransformToVisual(UIElement visual)

   at ESRI.ArcGIS.Client.Map.getFullViewExtent()

   at ESRI.ArcGIS.Client.Map.layer_OnLayerChanged(Object sender, EventArgs args)

   at ESRI.ArcGIS.Client.Layer.OnLayerChanged()

   at ESRI.ArcGIS.Client.GraphicsLayer.<CompositionTarget_Rendering>b__0()

I added an event handler to the PropertyChanged event on the GraphicsLayer that houses all of my Graphics. When I attempt the move the selected graphics, the FullExtent property of the layer changes probably 25+ times when there are 7 graphics in the layer. This seems excessive A, and B, why would that crash the application?

I have read a bit on other posts that this exception is common when trying to add something to the Visual Tree that has the same name as something already present in the tree. I don't see how that is the case in this scenario. I'm trying to move Graphics in a GraphicsLayer.... I'm not adding any objects to anything in the application. I've inspected the map, map layers, this graphics layer, the graphics in the layer, and attributes on the graphics... everything looks identical compared to the working status prior to the print.

What is OnLayerChanged() doing??? Have no idea what CompositionTarget_Rendering.... refers to either.

Please help! TIA.

0 Kudos
1 Solution

Accepted Solutions
LanceGoens
New Contributor III

Hoping this helps someone at some point.

Resolved this issue. In our application we launch a print preview window in which a new map control is displayed. All of the layers and graphics in the application map are cloned and placed into the preview window's map control. When the window is closed, I was working off the assumption that the preview map and contents would be disposed of and they simply are not. Plus, they don't seem to be independent objects which could be an issue with our cloning process but I'm not sure how as all of the layers and graphics are instantiated as "new" objects. Yet if the preview map's graphics are not cleared before closing the preview window, the application will crash when trying to move graphics in the application's map. I'm clearing them prior to closing and now the application continues without issue.

View solution in original post

0 Kudos
1 Reply
LanceGoens
New Contributor III

Hoping this helps someone at some point.

Resolved this issue. In our application we launch a print preview window in which a new map control is displayed. All of the layers and graphics in the application map are cloned and placed into the preview window's map control. When the window is closed, I was working off the assumption that the preview map and contents would be disposed of and they simply are not. Plus, they don't seem to be independent objects which could be an issue with our cloning process but I'm not sure how as all of the layers and graphics are instantiated as "new" objects. Yet if the preview map's graphics are not cleared before closing the preview window, the application will crash when trying to move graphics in the application's map. I'm clearing them prior to closing and now the application continues without issue.

0 Kudos