From 6d42097fbd5a5115e3f6f4a7cb6cef40453562be Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 10 Feb 2020 17:36:54 -0800 Subject: [PATCH 1/4] Document FieldInfo.SetValue breaking change --- xml/System.Reflection/FieldInfo.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xml/System.Reflection/FieldInfo.xml b/xml/System.Reflection/FieldInfo.xml index 5b26f6cae63..cafd79bbfa6 100644 --- a/xml/System.Reflection/FieldInfo.xml +++ b/xml/System.Reflection/FieldInfo.xml @@ -2096,6 +2096,8 @@ ## Remarks 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. + This method cannot be used to set value of static init-only (`readonly` in C#) fields reliably. In .NET Core 3.0+, attempt to set value of static init-only field causes exception to be thrown. + > [!NOTE] > Fully trusted code has the permissions that are needed to access and invoke private constructors, methods, fields, and properties using reflection. @@ -2195,6 +2197,8 @@ ## Remarks 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. + + This method cannot be used to set value of static init-only (`readonly` in C#) fields reliably. In .NET Core 3.0+, attempt to set value of static init-only field causes exception to be thrown. > [!NOTE] > Fully trusted code has the permissions that are needed to access and invoke private constructors, methods, fields, and properties using reflection. From a1387b3b7cd481786bbd2bee476b5bf00c390600 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 12 Feb 2020 13:19:12 -0800 Subject: [PATCH 2/4] Apply suggestions from code review Co-Authored-By: Genevieve Warren --- xml/System.Reflection/FieldInfo.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xml/System.Reflection/FieldInfo.xml b/xml/System.Reflection/FieldInfo.xml index cafd79bbfa6..2f7f6bcf6d0 100644 --- a/xml/System.Reflection/FieldInfo.xml +++ b/xml/System.Reflection/FieldInfo.xml @@ -2096,7 +2096,7 @@ ## Remarks 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. - This method cannot be used to set value of static init-only (`readonly` in C#) fields reliably. In .NET Core 3.0+, attempt to set value of static init-only field causes exception to be thrown. +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. > [!NOTE] > Fully trusted code has the permissions that are needed to access and invoke private constructors, methods, fields, and properties using reflection. @@ -2198,7 +2198,7 @@ ## Remarks 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. - This method cannot be used to set value of static init-only (`readonly` in C#) fields reliably. In .NET Core 3.0+, attempt to set value of static init-only field causes exception to be thrown. +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. > [!NOTE] > Fully trusted code has the permissions that are needed to access and invoke private constructors, methods, fields, and properties using reflection. From f60a0b15031390faa73d229fc7c12b5c0aaf8b61 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 13 Feb 2020 10:31:57 -0800 Subject: [PATCH 3/4] Apply suggestions from code review Add comma --- xml/System.Reflection/FieldInfo.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xml/System.Reflection/FieldInfo.xml b/xml/System.Reflection/FieldInfo.xml index 2f7f6bcf6d0..cf26d6c01db 100644 --- a/xml/System.Reflection/FieldInfo.xml +++ b/xml/System.Reflection/FieldInfo.xml @@ -2096,7 +2096,7 @@ ## Remarks 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. -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. +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. > [!NOTE] > Fully trusted code has the permissions that are needed to access and invoke private constructors, methods, fields, and properties using reflection. @@ -2198,7 +2198,7 @@ This method cannot be used to set values of static init-only (`readonly` in C#) ## Remarks 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. -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. +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. > [!NOTE] > Fully trusted code has the permissions that are needed to access and invoke private constructors, methods, fields, and properties using reflection. From 890254727abfdd07815980ee26bc71ee1372e751 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 13 Feb 2020 10:33:34 -0800 Subject: [PATCH 4/4] Apply suggestions from code review --- xml/System.Reflection/FieldInfo.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xml/System.Reflection/FieldInfo.xml b/xml/System.Reflection/FieldInfo.xml index cf26d6c01db..0846cfa9a65 100644 --- a/xml/System.Reflection/FieldInfo.xml +++ b/xml/System.Reflection/FieldInfo.xml @@ -2096,7 +2096,7 @@ ## Remarks 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. -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. +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. > [!NOTE] > Fully trusted code has the permissions that are needed to access and invoke private constructors, methods, fields, and properties using reflection. @@ -2198,7 +2198,7 @@ This method cannot be used to set values of static init-only (`readonly` in C#) ## Remarks 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. -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. +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. > [!NOTE] > Fully trusted code has the permissions that are needed to access and invoke private constructors, methods, fields, and properties using reflection.