Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The System.Security.Cryptography.Oid class, which is used to represent ASN.1 Object Identifier values and their "friendly" names, was previously fully mutable. This mutability was often overlooked or came as a surprise. The property setters now throw a PlatformNotSupportedException when you attempt to change the value after it's already been assigned.
Change description
In previous versions, the property setters on Oid can be used to change the value of the FriendlyName and Value properties.
In .NET 5 and later versions, the property setters can only be used to initialize the value. Once the property has a value, either from a constructor or a previous call to the property setter, the property setter always throws a PlatformNotSupportedException.
Reason for change
This change enables the reuse of Oid objects as part of return values in public APIs to reduce object allocation profiles. It avoids the need to create temporary "defensive" copies when Oid values are used as inputs.
Version introduced
5.0
Recommended action
Avoid using the Oid property setters other than for object initialization. To represent a new value, use a new instance instead of changing the value on an existing object.