diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs index 5b3f003d394d5..f69d99e02a9ec 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs @@ -1142,7 +1142,7 @@ public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] nam throw new ArgumentNullException(nameof(names)); if (names.Length == 0) - throw new ArgumentException(); + throw new ArgumentException(SR.Arg_EmptyArray, nameof(names)); for (int i = 0; i < names.Length; i++) if (names[i] == null) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 5449ed66b9444..74ea5902d7e71 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -2402,7 +2402,7 @@ ILGenerator usage is invalid. - MSIL instruction is invalid or index is out of bounds. + Opcodes using a short-form index cannot address a local position over 255. Interface must be declared abstract. @@ -2927,7 +2927,7 @@ Cannot resolve {0} to a TypeInfo object. - This feature is not currently implemented. + This feature is not implemented. Found an obsolete .resources file in assembly '{0}'. Rebuild that .resources file then rebuild that assembly. diff --git a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineGenericParameters.cs b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineGenericParameters.cs index 40e1efc2f8b86..5c20a1ddc4e37 100644 --- a/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineGenericParameters.cs +++ b/src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineGenericParameters.cs @@ -62,7 +62,7 @@ public void DefineGenericParameters_NullNames_ThrowsArgumentNullException() public void DefineGenericParameters_EmptyNames_ThrowsArgumentException() { TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public); - AssertExtensions.Throws(null, () => type.DefineGenericParameters(new string[0])); + AssertExtensions.Throws("names", () => type.DefineGenericParameters(new string[0])); } [Fact] diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs index bfbed4dd48925..3ab22d87a1df2 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs @@ -383,7 +383,7 @@ public object GetValue(int index) var lb = GetLowerBound(0); if (index < lb || index > GetUpperBound(0)) - throw new IndexOutOfRangeException("Index has to be between upper and lower bound of the array."); + throw new IndexOutOfRangeException(SR.Argument_IndexOutOfArrayBounds); if (GetType().GetElementType()!.IsPointer) throw new NotSupportedException(SR.NotSupported_Type); @@ -430,7 +430,7 @@ public void SetValue(object? value, int index) var lb = GetLowerBound(0); if (index < lb || index > GetUpperBound(0)) - throw new IndexOutOfRangeException("Index has to be >= lower bound and <= upper bound of the array."); + throw new IndexOutOfRangeException(SR.Argument_IndexOutOfArrayBounds); if (GetType().GetElementType()!.IsPointer) throw new NotSupportedException(SR.NotSupported_Type); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs index 3fde27fb5335c..0c6bfc8f87fd7 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs @@ -719,7 +719,7 @@ private static AttributeUsageAttribute RetrieveAttributeUsageNoCache(Type attrib // anyone from using IL ofcourse if (attribs.Length > 1) { - throw new FormatException("Duplicate AttributeUsageAttribute cannot be specified on an attribute type."); + throw new FormatException(SR.Format(SR.Format_AttributeUsage, attributeType.GetType().FullName)); } return ((AttributeUsageAttribute)attribs[0]); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs index 6f9c751d1da7b..b09c804795457 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs @@ -184,17 +184,18 @@ private void Initialize(ConstructorInfo con, object[] constructorArgs, if (fieldValues == null) throw new ArgumentNullException(nameof(fieldValues)); if (con.GetParametersCount() != constructorArgs.Length) - throw new ArgumentException("Parameter count does not match " + - "passed in argument value count."); + throw new ArgumentException(SR.Argument_BadParameterCountsForConstructor); if (namedProperties.Length != propertyValues.Length) - throw new ArgumentException("Array lengths must be the same.", - "namedProperties, propertyValues"); + throw new ArgumentException(SR.Arg_ArrayLengthsDiffer, "namedProperties, propertyValues"); if (namedFields.Length != fieldValues.Length) - throw new ArgumentException("Array lengths must be the same.", - "namedFields, fieldValues"); + throw new ArgumentException(SR.Arg_ArrayLengthsDiffer, "namedFields, fieldValues"); if ((con.Attributes & MethodAttributes.Static) == MethodAttributes.Static || (con.Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private) - throw new ArgumentException("Cannot have private or static constructor."); + throw new ArgumentException(SR.Argument_BadConstructor); + + // Here coreclr does + // if ((con.CallingConvention & CallingConventions.Standard) != CallingConventions.Standard) + // throw new ArgumentException(SR.Argument_BadConstructorCallConv); Type atype = ctor.DeclaringType; int i; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs index 507f4c302ae16..1ea2a264c4a8c 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.Mono.cs @@ -344,7 +344,7 @@ protected override PropertyInfo GetPropertyImpl( Type returnType, Type[] types, ParameterModifier[] modifiers) { - throw CreateNotSupportedException(); + throw new NotSupportedException(SR.NotSupported_DynamicModule); } protected override bool HasElementTypeImpl() @@ -438,11 +438,6 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute)); } - private Exception CreateNotSupportedException() - { - return new NotSupportedException("The invoked member is not supported in a dynamic module."); - } - internal override bool IsUserType { get diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs index 17ef8ec60eb7c..7c58831b56741 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs @@ -163,7 +163,7 @@ public void SetConstant(object defaultValue) RejectIfCreated(); /*if (defaultValue.GetType() != type) - throw new ArgumentException ("Constant doesn't match field type");*/ + throw new ArgumentException("Constant doesn't match field type");*/ def_value = defaultValue; } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs index cbf4cf3aec829..7b292197106d5 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs @@ -675,11 +675,11 @@ public virtual void Emit(OpCode opcode, LocalBuilder local) if (local == null) throw new ArgumentNullException(nameof(local)); if (local.ilgen != this) - throw new ArgumentException("Trying to emit a local from a different ILGenerator."); + throw new ArgumentException(SR.Argument_UnmatchedMethodForLocal, nameof(local)); uint pos = local.position; if ((opcode == OpCodes.Ldloca_S || opcode == OpCodes.Ldloc_S || opcode == OpCodes.Stloc_S) && pos > 255) - throw new InvalidOperationException("Opcodes using a short-form index cannot address a local position over 255."); + throw new InvalidOperationException(SR.InvalidOperation_BadInstructionOrIndexOutOfBound); bool load_addr = false; bool is_store = false; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs index f9fe0b33632ed..15d95e1536e4f 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs @@ -624,7 +624,7 @@ public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] nam if (names == null) throw new ArgumentNullException(nameof(names)); if (names.Length == 0) - throw new ArgumentException("", nameof(names)); + throw new ArgumentException(SR.Arg_EmptyArray, nameof(names)); type.check_not_created(); generic_params = new GenericTypeParameterBuilder[names.Length]; for (int i = 0; i < names.Length; i++) diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs index 75eb11e19b7f1..d8387937498c1 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs @@ -415,7 +415,7 @@ public override Type GetType(string className, bool throwOnError, bool ignoreCas if (className == null) throw new ArgumentNullException(nameof(className)); if (className.Length == 0) - throw new ArgumentException("className"); + throw new ArgumentException(SR.Argument_EmptyName, nameof(className)); TypeBuilder result = null; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs index 573f1619d0228..666c1103abbb1 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs @@ -101,7 +101,7 @@ internal TypeBuilder(ModuleBuilder mb, TypeAttributes attr, int table_idx) pmodule = mb; } - internal TypeBuilder(ModuleBuilder mb, string name, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packing_size, int type_size, Type nesting_type) + internal TypeBuilder(ModuleBuilder mb, string fullname, TypeAttributes attr, Type parent, Type[] interfaces, PackingSize packing_size, int type_size, Type nesting_type) { int sep_index; this.parent = ResolveUserType(parent); @@ -110,20 +110,20 @@ internal TypeBuilder(ModuleBuilder mb, string name, TypeAttributes attr, Type pa this.packing_size = packing_size; this.nesting_type = nesting_type; - check_name("fullname", name); + check_name(nameof(fullname), fullname); if (parent == null && (attr & TypeAttributes.Interface) != 0 && (attr & TypeAttributes.Abstract) == 0) - throw new InvalidOperationException("Interface must be declared abstract."); + throw new InvalidOperationException(SR.InvalidOperation_BadInterfaceNotAbstract); - sep_index = name.LastIndexOf('.'); + sep_index = fullname.LastIndexOf('.'); if (sep_index != -1) { - this.tname = name.Substring(sep_index + 1); - this.nspace = name.Substring(0, sep_index); + this.tname = fullname.Substring(sep_index + 1); + this.nspace = fullname.Substring(0, sep_index); } else { - this.tname = name; + this.tname = fullname; this.nspace = string.Empty; } if (interfaces != null) @@ -138,7 +138,7 @@ internal TypeBuilder(ModuleBuilder mb, string name, TypeAttributes attr, Type pa // skip . ? table_idx = mb.get_next_table_index(this, 0x02, 1); - fullname = GetFullName(); + this.fullname = GetFullName(); } public override Assembly Assembly @@ -396,7 +396,7 @@ private TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type pare /* This breaks mcs if (((attrs & TypeAttributes.VisibilityMask) == TypeAttributes.Public) || ((attrs & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic)) - throw new ArgumentException ("attr", "Bad type flags for nested type."); + throw new ArgumentException (nameof(attr), "Bad type flags for nested type."); */ if (interfaces != null) { @@ -555,7 +555,7 @@ public MethodBuilder DefineMethod(string name, MethodAttributes attributes, Call public MethodBuilder DefineMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers) { - check_name("name", name); + check_name(nameof(name), name); check_not_created(); if (IsInterface && ( !((attributes & MethodAttributes.Abstract) != 0) || @@ -596,9 +596,9 @@ public MethodBuilder DefinePInvokeMethod( CallingConvention nativeCallConv, CharSet nativeCharSet) { - check_name("name", name); - check_name("dllName", dllName); - check_name("entryName", entryName); + check_name(nameof(name), name); + check_name(nameof(dllName), dllName); + check_name(nameof(entryName), entryName); if ((attributes & MethodAttributes.Abstract) != 0) throw new ArgumentException("PInvoke methods must be static and native and cannot be abstract."); if (IsInterface) @@ -665,7 +665,7 @@ public FieldBuilder DefineField(string fieldName, Type type, FieldAttributes att public FieldBuilder DefineField(string fieldName, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes) { - check_name("fieldName", fieldName); + check_name(nameof(fieldName), fieldName); if (type == typeof(void)) throw new ArgumentException("Bad field type in defining field."); check_not_created(); @@ -715,7 +715,7 @@ public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers) { - check_name("name", name); + check_name(nameof(name), name); if (parameterTypes != null) foreach (Type param in parameterTypes) if (param == null) @@ -1544,12 +1544,12 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) public EventBuilder DefineEvent(string name, EventAttributes attributes, Type eventtype) { - check_name("name", name); + check_name(nameof(name), name); if (eventtype == null) throw new ArgumentNullException("type"); check_not_created(); if (eventtype.IsByRef) - throw new ArgumentException(nameof(eventtype)); + throw new ArgumentException(SR.Argument_CannotGetTypeTokenForByRef); EventBuilder res = new EventBuilder(this, name, attributes, eventtype); if (events != null) { @@ -1689,10 +1689,8 @@ private void check_name(string argName, string name) { if (name == null) throw new ArgumentNullException(argName); - if (name.Length == 0) - throw new ArgumentException("Empty name is not legal", argName); - if (name[0] == ((char)0)) - throw new ArgumentException("Illegal name", argName); + if (name.Length == 0 || name[0] == ((char)0)) + throw new ArgumentException(SR.Argument_EmptyName, argName); } public override string ToString() @@ -1812,7 +1810,7 @@ public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] nam if (names == null) throw new ArgumentNullException(nameof(names)); if (names.Length == 0) - throw new ArgumentException("names"); + throw new ArgumentException(SR.Arg_EmptyArray, nameof(names)); generic_params = new GenericTypeParameterBuilder[names.Length]; for (int i = 0; i < names.Length; i++) diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs index a5cc6e15cd565..6971d467d8fb2 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs @@ -535,7 +535,7 @@ abstract class TypeBuilderInstantiation : TypeInfo { internal static Type MakeGenericType (Type type, Type[] typeArguments) { - throw new NotSupportedException ("User types are not supported under full aot"); + throw new NotSupportedException("User types are not supported under full aot"); } } }