[OPEN] [#330] A suggestion to eradicate "Token is not unique" errors

  1. #1

    [OPEN] [#330] A suggestion to eradicate "Token is not unique" errors

    Token is not unique
    -------------------
    ID = ctl00_cp_TaskUC0_TDatesW_ClientInit
    TagName = anchor
    Match = <#:anchor id="ctl00_cp_TaskUC0_TDatesW_ClientInit" />



    I don't know if this would be considered a bug, but I was tracking the occurrence of this issue within my code. It took a good number of hours but I finally realized it was because I was adding the same user control twice. Effectively to reproduce, all you need to do is the following:
    Panel1.Items.Add( ctl ); Panel1.Items.Add( ctl );
    Panel1.Bin.Add( ctl ); Panel1.Bin.Add( ctl );
    Here's my reason for posting this. It seems to me that I had to work all the way backwards from Transformer which is very late way to discover the issue. It's not excepting out where the issue actually happens, and its easy to catch.

    I looked at ItemsCollection<T> which is derived from List<T> and though I thought HashSet might be better, I tried it but there's a lot of dependencies on functions of IList and performance was unnecessary to affect Release versions, so instead I thought it would be easy to add the following so I tried:

            new public void Add(T item)
            {
    #if DEBUG
                if(base.Contains(item))
                    throw new Exception("Duplicate control");
    #endif
    
    
                this.CheckItem(item);
    
    
                if (this.BeforeItemAdd != null)
                {
                    this.BeforeItemAdd(item);
                }
                
                base.Add(item);
    
    
                if (this.AfterItemAdd != null)
                {
                    this.AfterItemAdd(item);
                }
            }
    It worked. Now you just need to apply the same tests for AddRange and Insert and this problem saves another programmer some grief.
    Last edited by Daniil; Aug 28, 2013 at 6:01 AM. Reason: [OPEN] [#330]
  2. #2
    I'm realizing it couldn't hurt to call out the name of the ClientID in the exception as well.
  3. #3
    Well, your override doesn't cover all cases because you can add Ext.Net controls to ASP.NET native controls (Controls collection)
    Or you can add one instance to different containers

    In this case, you will have the same error. So, I am doubt that we can track it.
    I guess that we should to change text of the error, for example 'Token is not unique, possible control duplicating'
    Vladimir Shcheglov
    Sr. Developer
  4. #4
    Quote Originally Posted by Vladimir View Post
    Well, your override doesn't cover all cases because you can add Ext.Net controls to ASP.NET native controls (Controls collection)
    Yeah, this case is tricky.

    Quote Originally Posted by Vladimir View Post
    Or you can add one instance to different containers In this case, you will have the same error. So, I am doubt that we can track it.
    This one could be handled. Instead of the code I suggested above, you could have a shared HashTable resource you add all controls to in addition to the code that's supposed to be there. Debug mode only.

    Quote Originally Posted by Vladimir View Post
    I guess that we should to change text of the error, for example 'Token is not unique, possible control duplicating'
    At a minimum, communicative errors are helpful.
  5. #5
    Quote Originally Posted by michaeld View Post
    At a minimum, communicative errors are helpful.
    Created an Issue.
    https://github.com/extnet/Ext.NET/issues/330

Similar Threads

  1. Replies: 6
    Last Post: May 31, 2013, 3:04 AM
  2. [CLOSED] [MVC] Export Excel return "BADRESPONSE: Unexpected token <"
    By UnifyEducation in forum 2.x Premium Help
    Replies: 1
    Last Post: Aug 02, 2012, 3:05 PM
  3. Replies: 5
    Last Post: May 02, 2012, 5:37 PM
  4. Replies: 4
    Last Post: Oct 11, 2011, 2:42 AM
  5. Replies: 2
    Last Post: Jun 26, 2011, 1:59 AM

Posting Permissions