I’m experiencing a 100% reproducible Unity crash.
The following doesn’t crash but accessing the result IEnumerator later on does:
typeof(MyBaseClass).Assembly.GetTypes()
.SelectMany(type => type.GetFields())
.SelectMany(field => field.GetCustomAttributes(false));
I’ve managed to debug the content of the collection and it has the right amount of attributes found (based on the times I’ve added them in the code, 3) and if I add a breakpoint I’m able to see the content of the first attribute found, which it has the right values.
But if I iterate through the result IEnumerable more than once or if I cast the collection to List, for example, Unity crashes. Even if I hover the mouse over the IEnumerator in the foreach loop (using Visual Studio) unity crashes too, which is weird. It also takes forever to access this data. I’d assume the most consuming task is to search for them.
I’ve tried to run this in the editor and play mode, single and multi threaded, Unity 5.6 and 2017.2, .Net 4.6 and 3.5, Mono and il2cpp, I’ve even replaced the linq queries with for loops… It doesn’t matter.
I’m experiencing this issue when I try to find the attributes associated with a certain type too. It doesn’t happen when I search by method though.
Hope it makes sense. This is driving me crazy, hope you can see what I’m doing wrong.
Thanks.