add field Name to exception (#17668)
authorMarco Rossignoli <marco.rossignoli@gmail.com>
Thu, 19 Apr 2018 16:54:09 +0000 (18:54 +0200)
committerDan Moseley <danmose@microsoft.com>
Thu, 19 Apr 2018 16:54:09 +0000 (12:54 -0400)
src/mscorlib/Resources/Strings.resx
src/mscorlib/src/System/TypedReference.cs

index 2b7c9f5..29ebb33 100644 (file)
     <value>A null or zero length string does not represent a valid Type.</value>
   </data>
   <data name="Arg_TypeRefPrimitve" xml:space="preserve">
-    <value>TypedReferences cannot be redefined as primitives.</value>
+    <value>TypedReferences cannot be redefined as primitives. Field name '{0}'.</value>
   </data>
   <data name="Arg_TypeUnloadedException" xml:space="preserve">
     <value>Type had been unloaded.</value>
     <value>The DaylightTransitionStart property must not equal the DaylightTransitionEnd property.</value>
   </data>
   <data name="Argument_TypedReferenceInvalidField" xml:space="preserve">
-    <value>Field in TypedReferences cannot be static or init only.</value>
+    <value>Field '{0}' in TypedReferences cannot be static or init only.</value>
   </data>
   <data name="Argument_TypeIsWinRTType" xml:space="preserve">
     <value>The type must not be a Windows Runtime type.</value>
index 1a378d4..748f2db 100644 (file)
@@ -29,7 +29,7 @@ namespace System
             if (flds == null)
                 throw new ArgumentNullException(nameof(flds));
             if (flds.Length == 0)
-                throw new ArgumentException(SR.Arg_ArrayZeroError);
+                throw new ArgumentException(SR.Arg_ArrayZeroError, nameof(flds));
 
             IntPtr[] fields = new IntPtr[flds.Length];
             // For proper handling of Nullable<T> don't change GetType() to something like 'IsAssignableFrom'
@@ -42,14 +42,14 @@ namespace System
                     throw new ArgumentException(SR.Argument_MustBeRuntimeFieldInfo);
 
                 if (field.IsInitOnly || field.IsStatic)
-                    throw new ArgumentException(SR.Argument_TypedReferenceInvalidField);
+                    throw new ArgumentException(SR.Format(SR.Argument_TypedReferenceInvalidField, field.Name));
 
                 if (targetType != field.GetDeclaringTypeInternal() && !targetType.IsSubclassOf(field.GetDeclaringTypeInternal()))
                     throw new MissingMemberException(SR.MissingMemberTypeRef);
 
                 RuntimeType fieldType = (RuntimeType)field.FieldType;
                 if (fieldType.IsPrimitive)
-                    throw new ArgumentException(SR.Arg_TypeRefPrimitve);
+                    throw new ArgumentException(SR.Format(SR.Arg_TypeRefPrimitve, field.Name));
 
                 if (i < (flds.Length - 1) && !fieldType.IsValueType)
                     throw new MissingMemberException(SR.MissingMemberNestErr);