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
This document provides a list of .NET APIs that should not be used or should be used with caution in thread-safe tasks. These APIs are problematic because they either rely on or modify process-level state, which can cause race conditions in multithreaded execution.
The APIs listed in this document will be detected by Roslyn analyzers and/or MSBuild BuildCheck to help identify potential threading issues in tasks that implement IMultiThreadableTask.
Note: The analyzers rely on static code analysis and may not catch all dynamic scenarios (such as reflection-based API calls).
API Issues Categories
Categories of threading issues with .NET API usage in thread-safe tasks to be aware of:
Working Directory Modifications and Usage, such as file system operations with relative paths.
Environment Variables Modification and Usage
Process Culture Modification and Usage, which can affect data formatting.
Assembly Loading
Static Fields
Best Practices
Instead of the problematic APIs listed below, thread-safe tasks should:
Use TaskEnvironment for all file system operations, environment variable changes, and working directory changes.
Always use absolute paths when still using some standard .NET file system APIs.
Explicitly configure external processes using TaskEnvironment.
Never modify process culture: Avoid modifying culture defaults.
Detailed API Reference
The following tables list specific .NET APIs and their threading safety classification:
Tasks that load assemblies dynamically in the task host may cause version conflicts. Version conflicts in task assemblies will cause build failures (previously these might have been sporadic). Both dynamically loaded dependencies and static dependencies can cause issues.
API
Level
Short Reason
Recommendation
Assembly.LoadFrom(string assemblyFile)
WARNING
May cause version conflicts
Be aware of potential conflicts, use absolute paths