Exception: Value does not fall within the expected range

16 posts, 1 answers
  1. Carlos Rodriguez
    Carlos Rodriguez avatar
    72 posts
    Member since:
    Aug 2009

    Posted 10 Nov 2009 Link to this post

    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!!! =(
  2. Carlos Rodriguez
    Carlos Rodriguez avatar
    72 posts
    Member since:
    Aug 2009

    Posted 10 Nov 2009 Link to this post

    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
  3. DevCraft banner
  4. Carlos Rodriguez
    Carlos Rodriguez avatar
    72 posts
    Member since:
    Aug 2009

    Posted 10 Nov 2009 Link to this post

    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.
     =)
  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 13 Nov 2009 Link to this post

    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.
  6. Carlos Rodriguez
    Carlos Rodriguez avatar
    72 posts
    Member since:
    Aug 2009

    Posted 06 Jan 2010 Link to this post

    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)
  7. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 11 Jan 2010 Link to this post

    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.
  8. Carlos Rodriguez
    Carlos Rodriguez avatar
    72 posts
    Member since:
    Aug 2009

    Posted 11 Jan 2010 Link to this post

    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!
  9. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 12 Jan 2010 Link to this post

    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.
  10. Carlos Rodriguez
    Carlos Rodriguez avatar
    72 posts
    Member since:
    Aug 2009

    Posted 12 Jan 2010 Link to this post

    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();

     

    }

    }

  11. Carlos Rodriguez
    Carlos Rodriguez avatar
    72 posts
    Member since:
    Aug 2009

    Posted 12 Jan 2010 Link to this post

    he problem is that causes the exception to add a first RadTrieeViewItem.
  12. Answer
    Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 12 Jan 2010 Link to this post

    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.
  13. Carlos Rodriguez
    Carlos Rodriguez avatar
    72 posts
    Member since:
    Aug 2009

    Posted 12 Jan 2010 Link to this post

    Yes, there are two nodes that has the same name, but everyone is in different RadTreeView
  14. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 12 Jan 2010 Link to this post

    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.
  15. Carlos Rodriguez
    Carlos Rodriguez avatar
    72 posts
    Member since:
    Aug 2009

    Posted 12 Jan 2010 Link to this post

    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 =)
  16. Adriaan
    Adriaan avatar
    8 posts
    Member since:
    Jun 2011

    Posted 16 Jul 2012 Link to this post

    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
  17. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 19 Jul 2012 Link to this post

    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.

Back to Top
DevCraft banner