Why Custom Attributes in .NET Give Me Nightmares
2 days ago
- #.NET
- #Metadata
- #Custom Attributes
- The author criticizes .NET's custom attribute storage mechanism as poorly designed, causing significant issues.
- Custom attributes are metadata attached to .NET binaries, stored in metadata tables with a blob signature for arguments.
- Enum arguments in custom attributes require expensive type resolution to determine underlying types, adding complexity and overhead.
- Type arguments in custom attributes use fully qualified name (FQN) strings, which are inefficient and avoid deduplication, unlike other .NET signatures.
- FQN strings lead to bloated binary sizes, slower parsing, and inconsistent type resolution behaviors due to complex syntax and optional assembly specifiers.
- The design choices for custom attributes deviate from .NET's efficient metadata table system, but changes are unlikely due to backward compatibility concerns.