danrer
Topic Author
Posts: 10
Joined: 27 Apr 2019, 18:20

[ERROR] An item with the same key has already been added.

05 Jan 2020, 00:11

The code works perfectly, but at strange moments for me there is an error "ArgumentException: An item with the same key has already been added";
The code is very simple, there are 2 ListBox. Each of them is bound to its own ObservableCollection<BaseResearchItem>.
When I double click on ContentControl it moves BaseResearchItem from one ObservableCollection to another ObservableCollection. Everything works without errors, I can move dozens, hundreds of times from one collection to another, But sometimes this error appears.
And Yes, there is no Dictionary in my code.
More error information.
ArgumentException: An item with the same key has already been added. Key: 2489215921760
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <23c160f925be47d7a4fd083a3a62c920>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <23c160f925be47d7a4fd083a3a62c920>:0)
Noesis.Texture.WrapTexture (System.Object texture, System.IntPtr nativePointer, System.Int32 width, System.Int32 height, System.Int32 numLevels) (at Assets/NoesisGUI/Plugins/NoesisTexture.cs:21)
Noesis.TextureSource..ctor (UnityEngine.Texture2D texture) (at Assets/NoesisGUI/Plugins/NoesisTextureSource.cs:12)
Texture2DExtension.EncodeToNoesisImage (UnityEngine.Texture2D texture) (at Assets/Scripts/Extension/Texture2DExtension.cs:9)
BaseItem.get_Icon () (at Assets/Scripts/BaseItem/BaseItem.cs:64)
System.Reflection.MonoProperty.GetterAdapterFrame[T,R] (System.Reflection.MonoProperty+Getter`2[T,R] getter, System.Object obj) (at <23c160f925be47d7a4fd083a3a62c920>:0)
System.Reflection.MonoProperty.GetValue (System.Object obj, System.Object[] index) (at <23c160f925be47d7a4fd083a3a62c920>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoProperty.GetValue (System.Object obj, System.Object[] index) (at <23c160f925be47d7a4fd083a3a62c920>:0)
Noesis.Extend+PropertyAccessorPropRO`1+<>c__DisplayClass1_0[PropertyT].<.ctor>b__0 (System.Object instance) (at Assets/NoesisGUI/Plugins/API/Core/ExtendProps.cs:125)
Noesis.Extend+PropertyAccessorPropRO`1[PropertyT].Get (System.Object instance) (at Assets/NoesisGUI/Plugins/API/Core/ExtendProps.cs:130)
Noesis.Extend.GetPropertyValue[T] (Noesis.Extend+PropertyAccessor prop, System.Object instance) (at Assets/NoesisGUI/Plugins/API/Core/Extend.cs:2976)
Noesis.Extend.GetPropertyValue_BaseComponent (System.IntPtr nativeType, System.Int32 propertyIndex, System.IntPtr cPtr) (at Assets/NoesisGUI/Plugins/API/Core/Extend.cs:3387)
UnityEngine.Debug:LogException(Exception)
NoesisUnity:OnUnhandledException(Exception) (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:142)
Noesis.Error:UnhandledException(Exception) (at Assets/NoesisGUI/Plugins/API/Core/Error.cs:18)
Noesis.Extend:GetPropertyValue_BaseComponent(IntPtr, Int32, IntPtr) (at Assets/NoesisGUI/Plugins/API/Core/Extend.cs:3392)
Noesis.Extend:Noesis_LaunchPropertyChangedEvent(IntPtr, IntPtr, String)
Noesis.Extend:NotifyPropertyChanged(Object, PropertyChangedEventArgs) (at Assets/NoesisGUI/Plugins/API/Core/Extend.cs:4403)
GUI_Blend.NotifyPropertyChangedBase:OnPropertyChanged(String) (at Assets/GUI/Extension/NotifyPropertyChangedBase.cs:14)
GUI_Blend.ScienceWindowViewModel:set_SelectedResearchItem(BaseResearchItem) (at Assets/GUI/ScienceWindowViewModel.cs:87)
System.Reflection.PropertyInfo:SetValue(Object, Object, Object[])
Noesis.<>c__DisplayClass2_0:<.ctor>b__1(Object, Object) (at Assets/NoesisGUI/Plugins/API/Core/ExtendProps.cs:106)
Noesis.PropertyAccessorPropRW`1:Set(Object, Object) (at Assets/NoesisGUI/Plugins/API/Core/ExtendProps.cs:116)
Noesis.Extend:SetPropertyValue(PropertyAccessor, Object, Object) (at Assets/NoesisGUI/Plugins/API/Core/Extend.cs:3402)
Noesis.Extend:SetPropertyValue_BaseComponent(IntPtr, Int32, IntPtr, IntPtr, IntPtr) (at Assets/NoesisGUI/Plugins/API/Core/Extend.cs:3809)
Noesis.View:Noesis_View_MouseButtonDown(HandleRef, Int32, Int32, Int32)
Noesis.View:MouseButtonDown(Int32, Int32, MouseButton) (at Assets/NoesisGUI/Plugins/API/Core/View.cs:126)
NoesisView:ProcessEvent(Event, Boolean, Boolean, Boolean) (at Assets/NoesisGUI/Plugins/NoesisView.cs:936)
NoesisView:OnGUI() (at Assets/NoesisGUI/Plugins/NoesisView.cs:1045)
BaseResearchItem contains the following properties.
  public string Name
  public string Description
  public Noesis.TextureSource Icon
BaseItem.get_Icon () (at Assets/Scripts/BaseItem/BaseItem.cs:64)
62    [SerializeField]
63    private Texture2D _icon = null;
64    public Noesis.TextureSource Icon { get { return _icon.EncodeToNoesisImage(); } }

    public static Noesis.TextureSource EncodeToNoesisImage(this Texture2D texture)
    {
        return new Noesis.TextureSource(texture);
    }
at Assets/GUI/ScienceWindowViewModel.cs:87
77        private BaseResearchItem _selectedResearchItem;
78        public BaseResearchItem SelectedResearchItem
79       {
80           get
81            {
82              return _selectedResearchItem;
83            }
84            set
85            {
86                _selectedResearchItem = value;
87               OnPropertyChanged("SelectedResearchItem");
88            }
90        }
Before the mistake.
Image
After an error.
Image

Tags:
 
danrer
Topic Author
Posts: 10
Joined: 27 Apr 2019, 18:20

Re: [ERROR] An item with the same key has already been added.

05 Jan 2020, 02:09

Found in a bag tracker, already decided, I will wait for a new version. The topic can be closed or deleted.
 
User avatar
sfernandez
Site Admin
Posts: 1777
Joined: 22 Dec 2011, 19:20

Re: [ERROR] An item with the same key has already been added.

05 Jan 2020, 14:14

Yes, this seems the same bug as the one described here: #1607.
It will appear fixed in the next release, thanks for reporting anyway.

Who is online

Users browsing this forum: No registered users and 17 guests