Ticket T213062
Visible to All Users

Element with the same name already exists in the scope

created 10 years ago

Hi

Today we swiched from 14.1.9 to 14.2.5.  BUT

we have some difficulties getting the SetDXContextMenu up and running.  We have a n exception on it all the time.

C#
public virtual void CreatePopup() { m_Popup = new PopupMenu { StaysOpen = true }; BarManager.SetBarManager(m_Popup, m_Manager); m_Popup.Opening += OnPopupOpening; m_Popup.Opened += PopupOpened; m_Popup.Closed += PopupClosed; RegisterCommands(); CreateContextMenu(); BarManager.SetDXContextMenu(m_Owner, m_Popup); }

Can you see what we're doing wrong here?

Comments (3)
DevExpress Support Team 10 years ago

    Hi Alexander,
    I have copied your code to a clean sample, but was unable to reproduce the issue using it. I feel that you create elements (for example, Bar*Item objects) with the same names in your methods (RegisterCommands, CreateContextMenu). Please check this. If you're unable to find the cause of the problem, can you send me the code of these methods?

    A A
    Alexander Muylaert-Gelein 10 years ago

      Trying to find a small example, often not easy
      Changing GlobalSkipUniquenessCheck fixes it for me.  What does it do exactly? I decompiled core, but unfortunatly I cannot see the value of "object name".
      Can you  tell the developers to SHOW the name from now on in exceptions.  It would save everybody a huge amount of time.
             static AbstractPopupContext()
             {
                 ElementRegistrator.GlobalSkipUniquenessCheck = true;
             }
             public void Add(IBarNameScopeSupport element)
             {
                 if (this.IsValidName(element) && !this.Elements.ContainsValue(element))
                 {
                     object name = this.GetName(element);
                     if ((this.Unique && this.Elements.ContainsKey(name)) && !this.ActualSkipUniquenessCheck)
                     {
                         throw new InvalidOperationException("Element with the same name already exists in the scope");
                     }
                     this.Elements.Add(name, element);
                     this.RaiseChanged(element, ElementRegistratorChangeType.ElementAdded, name, name);
                 }
             }
      thanks
      a

      Andrey Marten (DevExpress Support) 10 years ago

        Hello Alexander,

        I'm happy to hear that you've found the solution for your situation. Thank you for informing us of your results. If you provide us with your project, we can try to research it to find the cause of the issue and suggest a more suitable solution for your case. Please note that you can mark this ticket Private and nobody except my colleagues and I have access to it.

        Setting the ElementRegistrator.GlobalSkipUniquenessCheck static property to True simply turns off the exception if there is a duplicated name conflict. Your suggestion about including the element's name into the exception's message makes sense and I've created a separate ticket with it: Show the name of the BarItem in the InvalidOperationException, which is caused by adding this item into the BarManager. Our developers will consider it in future and probably will provide the corresponding modifications.

        Thanks,
        Andrey

        Answers

        created 10 years ago

        Hi

        This is solved by now.    Just closing it

          Comments (3)
          Andrey Marten (DevExpress Support) 10 years ago

            I'm happy to hear that, Alexander!
            It will be great if you could find the opportunity to briefly describe how you've resolved the issue in your particular case. This information can be useful for other customers who may face the same difficulties.

            Thanks,
            Andrey

              In my case, the problem was x:Name attribute on dxr:RibbonGalleryBarItem within a data template.
              It is a bit strange because when the "second" item was added the "first" one was supposed to be removed from the ribbon.
              <dxr:RibbonPageCategory PagesSource="{Binding Selected.ContextMenu.ChildItems}"> was used and the Selected has changed. ContextMenu was constructed dynamically and different objects that could possibly be assigned to Selected could have an item that would use the same data template. If the explanation doesn't make much sense, I can probably come up with a sample project.
              By the way, I'm using 15.1.5 and the name is still not shown in the exception.

              Andrey Marten (DevExpress Support) 9 years ago

                Hello,

                To process your recent post more efficiently, I created a separate ticket on your behalf: T301032: An exception is raised when RibbonGalleryBarItem's name is defined within DataTemplate. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

                Thanks,
                Andrey

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.