You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unhandled Exception: System.TypeLoadException: Collectible type 'MyType`1[Dummy]' may not have Thread or Context static members.
at System.RuntimeType.MakeGenericType(Type[] instantiation)
at Repro.Main() in Program.cs:line 22
This means that a developer writing a general-purpose library with generic types can't use [ThreadStatic] because it would break a consumer of the library, and/or that a developer writing a collectible assembly needs to know the implementation details of generic types being used. Neither of those is very good.
As a perf improvement awhile back, ImmutableList<T> took a dependency on [ThreadStatic]. This unfortunately breaks cases where ImmutableList<T> is used with a T from a collectible assembly, due to https://github.com/dotnet/coreclr/issues/2191.
Until that limitation is removed, this provides a workaround to restore the ability to use ImmutableList<T> with such types. Some microbenchmarks around enumeration (which this was originally introduced to help with) show potential throughput regressions up to 10-15%.
// Workaround for https://github.com/dotnet/runtime/issues/4731.// When that's fixed, a [ThreadStatic] Stack should be added back to AllocFreeConcurrentStack<T>.[ThreadStatic]internalstaticDictionary<Type,object>? t_stacks;
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
See the discussion at dotnet/corefx@b460c27#commitcomment-14671045.
Example:
fails with:
This means that a developer writing a general-purpose library with generic types can't use [ThreadStatic] because it would break a consumer of the library, and/or that a developer writing a collectible assembly needs to know the implementation details of generic types being used. Neither of those is very good.
Related to https://github.com/dotnet/corefx/issues/4726.
The text was updated successfully, but these errors were encountered: