Skip to content

TypeDescriptor.Refresh is not thread-safe #51618

@stephentoub

Description

@stephentoub

In general, static methods are supposed to be thread-safe, and there's no warning in the docs about it not being so.

But TypeDescriptor.Refresh may end up calling into ReflectTypeDescriptionProvider.GetPopulatedTypes. It does so while holding a lock GetPopulatedTypes enumerates the _typeData Hashtable. If a concurrent call to GetTypeData (which takes a different lock) mutates that hashtable, it invalidates the enumerator being used by GetPopulatedTypes, causing GetPopulatedTypes to throw an exception.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions