I am facing a weird exception: Google cannot find anything about it (which is quite rare).
The code:
new Query<TElement>(/* ... arguments ...*/);
Thew an exception
System.TypeLoadException
Collectible type 'L.Caching.Query`1[<>transientClass1]' may not have Thread or Context static members.
I finally solved that issue, but this worth telling a bit google about it! (I will answer this question)
Let me put things in their context:
- I am calling the "new" that threw the exception from a runtime compiled lambda.
- The class taking place of TElement, e.g.
<>transientClass1
, is a dynamically generated class (using Reflection.Emit) - quite inofensive: it is the equivalent of what generates the compiler when writing an anonymous typenew{a=thing, b=otherThing}
- This "anonmyous" class works well in many other parts of my application (dont think about wrong IL emission)
Query<T>
is just another generic class.
What could cause that exception ?