generic-serializable-dictionary: InvalidOperationException: EnsureRunningOnMainThread can only be called from the main thread
Hi, I get this error when working with your class. Until now it works fine, and I can’t see where is the problem (I mean, I think I commented all the last changes before the error appears but still keep there…). Do you think there is some solution in your class? Here is the full stack error. Thank you.
InvalidOperationException: EnsureRunningOnMainThread can only be called from the main thread
UnityEngine.Object.EnsureRunningOnMainThread () (at <c6b52566f59b49fc861a7812a1ea2f6b>:0)
UnityEngine.Object.GetInstanceID () (at <c6b52566f59b49fc861a7812a1ea2f6b>:0)
UnityEngine.Object.IsNativeObjectAlive (UnityEngine.Object o) (at <c6b52566f59b49fc861a7812a1ea2f6b>:0)
UnityEngine.Object.CompareBaseObjects (UnityEngine.Object lhs, UnityEngine.Object rhs) (at <c6b52566f59b49fc861a7812a1ea2f6b>:0)
UnityEngine.Object.op_Equality (UnityEngine.Object x, UnityEngine.Object y) (at <c6b52566f59b49fc861a7812a1ea2f6b>:0)
UnityEngine.Object.Equals (System.Object other) (at <c6b52566f59b49fc861a7812a1ea2f6b>:0)
System.Collections.Generic.ObjectEqualityComparer1[T].Equals (T x, T y) (at <c2a97e0383e8404c9fc0ae19d58f57f1>:0) System.Collections.Generic.Dictionary2[TKey,TValue].FindEntry (TKey key) (at <c2a97e0383e8404c9fc0ae19d58f57f1>:0)
System.Collections.Generic.Dictionary2[TKey,TValue].ContainsKey (TKey key) (at <c2a97e0383e8404c9fc0ae19d58f57f1>:0) GenericDictionary2[TKey,TValue].ContainsKey (TKey key) (at Assets/Code/Libraries/GenericDictionary.cs:92)
GenericDictionary`2[TKey,TValue].OnAfterDeserialize () (at Assets/Code/Libraries/GenericDictionary.cs:50)
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 19 (8 by maintainers)
I’ve kept this issue open since I suspected there was some issue with static initialization. I don’t use singletons so haven’t encountered this issue myself, but sounds like it’s pretty tricky to reproduce since it doesn’t occur immediately.
Ok, can be… If I can reproduce the bug anyway I’ll advice you. Thank you for all 😃
Hey again! I cannot reproduce it. If I were you I would try to narrow down what’s causing the error. I suspect it could be the TextMeshProUGUI values in the dictionary, but could be anything. So best bet is to backup your work in source control and then replace all object types with primitive types one by one, to check if the problem goes away and if so what caused it.
For instance
Will become
and so on…
This should help narrow down the problem into exactly what is breaking it.
Thanks for getting back, I’ll have some time to reproduce this in a couple of hours and get back to you!