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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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]

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 Legacy 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