KingAOP icon indicating copy to clipboard operation
KingAOP copied to clipboard

"An entry with the same key already exists."

Open juliermecarvalho opened this issue 7 years ago • 1 comments

When creating two attributes it generates an "An entry with the same key already exists."

Ex: I have a method that add user and for this method I created two attributes one that authorization and another that time of excution both work but when set together it generates the error: "An entry with the same key already exists."

juliermecarvalho avatar Aug 14 '18 18:08 juliermecarvalho

Due to the SortedList dictionary. Set the AspectPriority property https://github.com/AntyaDev/KingAOP/blob/7ef4777a90782cec704a545cd94045df8d33bc43/src/VS%202010/KingAOP/AspectWeaver.cs#L108

        IEnumerable RetrieveAspects(MemberInfo member)
        {
            var aspects = new SortedList<int, object>(new InvertedComparer());
            foreach (Aspect aspect in member.GetCustomAttributes(typeof(Aspect), false))
            {
                var instance = Activator.CreateInstance(aspect.GetType());
                aspects.Add(aspect.AspectPriority, instance);
            }
            return aspects.Values;
        }

Docs should mention this.

tonyhallett avatar Apr 01 '22 12:04 tonyhallett