From edf9707a210aa223f8f7cff8ffb4f269e54832e5 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 26 Nov 2018 14:08:38 -0500 Subject: [PATCH] Remove TypedReference.MakeTypedReference readonly restriction (dotnet/coreclr#21193) TypedReference.MakeTypedReference validates that the fields aren't readonly, which limits our ability to make fields readonly in core while maintaining BinaryFormatter compatibility. This restriction isn't useful for a variety of reasons, though: reflection allows readonly fields to be set, but more importantly, TypedReference.SetTypedReference has always thrown NotSupportedException, so it's not even actually usable. This change just removes the readonly check from MakeTypedReference. Commit migrated from https://github.com/dotnet/coreclr/commit/a6729dab35fde5d50fb12b06aeb77d3e1f3be872 --- src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx | 2 +- src/coreclr/src/System.Private.CoreLib/src/System/TypedReference.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx b/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx index dcf61a0..9fa2e10 100644 --- a/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx +++ b/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx @@ -1499,7 +1499,7 @@ The DaylightTransitionStart property must not equal the DaylightTransitionEnd property. - Field '{0}' in TypedReferences cannot be static or init only. + Field '{0}' in TypedReferences cannot be static. The type must not be a Windows Runtime type. diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/TypedReference.cs b/src/coreclr/src/System.Private.CoreLib/src/System/TypedReference.cs index 3f5d5ac..152ba70 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/TypedReference.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/TypedReference.cs @@ -41,7 +41,7 @@ namespace System if (field == null) throw new ArgumentException(SR.Argument_MustBeRuntimeFieldInfo); - if (field.IsInitOnly || field.IsStatic) + if (field.IsStatic) throw new ArgumentException(SR.Format(SR.Argument_TypedReferenceInvalidField, field.Name)); if (targetType != field.GetDeclaringTypeInternal() && !targetType.IsSubclassOf(field.GetDeclaringTypeInternal())) -- 2.7.4