Skip to content

Commit d3d1f28

Browse files
jkotasgewarren
andauthored
Document FieldInfo.SetValue breaking change (#3869)
* Document FieldInfo.SetValue breaking change * Apply suggestions from code review Co-Authored-By: Genevieve Warren <[email protected]> * Apply suggestions from code review Add comma * Apply suggestions from code review Co-authored-by: Genevieve Warren <[email protected]>
1 parent 5a94d09 commit d3d1f28

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

xml/System.Reflection/FieldInfo.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,8 @@
21022102
## Remarks
21032103
This method will assign `value` to the field reflected by this instance on object `obj`. If the field is static, `obj` will be ignored. For non-static fields, `obj` should be an instance of a class that inherits or declares the field. The new value is passed as an `Object`. For example, if the field's type is Boolean, an instance of `Object` with the appropriate Boolean value is passed. Before setting the value, `SetValue` checks to see if the user has access permission. This final method is a convenience method for calling the following `SetValue` method.
21042104
2105+
This method cannot be used to set values of static, init-only (`readonly` in C#) fields reliably. In .NET Core 3.0 and later versions, an exception is thrown if you attempt to set a value on a static, init-only field.
2106+
21052107
> [!NOTE]
21062108
> Fully trusted code has the permissions that are needed to access and invoke private constructors, methods, fields, and properties using reflection.
21072109
@@ -2200,6 +2202,8 @@
22002202
22012203
## Remarks
22022204
This method will assign `value` to the field reflected by this instance on `obj`. If the field is static, `obj` will be ignored. For non-static fields, `obj` should be an instance of a class that inherits or declares the field. The new value is passed as an `Object`. For example, if the field's type is `Boolean`, an instance of `Object` with the appropriate Boolean value is passed. Before setting the value, `SetValue` checks to see if the user has access permission.
2205+
2206+
This method cannot be used to set values of static, init-only (`readonly` in C#) fields reliably. In .NET Core 3.0 and later versions, an exception is thrown if you attempt to set a value on a static, init-only field.
22032207
22042208
> [!NOTE]
22052209
> Fully trusted code has the permissions that are needed to access and invoke private constructors, methods, fields, and properties using reflection.

0 commit comments

Comments
 (0)