This is a migrated thread and some comments may be shown as answers.

Exception: Value does not fall within the expected range

15 Answers 1217 Views
Window
This is a migrated thread and some comments may be shown as answers.
Carlos Rodriguez
Top achievements
Rank 1
Carlos Rodriguez asked on 10 Nov 2009, 04:54 PM
I have two RadWindow, the first opens the RadWindow to click on an button, and the second RadWindow opens when you click at a button within the first RadWindow and finally close the two RadWindow.

When I want to reopen the first RadWindow I get the exception: " Value does not fall within the expected range"

Heeeelp!!! =(

15 Answers, 1 is accepted

Sort by
0
Carlos Rodriguez
Top achievements
Rank 1
answered on 10 Nov 2009, 07:33 PM
I forgot to tell that in the first several textBlock RadWindow, there is a RadToolBar and RadTreeView, and the second RadWindow and several texbox textblock.

Thanks
0
Carlos Rodriguez
Top achievements
Rank 1
answered on 10 Nov 2009, 08:19 PM
Hello, I've found the error.
The error is caused by the RadTreeView that was within the first RadWindow when select an item, close the window, when you reopen the window caused the error, because he had left an Item selected in the RadTreeView.

I tried to give the value "false" RadTreeViewItem.IsSelected property did not work.

Thank you!

P.D. Excuse my English, I'm just learning.
 =)
0
Miroslav
Telerik team
answered on 13 Nov 2009, 04:36 PM
Hello Carlos,

This seems like a bug in the TreeView.

Can you please send us the CallStack when the exception happens?

Please uncheck "Tools -> Options -> Debugging -> Enable Just My Code".

Thank you for helping us identify this issue.

Regards,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Carlos Rodriguez
Top achievements
Rank 1
answered on 07 Jan 2010, 12:16 AM
System.ArgumentException:Value does not fall within the expected range 

en MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
   en MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)
   en MS.Internal.XcpImports.Collection_Add[T](PresentationFrameworkCollection`1 collection, Object value)
   en System.Windows.PresentationFrameworkCollection`1.AddImpl(Object value)
   en System.Windows.Controls.ItemCollection.AddImpl(Object value)
   en System.Windows.Controls.ItemCollection.AddInternal(Object value)
   en System.Windows.PresentationFrameworkCollection`1.Add(T value)
   en ReqMaterial.Presentacion.Silverlight.Views.formSolicitud.consSolReqMaterial.cliente_consulta_PartidasAutorizarCompleted(Object sender, consulta_PartidasAutorizarCompletedEventArgs e)
0
Miroslav
Telerik team
answered on 11 Jan 2010, 08:57 AM
Hello Carlos Rodriguez,

The exception "Value does not fall within the expected range" is thrown when an object that already exists in the visual tree of the appellation is added to it again. From your callstack it seems that this is what is happening, i.e. this method:

ReqMaterial.Presentacion.Silverlight.Views.formSolicitud.consSolReqMaterial.cliente_consulta_PartidasAutorizarCompleted(Object sender, consulta_PartidasAutorizarCompletedEventArgs e)

adds something to the visual tree that has not been removed from its previous parent:

System.Windows.PresentationFrameworkCollection`1.Add(T value)

Unfortunately I cannot guess what this may be. What happens in your code when all items in the TreeView are deselected? It seems that it is related to the error.

If you could send us a project where the exception occurs, I will be happy to help you.

All the best,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Carlos Rodriguez
Top achievements
Rank 1
answered on 11 Jan 2010, 09:39 PM
Hi Miroslav!

The exception and occurs when the tree is loaded first. I've been seeing that in executing the application, load normally, other occasions that exception occurs.

Unfortunately I can not send the project, because I have no privileges on my account even send the projects.

Thanks and greetings!
0
Miroslav
Telerik team
answered on 12 Jan 2010, 02:29 PM
Hello Carlos Rodriguez,

Could you share the code in this method?

ReqMaterial.Presentacion.Silverlight.Views.formSolicitud.consSolReqMaterial.cliente_consulta_PartidasAutorizarCompleted(Object sender, consulta_PartidasAutorizarCompletedEventArgs e)

It seems that something there is causing the exception.

All the best,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Carlos Rodriguez
Top achievements
Rank 1
answered on 12 Jan 2010, 04:47 PM

This same method you ask:

void

 

cliente_consulta_PartidasAutorizarCompleted(object sender, consulta_PartidasAutorizarCompletedEventArgs e)

 

{

 

    try
    
{

 

 

        for (int i = 0; i < e.Result.Count; i++)

 

        {

            radTreVieParProgramacion.Items.Add(Agregar_TreVieItem(e.Result[i]));

        }

    }

 

    catch (Exception parException)

 

    {

    }

}

This is the method that creates the TreeViewItem:

 

RadTreeViewItem

 

Agregar_TreVieItem(object parObjGenerico)

 

{

 

    try

 

    {

 

        RadTreeViewItem newRadItem = new RadTreeViewItem();

 

 

        Type TypObjeto = parObjGenerico.GetType();

 

 

        if (TypObjeto.Name == "objEntSolicitud")

 

        {

 

            objEntSolicitud objGenerico = (objEntSolicitud)parObjGenerico;

 

            newRadItem.Header =

"Sol." + objGenerico.numIdeParEncabezado + " " + objGenerico.carDesBodega + " [" + objGenerico.carNomUsuario + "]";

 

            newRadItem.Name = objGenerico.numIdeParEncabezado.ToString();

            newRadItem.Tag = objGenerico;

            newRadItem.SetValue(

ToolTipService.ToolTipProperty, newRadItem.Header);

 

            newRadItem.DefaultImageSrc =

"../../Imagen/Button/folder_solicitud.png";

 

 

            return newRadItem;

 

        }

 

        else if (TypObjeto.Name == "objEntSolicitudDetalle")

 

        {

 

objEntSolicitudDetalle objGenerico = (objEntSolicitudDetalle)parObjGenerico;

 

newRadItem.Header = objGenerico.carDesProducto +

" [" + objGenerico.numCanSolicitada + " " + objGenerico.carDesUniMedida + "]";

 

newRadItem.Name = objGenerico.numIdeParDetalle.ToString();

newRadItem.Tag = objGenerico;

newRadItem.SetValue(

ToolTipService.ToolTipProperty, newRadItem.Header);

 

newRadItem.DefaultImageSrc =

"../../Imagen/Button/partida.png";

 

 

return newRadItem;

 

}

 

else if (TypObjeto.Name == "objEntParProgramacion")

 

{

 

objEntParProgramacion objGenerico = (objEntParProgramacion)parObjGenerico;

 

newRadItem.Header = objGenerico.carDesProducto +

" [" + objGenerico.numCanProgramada + "]";

 

newRadItem.Name = objGenerico.numIdeParProgramacion.ToString();

newRadItem.Tag = objGenerico;

newRadItem.SetValue(

ToolTipService.ToolTipProperty, newRadItem.Header);

 

newRadItem.DefaultImageSrc =

"../../Imagen/Button/partida.png";

 

 

return newRadItem;

 

}

 

else if (TypObjeto.Name == "objEntTransMaterial")

 

{

 

objEntTransMaterial objGenerico = (objEntTransMaterial)parObjGenerico;

 

newRadItem.Header = objGenerico.carDescripcion;

newRadItem.Name = objGenerico.numIdeTransMaterial.ToString();

newRadItem.Tag = objGenerico;

newRadItem.SetValue(

ToolTipService.ToolTipProperty, newRadItem.Header);

 

newRadItem.DefaultImageSrc =

"../../Imagen/Button/carpeta.png";

 

 

return newRadItem;

 

}

 

return new RadTreeViewItem();

 

}

 

catch (Exception parException)

 

{

 

return new RadTreeViewItem();

 

}

}

0
Carlos Rodriguez
Top achievements
Rank 1
answered on 12 Jan 2010, 04:57 PM
he problem is that causes the exception to add a first RadTrieeViewItem.
0
Accepted
Miroslav
Telerik team
answered on 12 Jan 2010, 04:58 PM
Hi Carlos Rodriguez,

This line here may be the reason for the problem:

newRadItem.Name = objGenerico.numIdeParEncabezado.ToString();

it appears to me that quite possibly two items with the same name could be created in the same namescope. Namescopes can be surprising in Silverlight, even if an object is not visible (like a closed window) it may still be part of the current namescope.

Could you try commenting the line to check whether the error is resolved. If it indeed is so, you may have to make sure that items with equal names are not added and that items are removed from their namescope before adding items with the same names.

Does this work for you?

Regards,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Carlos Rodriguez
Top achievements
Rank 1
answered on 12 Jan 2010, 06:00 PM
Yes, there are two nodes that has the same name, but everyone is in different RadTreeView
0
Miroslav
Telerik team
answered on 12 Jan 2010, 06:06 PM
Hello Carlos Rodriguez,

Quite possibly the two windows share the same namescope.

Do you see the exception if the names are not set?

We have no control over the namescopes in Silverlight, they are determined by the visual tree and whether the item is a part of a Template (DataTemplate or ControlTemplate), possibly other rules that I am not aware of.

Regards,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Carlos Rodriguez
Top achievements
Rank 1
answered on 12 Jan 2010, 06:21 PM
Agree, the only solution is to not assign a value to the parameter name, as you say is what runs the exception and that is the problem. Delete the line that assign values to the Name parameter and the exception no longer occurs.
I think it's better that way and better to store the value in the Tag parameter.
Miroslav'd appreciate your help, I was going crazy = P.
thanks =)
0
Adriaan
Top achievements
Rank 1
answered on 16 Jul 2012, 12:10 PM
Hi,

I understand that you have no control over the namescope but could you give a better error message? This message is only confusing the issue. I am getting the same error message but it is not resolved by following this thread (I don't name my controls) so the same error message is obviously generated by something else
0
Petar Mladenov
Telerik team
answered on 19 Jul 2012, 06:05 AM
Hi Adriaan,

 "Value does not fall within the expected range" may occur in other scenarios different from the one described in this old thread. Yes, you are right,  we cannot control how namescope in Silverlight works, furthermore we cannot override such system (Framework) exceptions.
We highly suggest you to open a new support thread with more details on your scenario and the steps you perform when reproducing the issue. This way we would be better able to investigate your case and you will receive a much faster response.
Thank you in advance for your cooperation.

Greetings,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Window
Asked by
Carlos Rodriguez
Top achievements
Rank 1
Answers by
Carlos Rodriguez
Top achievements
Rank 1
Miroslav
Telerik team
Adriaan
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or