From 0d46864f82398ad9cffe516e8f1953b2a8ebb896 Mon Sep 17 00:00:00 2001 From: databunks Date: Mon, 14 Nov 2022 20:59:09 +0000 Subject: [PATCH 01/22] swapping exception strings from resx file --- .../src/Resources/Strings.resx | 299 +++++++++++++++++- .../src/Mono/HotReload.cs | 4 +- .../src/System/ArgIterator.cs | 8 +- .../src/System/Delegate.Mono.cs | 2 +- .../src/System/Reflection/CustomAttribute.cs | 14 +- .../Emit/ConstructorBuilder.Mono.cs | 12 +- .../Emit/CustomAttributeBuilder.Mono.cs | 44 +-- .../Reflection/Emit/DerivedTypes.Mono.cs | 8 +- .../Reflection/Emit/DynamicMethod.Mono.cs | 2 +- .../Reflection/Emit/EventBuilder.Mono.cs | 2 +- .../Reflection/Emit/FieldBuilder.Mono.cs | 8 +- .../Reflection/Emit/ILGenerator.Mono.cs | 36 +-- .../Reflection/Emit/MethodBuilder.Mono.cs | 12 +- .../Emit/MethodOnTypeBuilderInst.cs | 4 +- .../Reflection/Emit/ModuleBuilder.Mono.cs | 30 +- .../Reflection/Emit/PropertyBuilder.Mono.cs | 2 +- .../System/Reflection/Emit/SignatureHelper.cs | 18 +- .../Reflection/Emit/TypeBuilder.Mono.cs | 69 ++-- .../Emit/TypeBuilderInstantiation.cs | 2 +- .../src/System/Reflection/FieldInfo.Mono.cs | 2 +- .../src/System/Reflection/RuntimeEventInfo.cs | 4 +- .../src/System/Reflection/RuntimeFieldInfo.cs | 18 +- .../Reflection/RuntimeMethodInfo.Mono.cs | 8 +- .../System/Reflection/RuntimeParameterInfo.cs | 2 +- .../System/Reflection/RuntimePropertyInfo.cs | 6 +- .../CompilerServices/RuntimeHelpers.Mono.cs | 4 +- .../src/System/RuntimeType.Mono.cs | 14 +- .../src/System/RuntimeTypeHandle.cs | 6 +- .../src/System/Threading/Monitor.Mono.cs | 6 +- .../src/System/Type.Mono.cs | 6 +- .../src/System/TypeSpec.cs | 36 +-- 31 files changed, 477 insertions(+), 211 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 762886be5e9f36..b3d0d8ff998821 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -280,6 +280,9 @@ Delegates must be of the same type. + + DllName cannot be empty. + Dll was not found. @@ -325,6 +328,9 @@ External component has thrown an exception. + + EnC: Expected a primitive, valuetype, class or interface field + Attempted to access a field that is not accessible by the caller. @@ -352,6 +358,9 @@ One of the identified items was in an invalid format. + + Generic arguments after array spec or pointer type + Method must be called on a Type for which Type.IsGenericParameter is false. @@ -648,6 +657,9 @@ Object reference not set to an instance of an object. + + Type handle was null {0}. + Object type cannot be converted to target type. @@ -834,11 +846,17 @@ 'handle' has already been bound to the thread pool, or was not opened for asynchronous I/O. + + Array spec cannot have 2 bound dimensions. + Interface maps for generic interfaces on arrays cannot be retrieved. - Array or pointer types are not valid. + Array or pointer types are not valid. Name: {0}. + + + Error parsing array spec. Attribute names must be unique. @@ -912,12 +930,28 @@ An invalid type was used as a custom attribute constructor argument, field or property. + + An invalid type was used as a custom attribute constructor argument, field or property. + + + + Cannot create an array type of a byref type. + + + Can't have a pointer to a byref type. + Cannot use function evaluation to create a TypedReference object. Cannot set parent to an interface. + + Can't have a byref of a byref. + + + Can't have a pointer to a byref type + {0} is not a supported code page. @@ -940,7 +974,10 @@ Null is not a valid constant value for this type. - The specified constructor must be declared on a generic type definition. + The specified constructor must be declared on a generic type definition. Name of constructor: {0}. + + + Constructor not found. Conversion buffer overflow. @@ -972,9 +1009,15 @@ Resolved assembly's simple name should be the same as of the requested assembly. + + Cannot emit a CustomAttribute with argument of type {0}. + Customized cultures cannot be passed by LCID, only by name. + + Custom modifiers length `{0}' does not match the size of the arguments. + The binary data must result in a DateTime with ticks between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. @@ -1035,14 +1078,29 @@ The argument type, '{0}', is not the same as the enum type '{1}'. + + Do not supply an exception type for filter clause. + Cannot change fallback when buffer is not empty. Previous Convert() call left data in the fallback buffer. Cannot resolve field {0} because the declaring type of the field handle {1} is generic. Explicitly provide the declaring type to GetFieldFromHandle. + + Field {0} does not belong to the same class as the constructor + + + Field {0} does not have a valid type. + + + Field {0} does not have a valid value. + + + The field handle and the type handle are incompatible. + - The specified field must be declared on a generic type definition. + The specified field must be declared on a generic type definition. Name of field: {0} GenericArguments[{0}], '{1}', on '{2}' violates the constraint of type '{3}'. @@ -1050,9 +1108,24 @@ The number of generic arguments provided doesn't equal the arity of the generic type definition. + + The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter. Name of type arguments: {2} + + + Generic argument can't be byref or pointer type. + Generic types are not valid. + + Error parsing generic params spec. + + + Open Generic Type not permitted. Name: {0} + + + Get Method not found for '{Name}' + Global members must be static. @@ -1089,6 +1162,12 @@ The specified index is out of bounds of the specified array. + + The property handle and the type handle are incompatible. + + + Incorrect length {0}. + 'this' type cannot be an interface itself. @@ -1110,8 +1189,11 @@ Length of the array must be {0}. - - Target array type is not compatible with the type of items in the collection. + + Array type is invalid. + + + Invalid array spec, multi-dimensional array cannot be bound. The given assembly name was invalid. @@ -1119,6 +1201,9 @@ Not a valid calendar for the given culture. + + "Invalid character in array spec: {0} + Invalid Unicode code point found at index {0}. @@ -1132,7 +1217,7 @@ Unable to translate Unicode character \\u{0:X4} at index {1} to specified code page. - The specified constructor must be declared on the generic type definition of the specified type. + The specified constructor must be declared on the generic type definition of the specified type. Name of type: {0} The ConstructorInfo object is not valid. @@ -1175,7 +1260,7 @@ The value '{0}' is not valid for this usage of the type {1}. - The specified field must be declared on the generic type definition of the specified type. + The specified field must be declared on the generic type definition of the specified type. Name of type: {0} Combining FileMode: {0} with FileAccess: {1} is invalid. @@ -1184,7 +1269,10 @@ Value of flags is invalid. - The generic type parameter was not valid + Invalid generic arguments spec + + + Invalid generic arguments separator {0} Generic arguments must be provided for each generic parameter and each generic argument must be a RuntimeType. @@ -1249,6 +1337,9 @@ Null character in path. + + Elements of the parameterTypes array cannot be null. Name of parameter type: {0}. + The given culture name '{0}' cannot be used to locate a resource file. Resource filenames must consist of only letters, numbers, hyphens or underscores. @@ -1291,18 +1382,30 @@ Integer or token was too large to be encoded. + + Label #{0} is not marked in method `{1}' + Environment variable name or value is too long. + + Method body must belong to this type. + Cannot resolve method {0} because the declaring type of the method handle {1} is generic. Explicitly provide the declaring type to GetMethodFromHandle. Method '{0}' has a generic declaring type '{1}'. Explicitly provide the declaring type to GetTokenFor. + + Method is not a generic method definition. + The specified method cannot be dynamic or global and must be declared on a generic type definition. + + Method {0} not found in type {1}. + '{0}' cannot be greater than {1}. @@ -1325,10 +1428,10 @@ MethodInfo must be a runtime MethodInfo object. - Type must be a runtime Type object. + Type must be a runtime Type object {0}. - 'type' must contain a TypeBuilder as a generic argument. + 'type' must contain a TypeBuilder as a generic argument. Name of builder type: {0}. Type passed in must be derived from System.Attribute or System.Attribute itself. @@ -1336,6 +1439,9 @@ The specified structure must be blittable or have layout information. + + Argument must be an interface {0}. + 'overlapped' has already been freed. @@ -1354,6 +1460,9 @@ The specified Type must be a struct containing no references. + + Negative field offset is not allowed. + The type '{0}' may not be used as a type argument. @@ -1420,9 +1529,24 @@ The DateStart property must come before the DateEnd property. + + Output streams do not support TypeBuilders. + Path cannot be the empty string or all whitespace. + + Value of argument {0} + does not match parameter type: {1} -> {2}. + + + Parameter {0} does not have a valid type. + + + Parameter {0} does not have a valid value. + + + Could not parse the type name: {0}. + 'preAllocated' is already in use. @@ -1465,6 +1589,9 @@ The initial count for the semaphore must be greater than or equal to zero and less than the maximum count. + + Set Method not found for '{0}'. + Should not specify exception type for catch clause for filter block. @@ -1510,6 +1637,12 @@ The specified type must be visible from COM. + + Type should be an exception type. Name of exception type: {0}. + + + Type should have a default constructor. Name of exception type: {0}. + The type must not be imported from COM. @@ -1519,6 +1652,9 @@ The type must be __ComObject or be derived from __ComObject. + + Unclosed assembly-qualified type name at {0} + The IL Generator cannot be used while there are unclosed exceptions. @@ -1526,11 +1662,20 @@ Unknown unmanaged calling convention for function signature. + Specified unmanaged type is only valid on fields. + + The UnmanagedMemoryAccessor capacity and offset would wrap around the high end of the address space. + + Value of field '{0}' does not match field type: {1} + Local passed in does not belong to this ILGenerator. + + Unmatched ']' while parsing generic argument assembly name + Non-matching symbol scope. @@ -1546,6 +1691,12 @@ The buffer is not associated with this pool and may not be returned to it. + + Interface not found {0}. + + + ModuleBuilder is expected. + The object is not an array with the same number of elements as the array to compare it to. @@ -1943,6 +2094,9 @@ The SyncRoot property may not be used for the synchronization of concurrent collections. + + Invalid custom attribute format. + Task {2} completed. @@ -2150,18 +2304,49 @@ Event {0} was called with a different type as defined (argument "{1}"). This may cause the event to be displayed incorrectly. + + Error in customattr. + + + + Custom attribute type '{0}' doesn't contain a field named '{1}' + --- End of inner exception stack trace --- --- End of stack trace from previous location --- + + Custom attribute length is only '{0}' + + + Prolog invalid. + + + Unknown element type '{0}'. + + + Unknown named type: {0} + + + Unknown MarshalAsAttribute field: {0}. + + + FIXME: Type {0} not yet handled in decode_cattr_value. + + + Subtype '{0}' of type object not yet handled in decode_cattr_value + Exception of type '{0}' was thrown. An exception was not handled in an AsyncLocal<T> notification callback. + + Cannot set a constant field + Could not resolve assembly '{0}'. @@ -2383,6 +2568,9 @@ Object cannot be stored in an array of this type. + + Type is concrete but has abstract method {0} + AsyncFlowControl objects can be used to restore flow only on a Context that had its flow suppressed. @@ -2401,6 +2589,9 @@ Interface must be declared abstract. + + Interface method must be abstract and virtual. + Method '{0}' cannot have a method body. @@ -2470,6 +2661,9 @@ The generic parameters are already defined on this MethodBuilder. + + can only be called in generic type. + OSVersion's call to GetVersionEx failed. @@ -2477,7 +2671,7 @@ Type definition of the global function has been completed. - Handle is not initialized. + Handle is not initialized. Name of type: {0} Handle is not pinned. @@ -2488,15 +2682,24 @@ Failed to compare two elements in the array. + + Iterator is at an invalid position + Type definition of the method is complete. The signature of the MethodBuilder can no longer be modified because an operation on the MethodBuilder caused the methodDef token to be created. For example, a call to SetCustomAttribute requires the methodDef token to emit the CustomAttribute token. + + Method '{0}' does not have a method body. + Method already has a body. + + Module-level methods cannot be retrieved until after the CreateGlobalFunctions method has been called for the module. + You must call Initialize on this object instance before using it. @@ -2546,6 +2749,9 @@ The requested operation is invalid when called on a null ModuleHandle. + + Object fields may not be properly initialized. + Local variable scope was not properly closed. @@ -2780,6 +2986,9 @@ Method '{0}.{1}' not found. + + Cannot create an abstract class '{0}'. + The satellite assembly named "{1}" for fallback culture "{0}" either could not be found or could not be loaded. This is generally a setup problem. Please consider reinstalling or repairing the application. @@ -2834,6 +3043,9 @@ A non-collectible assembly may not reference a collectible assembly. + + An element type cannot contain a stack pointer + CreateInstance cannot be used with an object of type TypeBuilder. @@ -2885,6 +3097,9 @@ Methods with UnmanagedCallersOnlyAttribute cannot be used as delegate target. + + User defined subclasses of System.Type are not yet supported. + No data is available for encoding {0}. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. @@ -2900,12 +3115,18 @@ Non-static methods with UnmanagedCallersOnlyAttribute are invalid. + + Mono does not currently support setting modOpt/modReq through SignatureHelper. + Parent does not have a default constructor. The default constructor must be explicitly defined. Cannot resolve {0} to a TypeInfo object. + + Not in an exception block + This feature is not implemented. @@ -2915,6 +3136,9 @@ The given Variant type is not supported by this OleAut function. + + Only Call and CallVirt are allowed + Cannot create arrays of open type. @@ -2975,6 +3199,9 @@ Stream does not support writing. + + User types are not supported under full aot. + Custom marshalers for value types are not currently supported. @@ -3314,6 +3541,9 @@ in {0}:line {1} + + Method cannot be invoked. + The specified TaskContinuationOptions combined LongRunning and ExecuteSynchronously. Synchronous continuations should not be long running. @@ -3452,6 +3682,15 @@ The type initializer for '{0}' threw an exception. + + Could not load type '{0}' from assembly '{1}' because it is an enum with methods + + + "Could not load type '{0}' from assembly '{1}' because it is implements the inaccessible interface '{2}'. + + + Could not load type '{0}' from assembly '{1}' because the parent type is sealed. + Could not resolve nested type '{0}' in type "{1}'. @@ -3584,6 +3823,9 @@ PInvoke methods cannot exist on interfaces. + + Bad type def, can't handle '{0}' at {1} + Method has been already defined. @@ -3599,6 +3841,21 @@ Precision cannot be larger than {0}. + + Property '{0}' does not belong to the same class as the constructor + + + Property '{0}' does not have a valid type. + + + Property {0} does not have a valid value. + + + "Property '{0}' does not have a setter. + + + "Value of property '{0}' does not match property type: {1} -> {2} + Cannot load hostpolicy library. AssemblyDependencyResolver is currently only supported if the runtime is hosted through hostpolicy library. @@ -3632,6 +3889,12 @@ Startup hook assembly '{0}' failed to load. See inner exception for details. + + Can't construct custom attribute for TypeBuilder type. + + + First argument to GetCustomAttributes can't be a TypeBuilder. + COM register function must be static. @@ -3890,12 +4153,18 @@ The feature associated with this method was removed. + + This method is not implemented for incomplete types. + The body of this instance method was removed by the AOT compiler. This can happen if the owning type was not seen as allocated by the AOT compiler. Attempted to load a type that was not created during ahead of time compilation. + + Field {0} defined on type {1} is not a field on the target object which is of type {2}. + A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property. @@ -3972,7 +4241,7 @@ Type names passed to Assembly.GetType() must not specify an assembly. - There is no metadata token available for the given member. + There is no metadata token available for the given member, MemberImplementationType: {0}. The type '{0}' may not be used as a type argument. @@ -3986,6 +4255,9 @@ The type '{0}' was created by a custom ReflectionContext and cannot be used here. + + type can't be a byref type. Name of type: {0} + Cannot create a byref of a byref: {0} @@ -3995,6 +4267,9 @@ The type '{0}' cannot be found. + + The type '{0}' cannot be loaded. + The type '{0}' cannot be found in assembly '{1}'. diff --git a/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs b/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs index f9096a68869bf0..5c839efd3c5010 100644 --- a/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs +++ b/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs @@ -100,14 +100,14 @@ private FieldStore (object? loc) public static FieldStore Create (RuntimeTypeHandle type) { - Type t = Type.GetTypeFromHandle(type) ?? throw new ArgumentException(nameof(type), "Type handle was null"); + Type t = Type.GetTypeFromHandle(type) ?? throw new ArgumentException(string.Format(SR.Arg_NullTypeHandleReferenceException, nameof(type))); object? loc; if (t.IsPrimitive || t.IsValueType) loc = RuntimeHelpers.GetUninitializedObject(t); else if (t.IsClass || t.IsInterface) loc = null; else - throw new ArgumentException("EnC: Expected a primitive, valuetype, class or interface field"); + throw new ArgumentException(SR.Arg_EnC); /* FIXME: do we want FieldStore to be pinned? */ return new FieldStore(loc); } diff --git a/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs b/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs index 0a8400925d7942..abb941cfe77fe3 100644 --- a/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs +++ b/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs @@ -47,7 +47,7 @@ public void End() public override bool Equals(object? o) { - throw new NotSupportedException("ArgIterator does not support Equals."); + throw new NotSupportedException(SR.PlatformNotSupported_ArgIterator); } public override int GetHashCode() @@ -59,7 +59,7 @@ public override int GetHashCode() public TypedReference GetNextArg() { if (num_args == next_arg) - throw new InvalidOperationException("Invalid iterator position."); + throw new InvalidOperationException(SR.InvalidOperation_InvalidIteratorPosition); TypedReference result = default; unsafe { @@ -75,7 +75,7 @@ public TypedReference GetNextArg() public TypedReference GetNextArg(RuntimeTypeHandle rth) { if (num_args == next_arg) - throw new InvalidOperationException("Invalid iterator position."); + throw new InvalidOperationException(SR.InvalidOperation_InvalidIteratorPosition); TypedReference result = default; unsafe { @@ -90,7 +90,7 @@ public TypedReference GetNextArg(RuntimeTypeHandle rth) public RuntimeTypeHandle GetNextArgType() { if (num_args == next_arg) - throw new InvalidOperationException("Invalid iterator position."); + throw new InvalidOperationException(SR.InvalidOperation_InvalidIteratorPosition); return new RuntimeTypeHandle(IntGetNextArgType()); } diff --git a/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs index 68d4552e54f6e7..b38170f8bc5b4f 100644 --- a/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs @@ -427,7 +427,7 @@ private static bool IsArgumentTypeMatchWithThis(Type delArgType, Type argType, b protected virtual object? DynamicInvokeImpl(object?[]? args) { - MethodInfo _method = Method ?? throw new NullReferenceException ("method_info is null"); + MethodInfo _method = Method ?? throw new NullReferenceException (SR.NullReference_This); object? target = _target; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs index 049a06bd0817c5..82461cd4b23d9e 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs @@ -158,7 +158,7 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type if (!inherit && res.Length == 1) { if (res[0] == null) - throw new CustomAttributeFormatException("Invalid custom attribute format"); + throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); if (attributeType != null) { @@ -206,7 +206,7 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type foreach (object attr in res) { if (attr == null) - throw new CustomAttributeFormatException("Invalid custom attribute format"); + throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); } var result = new Attribute[res.Length]; res.CopyTo(result, 0); @@ -217,7 +217,7 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type foreach (object attr in res) { if (attr == null) - throw new CustomAttributeFormatException("Invalid custom attribute format"); + throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); Type attrType = attr.GetType(); if (attributeType != null && !attributeType.IsAssignableFrom(attrType)) @@ -244,7 +244,7 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type { AttributeUsageAttribute usage; if (attr == null) - throw new CustomAttributeFormatException("Invalid custom attribute format"); + throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); Type attrType = attr.GetType(); if (attributeType != null) @@ -376,7 +376,7 @@ internal static IList GetCustomAttributesData(ICustomAttrib foreach (CustomAttributeData attrData in res) { if (attrData == null) - throw new CustomAttributeFormatException(Message); + throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); } var result = new CustomAttributeData[res.Count]; @@ -389,7 +389,7 @@ internal static IList GetCustomAttributesData(ICustomAttrib foreach (CustomAttributeData attrData in res) { if (attrData == null) - throw new CustomAttributeFormatException(Message); + throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); if (!attributeType.IsAssignableFrom(attrData.AttributeType)) continue; a.Add(attrData); @@ -410,7 +410,7 @@ internal static IList GetCustomAttributesData(ICustomAttrib { AttributeUsageAttribute usage; if (attrData == null) - throw new CustomAttributeFormatException(Message); + throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); Type attrType = attrData.AttributeType; if (attributeType != null) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs index d6c30ccd65a8ad..c6190cfb59ff31 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs @@ -70,7 +70,7 @@ internal ConstructorBuilder(TypeBuilder tb, MethodAttributes attributes, Calling { for (int i = 0; i < parameterTypes.Length; ++i) if (parameterTypes[i] == null) - throw new ArgumentException("Elements of the parameterTypes array cannot be null", nameof(parameterTypes)); + throw new ArgumentException(string.Format(SR.Argument_NullParameterTypes, nameof(parameterTypes))); this.parameters = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); @@ -319,7 +319,7 @@ internal void fixup() if (((attrs & (MethodAttributes.Abstract | MethodAttributes.PinvokeImpl)) == 0) && ((iattrs & (MethodImplAttributes.Runtime | MethodImplAttributes.InternalCall)) == 0)) { if ((ilgen == null) || (ilgen.ILOffset == 0)) - throw new InvalidOperationException("Method '" + Name + "' does not have a method body."); + throw new InvalidOperationException(string.Format(SR.InvalidOperation_MethodDoesNotHaveBody, Name)); } if (IsStatic && ((call_conv & CallingConventions.VarArgs) != 0 || @@ -351,22 +351,22 @@ internal override int get_next_table_index(int table, int count) private void RejectIfCreated() { if (type.is_created) - throw new InvalidOperationException("Type definition of the method is complete."); + throw new InvalidOperationException(SR.InvalidOperation_MethodBaked); } private static Exception not_supported() { - return new NotSupportedException("The invoked member is not supported in a dynamic module."); + return new NotSupportedException(SR.NotSupported_DynamicModule); } private static Exception not_after_created() { - return new InvalidOperationException("Unable to change after type has been created."); + return new InvalidOperationException(SR.InvalidOperation_TypeHasBeenCreated); } private static Exception not_created() { - return new NotSupportedException("The type is not yet created."); + return new NotSupportedException(SR.InvalidOperation_TypeNotCreated); } } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs index 86fa5e36f9c345..7aa2579ea534c4 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs @@ -198,11 +198,11 @@ private void Initialize(ConstructorInfo con, object?[] constructorArgs, { Type t = fi.DeclaringType!; if ((atype != t) && (!t.IsSubclassOf(atype)) && (!atype.IsSubclassOf(t))) - throw new ArgumentException("Field '" + fi.Name + "' does not belong to the same class as the constructor"); + throw new ArgumentException(string.Format(SR.Argument_FieldDoesNotBelongToConstructorClass, fi.Name)); if (!IsValidType(fi.FieldType)) - throw new ArgumentException("Field '" + fi.Name + "' does not have a valid type."); + throw new ArgumentException(string.Format(SR.Argument_FieldDoesNotHaveAValidType, fi.Name)); if (!IsValidValue(fi.FieldType, fieldValues[i])) - throw new ArgumentException("Field " + fi.Name + " is not a valid value."); + throw new ArgumentException(string.Format(SR.Argument_FieldDoesNotHaveAValidValue, fi.Name)); // FIXME: Check enums and TypeBuilders as well if (fieldValues[i] != null) // IsEnum does not seem to work on TypeBuilders @@ -213,7 +213,7 @@ private void Initialize(ConstructorInfo con, object?[] constructorArgs, // MS.NET allows this // if (!fi.FieldType.IsArray) - throw new ArgumentException("Value of field '" + fi.Name + "' does not match field type: " + fi.FieldType); + throw new ArgumentException(string.Format(SR.Argument_UnmatchedFieldValueAndType, fi.Name, fi.FieldType)); } i++; } @@ -222,19 +222,19 @@ private void Initialize(ConstructorInfo con, object?[] constructorArgs, foreach (PropertyInfo pi in namedProperties) { if (!pi.CanWrite) - throw new ArgumentException("Property '" + pi.Name + "' does not have a setter."); + throw new ArgumentException(string.Format(SR.Argument_PropertyMissingSetter, pi.Name)); Type t = pi.DeclaringType!; if ((atype != t) && (!t.IsSubclassOf(atype)) && (!atype.IsSubclassOf(t))) - throw new ArgumentException("Property '" + pi.Name + "' does not belong to the same class as the constructor"); + throw new ArgumentException(string.Format(SR.Argument_PropertyClassUnmatchedWithConstructor, pi.Name)); if (!IsValidType(pi.PropertyType)) - throw new ArgumentException("Property '" + pi.Name + "' does not have a valid type."); + throw new ArgumentException(string.Format(SR.Argument_PropertyInvalidType, pi.Name)); if (!IsValidValue(pi.PropertyType, propertyValues[i])) - throw new ArgumentException("Property " + pi.Name + " is not a valid value."); + throw new ArgumentException(string.Format(SR.Argument_PropertyInvalidValue, pi.Name)); if (propertyValues[i] != null) { if (!(pi.PropertyType is TypeBuilder) && !pi.PropertyType.IsEnum && !pi.PropertyType.IsInstanceOfType(propertyValues[i])) if (!pi.PropertyType.IsArray) - throw new ArgumentException("Value of property '" + pi.Name + "' does not match property type: " + pi.PropertyType + " -> " + propertyValues[i]); + throw new ArgumentException(string.Format(SR.Argument_PropertyUnmatchingPropertyType, pi.Name, pi.PropertyType, propertyValues[i])); } i++; } @@ -246,17 +246,17 @@ private void Initialize(ConstructorInfo con, object?[] constructorArgs, { Type paramType = pi.ParameterType; if (!IsValidType(paramType)) - throw new ArgumentException("Parameter " + i + " does not have a valid type."); + throw new ArgumentException(string.Format(SR.Argument_ParameterInvalidType, i)); if (!IsValidValue(paramType, constructorArgs[i])) - throw new ArgumentException("Parameter " + i + " is not a valid value."); + throw new ArgumentException(string.Format(SR.Argument_ParameterInvalidValue, i)); if (constructorArgs[i] != null) { if (!(paramType is TypeBuilder) && !paramType.IsEnum && !paramType.IsInstanceOfType(constructorArgs[i])) if (!paramType.IsArray) - throw new ArgumentException("Value of argument " + i + " does not match parameter type: " + paramType + " -> " + constructorArgs[i]); + throw new ArgumentException(string.Format(SR.Argument_ParameterHasUnmatchedArgumentValue, i, paramType, constructorArgs[i])); if (!IsValidParam(constructorArgs[i]!, paramType)) - throw new ArgumentException("Cannot emit a CustomAttribute with argument of type " + constructorArgs[i]!.GetType() + "."); + throw new ArgumentException(string.Format(SR.Argument_CustomAttributeInvalidType, constructorArgs[i]!.GetType())); } } i++; @@ -401,7 +401,7 @@ internal static UnmanagedMarshal get_umarshal(CustomAttributeBuilder customBuild marshalCookie = decode_string(data, pos, out pos)!; break; default: - throw new Exception("Unknown MarshalAsAttribute field: " + named_name); + throw new Exception(string.Format(SR.Exception_UnknownMarshalAsAttributeField, named_name)); } } @@ -418,7 +418,7 @@ internal static UnmanagedMarshal get_umarshal(CustomAttributeBuilder customBuild #endif case UnmanagedType.ByValArray: if (!is_field) - throw new ArgumentException("Specified unmanaged type is only valid on fields"); + throw new ArgumentException(SR.Argument_UnmanagedMemAccessorWrapAround); return UnmanagedMarshal.DefineByValArray(sizeConst); case UnmanagedType.ByValTStr: @@ -449,7 +449,7 @@ private static Type elementTypeToType(int elementType) => 0x0c => typeof(float), 0x0d => typeof(double), 0x0e => typeof(string), - _ => throw new Exception("Unknown element type '" + elementType + "'"), + _ => throw new Exception(string.Format(SR.Exception_UnknownElementType, elementType)), }; private static object? decode_cattr_value(Type t, byte[] data, int pos, out int rpos) @@ -478,9 +478,9 @@ private static Type elementTypeToType(int elementType) => if (subtype >= 0x02 && subtype <= 0x0e) return decode_cattr_value(elementTypeToType(subtype), data, pos, out rpos); else - throw new Exception("Subtype '" + subtype + "' of type object not yet handled in decode_cattr_value"); + throw new Exception(string.Format(SR.Exception_UnhandledSubType, subtype)); default: - throw new Exception("FIXME: Type " + t + " not yet handled in decode_cattr_value."); + throw new Exception(string.Format(SR.Exception_UnhandledFixMeType, t)); } } @@ -506,9 +506,9 @@ internal static CustomAttributeInfo decode_cattr(CustomAttributeBuilder customBu // Prolog if (data.Length < 2) - throw new Exception("Custom attr length is only '" + data.Length + "'"); + throw new Exception(string.Format(SR.Exception_InvalidCustomAttributeLength, data.Length)); if ((data[0] != 0x1) || (data[1] != 0x00)) - throw new Exception("Prolog invalid"); + throw new Exception(SR.Exception_InvalidProlog); pos = 2; ParameterInfo[] pi = GetParameters(ctor); @@ -545,7 +545,7 @@ internal static CustomAttributeInfo decode_cattr(CustomAttributeBuilder customBu /* Field */ FieldInfo? fi = ctor.DeclaringType!.GetField(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (fi == null) - throw new Exception("Custom attribute type '" + ctor.DeclaringType + "' doesn't contain a field named '" + name + "'"); + throw new Exception(string.Format(SR.Exception_EmptyFieldForCustomAttributeType, ctor.DeclaringType, name)); object? val = decode_cattr_value(fi.FieldType, data, pos, out pos); if (enum_type_name != null) @@ -558,7 +558,7 @@ internal static CustomAttributeInfo decode_cattr(CustomAttributeBuilder customBu } else // FIXME: - throw new Exception("Unknown named type: " + named_type); + throw new Exception(string.Format(SR.Exception_UnknownNamedType, named_type)); } return info; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs index 287de77ebe9f6c..fb5bf6349a4e1c 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs @@ -453,22 +453,22 @@ protected override bool IsByRefImpl() public override Type MakeArrayType() { - throw new ArgumentException("Cannot create an array type of a byref type"); + throw new ArgumentException(SR.Argument_CannotCreateArrayTypeOfByref); } public override Type MakeArrayType(int rank) { - throw new ArgumentException("Cannot create an array type of a byref type"); + throw new ArgumentException(SR.Argument_CannotCreateArrayTypeOfByref); } public override Type MakeByRefType() { - throw new ArgumentException("Cannot create a byref type of an already byref type"); + throw new ArgumentException(SR.Argument_CannotCreateArrayTypeOfByref); } public override Type MakePointerType() { - throw new ArgumentException("Cannot create a pointer type of a byref type"); + throw new ArgumentException(SR.Argument_CannotCreatePointerTypeOfByref); } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.Mono.cs index 0e399afedbde86..588f4f9c1b1b7f 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.Mono.cs @@ -79,7 +79,7 @@ public ILGenerator GetILGenerator(int streamSize) => } catch (MethodAccessException mae) { - throw new TargetInvocationException("Method cannot be invoked.", mae); + throw new TargetInvocationException(SR.TargetInvocation_MethodCannotBeInvoked, mae); } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs index 65fedfb5c6023b..deb9015c0c0d1a 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs @@ -140,7 +140,7 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) private void RejectIfCreated() { if (typeb.is_created) - throw new InvalidOperationException("Type definition of the method is complete."); + throw new InvalidOperationException(SR.InvalidOperation_TypeHasBeenCreated); } } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs index b113b088551b35..9b8f8c51149fe3 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs @@ -170,7 +170,7 @@ public void SetConstant(object? defaultValue) RejectIfCreated(); /*if (defaultValue.GetType() != type) - throw new ArgumentException("Constant doesn't match field type");*/ + throw new ArgumentException(SR.Argument_ConstantDoesntMatch);*/ def_value = defaultValue; } @@ -231,7 +231,7 @@ public void SetOffset(int iOffset) { RejectIfCreated(); if (iOffset < 0) - throw new ArgumentException("Negative field offset is not allowed"); + throw new ArgumentException(SR.Argument_NegativeFieldOffsetNotPermitted); offset = iOffset; } @@ -242,13 +242,13 @@ public override void SetValue(object? obj, object? val, BindingFlags invokeAttr, private static Exception CreateNotSupportedException() { - return new NotSupportedException("The invoked member is not supported in a dynamic module."); + return new NotSupportedException(SR.NotSupported_DynamicModule); } private void RejectIfCreated() { if (typeb.is_created) - throw new InvalidOperationException("Unable to change after type has been created."); + throw new InvalidOperationException(SR.InvalidOperation_TypeHasBeenCreated); } internal void ResolveUserTypes() diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs index 3f7f25a4d5f74f..b083b09c59dcbb 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs @@ -346,13 +346,13 @@ private void InternalEndClause() public virtual void BeginCatchBlock(Type? exceptionType) { if (!InExceptionBlock) - throw new NotSupportedException("Not in an exception block"); + throw new NotSupportedException(SR.NotSupported_NotInAnExceptionBlock); if (exceptionType != null && exceptionType.IsUserType) - throw new NotSupportedException("User defined subclasses of System.Type are not yet supported."); + throw new NotSupportedException(SR.NotSupported_UserDefinedSubClassesOfSystemTypeNotSupported); if (ex_handlers![cur_block].LastClauseType() == ILExceptionBlock.FILTER_START) { if (exceptionType != null) - throw new ArgumentException("Do not supply an exception type for filter clause"); + throw new ArgumentException(SR.Argument_ExceptionSuppliedForFilterClause); Emit(OpCodes.Endfilter); ex_handlers[cur_block].PatchFilterClause(code_len); } @@ -372,7 +372,7 @@ public virtual void BeginCatchBlock(Type? exceptionType) public virtual void BeginExceptFilterBlock() { if (!InExceptionBlock) - throw new NotSupportedException("Not in an exception block"); + throw new NotSupportedException(SR.NotSupported_NotInAnExceptionBlock); InternalEndClause(); ex_handlers![cur_block].AddFilter(code_len); @@ -403,7 +403,7 @@ public virtual Label BeginExceptionBlock() public virtual void BeginFaultBlock() { if (!InExceptionBlock) - throw new NotSupportedException("Not in an exception block"); + throw new NotSupportedException(SR.NotSupported_NotInAnExceptionBlock); if (ex_handlers![cur_block].LastClauseType() == ILExceptionBlock.FILTER_START) { @@ -419,7 +419,7 @@ public virtual void BeginFaultBlock() public virtual void BeginFinallyBlock() { if (!InExceptionBlock) - throw new NotSupportedException("Not in an exception block"); + throw new NotSupportedException(SR.NotSupported_NotInAnExceptionBlock); InternalEndClause(); @@ -446,7 +446,7 @@ public virtual LocalBuilder DeclareLocal(Type localType, bool pinned) { ArgumentNullException.ThrowIfNull(localType); if (localType.IsUserType) - throw new NotSupportedException("User defined subclasses of System.Type are not yet supported."); + throw new NotSupportedException(SR.NotSupported_UserDefinedSubClassesOfSystemTypeNotSupported); LocalBuilder res = new LocalBuilder(localType, this); res.is_pinned = pinned; @@ -719,7 +719,7 @@ public virtual void Emit(OpCode opcode, MethodInfo meth) // For compatibility with MS if ((meth is DynamicMethod) && ((opcode == OpCodes.Ldftn) || (opcode == OpCodes.Ldvirtftn) || (opcode == OpCodes.Ldtoken))) - throw new ArgumentException("Ldtoken, Ldftn and Ldvirtftn OpCodes cannot target DynamicMethods."); + throw new ArgumentException(SR.Argument_InvalidOpCodeOnDynamicMethod); int token = token_gen.GetToken(meth, true); make_room(6); @@ -790,14 +790,14 @@ public virtual void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[]? optio ArgumentNullException.ThrowIfNull(methodInfo); short value = opcode.Value; if (!(value == OpCodes.Call.Value || value == OpCodes.Callvirt.Value)) - throw new NotSupportedException("Only Call and CallVirt are allowed"); + throw new NotSupportedException(SR.NotSupported_OnlyCallAndCallVirtAllowed); if ((methodInfo.CallingConvention & CallingConventions.VarArgs) == 0) optionalParameterTypes = null; if (optionalParameterTypes != null) { if ((methodInfo.CallingConvention & CallingConventions.VarArgs) == 0) { - throw new InvalidOperationException("Method is not VarArgs method and optional types were passed"); + throw new InvalidOperationException(SR.InvalidOperation_NotAVarArgCallingConvention); } int token = token_gen.GetToken(methodInfo, optionalParameterTypes); @@ -848,7 +848,7 @@ public virtual void EmitWriteLine(LocalBuilder localBuilder) { ArgumentNullException.ThrowIfNull(localBuilder); if (localBuilder.LocalType is TypeBuilder) - throw new ArgumentException("Output streams do not support TypeBuilders."); + throw new ArgumentException(SR.Argument_OutputStreamsNotSupportingTypeBuilders); // The MS implementation does not check for valuetypes here but it // should. Emit(OpCodes.Ldloc, localBuilder); @@ -866,10 +866,10 @@ public virtual void EmitWriteLine(string value) public virtual void EndExceptionBlock() { if (!InExceptionBlock) - throw new NotSupportedException("Not in an exception block"); + throw new NotSupportedException(SR.NotSupported_NotInAnExceptionBlock); if (ex_handlers![cur_block].LastClauseType() == ILExceptionBlock.FILTER_START) - throw new InvalidOperationException("Incorrect code generation for exception block."); + throw new InvalidOperationException(SR.Argument_BadExceptionCodeGen); InternalEndClause(); MarkLabel(ex_handlers[cur_block].end); @@ -885,9 +885,9 @@ public virtual void EndScope() public virtual void MarkLabel(Label loc) { if (loc.m_label < 0 || loc.m_label >= num_labels) - throw new System.ArgumentException("The label is not valid"); + throw new System.ArgumentException(SR.Argument_InvalidLabel); if (labels![loc.m_label].addr >= 0) - throw new System.ArgumentException("The label was already defined"); + throw new System.ArgumentException(SR.Argument_InvalidLabel); labels[loc.m_label].addr = code_len; if (labels[loc.m_label].maxStack > cur_stack) cur_stack = labels[loc.m_label].maxStack; @@ -898,10 +898,10 @@ public virtual void ThrowException([DynamicallyAccessedMembers(DynamicallyAccess ArgumentNullException.ThrowIfNull(excType); if (!((excType == typeof(Exception)) || excType.IsSubclassOf(typeof(Exception)))) - throw new ArgumentException("Type should be an exception type", nameof(excType)); + throw new ArgumentException(string.Format(SR.Argument_TypeMustBeOfExceptionType, nameof(excType))); ConstructorInfo? ctor = excType.GetConstructor(Type.EmptyTypes); if (ctor == null) - throw new ArgumentException("Type should have a default constructor", nameof(excType)); + throw new ArgumentException(string.Format(SR.Argument_TypeMustHaveDefaultConstructor, nameof(excType))); Emit(OpCodes.Newobj, ctor); Emit(OpCodes.Throw); } @@ -917,7 +917,7 @@ internal void label_fixup(MethodBase mb) for (int i = 0; i < num_fixups; ++i) { if (labels![fixups![i].label_idx].addr < 0) - throw new ArgumentException(string.Format("Label #{0} is not marked in method `{1}'", fixups[i].label_idx + 1, mb.Name)); + throw new ArgumentException(string.Format(SR.Argument_LabelUnmarked, fixups[i].label_idx + 1, mb.Name)); // Diff is the offset from the end of the jump instruction to the address of the label int diff = labels[fixups[i].label_idx].addr - (fixups[i].pos + fixups[i].offset); if (fixups[i].offset == 1) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs index e5b8fbeab3f6f8..c63321190f8588 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs @@ -93,7 +93,7 @@ internal MethodBuilder(TypeBuilder tb, string name, MethodAttributes attributes, { for (int i = 0; i < parameterTypes.Length; ++i) if (parameterTypes[i] == null) - throw new ArgumentException("Elements of the parameterTypes array cannot be null", nameof(parameterTypes)); + throw new ArgumentException(string.Format(SR.Argument_NullParameterTypes, nameof(parameterTypes))); this.parameters = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); @@ -321,7 +321,7 @@ public ILGenerator GetILGenerator(int size) MethodImplAttributes.IL) || ((iattrs & MethodImplAttributes.ManagedMask) != MethodImplAttributes.Managed)) - throw new InvalidOperationException("Method body should not exist."); + throw new InvalidOperationException(SR.InvalidOperation_ShouldNotHaveMethodBody); if (ilgen != null) return ilgen; ilgen = new ILGenerator(type.Module, ((ModuleBuilder)type.Module).GetTokenGenerator(), size); @@ -418,7 +418,7 @@ public void SetCustomAttribute(CustomAttributeBuilder customBuilder) pi_dll = (string?)attr.ctorArgs[0]; if (pi_dll == null || pi_dll.Length == 0) - throw new ArgumentException("DllName cannot be empty"); + throw new ArgumentException(SR.Arg_DllNameNotFound); native_cc = Runtime.InteropServices.CallingConvention.Winapi; @@ -532,12 +532,12 @@ internal void set_override(MethodInfo mdecl) private void RejectIfCreated() { if (type.is_created) - throw new InvalidOperationException("Type definition of the method is complete."); + throw new InvalidOperationException(SR.InvalidOperation_MethodBaked); } private static Exception NotSupported() { - return new NotSupportedException("The invoked member is not supported in a dynamic module."); + return new NotSupportedException(SR.NotSupported_DynamicModule); } [RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")] @@ -545,7 +545,7 @@ private static Exception NotSupported() public override MethodInfo MakeGenericMethod(params Type[] typeArguments) { if (!IsGenericMethodDefinition) - throw new InvalidOperationException("Method is not a generic method definition"); + throw new InvalidOperationException(SR.Argument_MethodIsNotAGenericMethodDefinition); ArgumentNullException.ThrowIfNull(typeArguments); foreach (Type type in typeArguments) { diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs index 91525190483f11..f4c4c0a1dab5de 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs @@ -251,12 +251,12 @@ public override CallingConventions CallingConvention public override MethodInfo MakeGenericMethod(params Type[] methodInstantiation) { if (!base_method.IsGenericMethodDefinition || (method_arguments != null)) - throw new InvalidOperationException("Method is not a generic method definition"); + throw new InvalidOperationException(SR.Argument_MethodIsNotAGenericMethodDefinition); ArgumentNullException.ThrowIfNull(methodInstantiation); if (base_method.GetGenericArguments().Length != methodInstantiation.Length) - throw new ArgumentException("Incorrect length", nameof(methodInstantiation)); + throw new ArgumentException(string.Format(SR.Argument_IncorrectLength, nameof(methodInstantiation))); foreach (Type type in methodInstantiation) { diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs index 67b975b658a57f..38dfeef4d45787 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs @@ -123,7 +123,7 @@ public override string FullyQualifiedName public void CreateGlobalFunctions() { if (global_type_created) - throw new InvalidOperationException("global methods already created"); + throw new InvalidOperationException(SR.InvalidOperation_GlobalsHaveBeenCreated); if (global_type != null) { global_type_created = true; @@ -153,9 +153,9 @@ private FieldBuilder DefineDataImpl(string name, int size, FieldAttributes attri { ArgumentException.ThrowIfNullOrEmpty(name); if (global_type_created) - throw new InvalidOperationException("global fields already created"); + throw new InvalidOperationException(SR.InvalidOperation_GlobalsHaveBeenCreated); if ((size <= 0) || (size >= 0x3f0000)) - throw new ArgumentException("Data size must be > 0 and < 0x3f0000", null as string); + throw new ArgumentException(SR.Argument_BadSizeForData, null as string); CreateGlobalType(); @@ -204,9 +204,9 @@ public MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes { ArgumentNullException.ThrowIfNull(name); if ((attributes & MethodAttributes.Static) == 0) - throw new ArgumentException("global methods must be static"); + throw new ArgumentException(SR.Argument_GlobalFunctionHasToBeStatic); if (global_type_created) - throw new InvalidOperationException("global methods already created"); + throw new InvalidOperationException(SR.InvalidOperation_GlobalsHaveBeenCreated); CreateGlobalType(); MethodBuilder mb = global_type!.DefineMethod(name, attributes, callingConvention, returnType, requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers, parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers); @@ -219,9 +219,9 @@ public MethodBuilder DefinePInvokeMethod(string name, string dllName, string ent { ArgumentNullException.ThrowIfNull(name); if ((attributes & MethodAttributes.Static) == 0) - throw new ArgumentException("global methods must be static"); + throw new ArgumentException(SR.Argument_GlobalFunctionHasToBeStatic); if (global_type_created) - throw new InvalidOperationException("global methods already created"); + throw new InvalidOperationException(SR.InvalidOperation_GlobalsHaveBeenCreated); CreateGlobalType(); MethodBuilder mb = global_type!.DefinePInvokeMethod(name, dllName, entryName, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet); @@ -253,7 +253,7 @@ private TypeBuilder DefineType(string name, TypeAttributes attr, [DynamicallyAcc ArgumentNullException.ThrowIfNull(name, "fullname"); ITypeIdentifier ident = TypeIdentifiers.FromInternal(name); if (name_cache.ContainsKey(ident)) - throw new ArgumentException("Duplicate type name within an assembly."); + throw new ArgumentException(SR.Argument_DuplicateTypeName); TypeBuilder res = new TypeBuilder(this, name, attr, parent, interfaces, packingSize, typesize, null); AddType(res); @@ -293,7 +293,7 @@ public EnumBuilder DefineEnum(string name, TypeAttributes visibility, Type under { ITypeIdentifier ident = TypeIdentifiers.FromInternal(name); if (name_cache.ContainsKey(ident)) - throw new ArgumentException("Duplicate type name within an assembly."); + throw new ArgumentException(SR.Argument_DuplicateTypeName); EnumBuilder eb = new EnumBuilder(this, name, visibility, underlyingType); TypeBuilder res = eb.GetTypeBuilder(); @@ -540,7 +540,7 @@ internal static int GetTypeToken(Type type) { ArgumentNullException.ThrowIfNull(type); if (type.IsByRef) - throw new ArgumentException("type can't be a byref type", nameof(type)); + throw new ArgumentException(string.Format(SR.Argument_CannotBeByRefType, nameof(type))); return type.MetadataToken; } @@ -876,7 +876,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) return Array.Empty(); if (attributeType is TypeBuilder) - throw new InvalidOperationException("First argument to GetCustomAttributes can't be a TypeBuilder"); + throw new InvalidOperationException(SR.InvalidOperation_CannotHaveFirstArgumentAsTypeBuilder); List results = new List(); for (int i = 0; i < cattrs.Length; i++) @@ -884,7 +884,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) Type t = cattrs[i].Ctor.GetType(); if (t is TypeBuilder) - throw new InvalidOperationException("Can't construct custom attribute for TypeBuilder type"); + throw new InvalidOperationException(SR.InvalidOperation_CannotConstructCustomAttributeForTypeBuilderType); if (attributeType == null || attributeType.IsAssignableFrom(t)) results.Add(cattrs[i].Invoke()); @@ -902,7 +902,7 @@ public override IList GetCustomAttributesData() public override FieldInfo? GetField(string name, BindingFlags bindingAttr) { if (!global_type_created) - throw new InvalidOperationException("Module-level fields cannot be retrieved until after the CreateGlobalFunctions method has been called for the module."); + throw new InvalidOperationException(SR.InvalidOperation_ModuleMethodsRelyOnCreateGlobalFunctionsMethod); return global_type!.AsType().GetField(name, bindingAttr); } @@ -910,7 +910,7 @@ public override IList GetCustomAttributesData() public override FieldInfo[] GetFields(BindingFlags bindingFlags) { if (!global_type_created) - throw new InvalidOperationException("Module-level fields cannot be retrieved until after the CreateGlobalFunctions method has been called for the module."); + throw new InvalidOperationException(SR.InvalidOperation_ModuleMethodsRelyOnCreateGlobalFunctionsMethod); return global_type!.AsType().GetFields(bindingFlags); } @@ -918,7 +918,7 @@ public override FieldInfo[] GetFields(BindingFlags bindingFlags) public override MethodInfo[] GetMethods(BindingFlags bindingFlags) { if (!global_type_created) - throw new InvalidOperationException("Module-level methods cannot be retrieved until after the CreateGlobalFunctions method has been called for the module."); + throw new InvalidOperationException(SR.InvalidOperation_ModuleMethodsRelyOnCreateGlobalFunctionsMethod); return global_type!.AsType().GetMethods(bindingFlags); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs index 041784bdce33ee..cb6b4f4faac9c2 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyBuilder.Mono.cs @@ -222,7 +222,7 @@ public override Module Module private static Exception not_supported() { - return new NotSupportedException("The invoked member is not supported in a dynamic module."); + return new NotSupportedException(SR.NotSupported_DynamicModule); } } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs index 45c734ef396a13..14552a243169fc 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs @@ -72,7 +72,7 @@ internal SignatureHelper(ModuleBuilder? module, SignatureHelperType type) public static SignatureHelper GetFieldSigHelper(Module? mod) { if (mod != null && !(mod is ModuleBuilder)) - throw new ArgumentException("ModuleBuilder is expected"); + throw new ArgumentException(SR.ArgumentException_ModuleBuilderExpected); return new SignatureHelper((ModuleBuilder?)mod, SignatureHelperType.HELPER_FIELD); } @@ -80,7 +80,7 @@ public static SignatureHelper GetFieldSigHelper(Module? mod) public static SignatureHelper GetLocalVarSigHelper(Module? mod) { if (mod != null && !(mod is ModuleBuilder)) - throw new ArgumentException("ModuleBuilder is expected"); + throw new ArgumentException(SR.ArgumentException_ModuleBuilderExpected); return new SignatureHelper((ModuleBuilder?)mod, SignatureHelperType.HELPER_LOCAL); } @@ -192,9 +192,9 @@ private static void ValidateParameterModifiers(string name, Type[] parameter_mod { ArgumentNullException.ThrowIfNull(modifier, name); if (modifier.IsArray) - throw new ArgumentException("Array type not permitted", name); + throw new ArgumentException(string.Format(SR.Argument_ArraysInvalid, name)); if (modifier.ContainsGenericParameters) - throw new ArgumentException("Open Generic Type not permitted", name); + throw new ArgumentException(string.Format(SR.Argument_OpenGenericTypeNotPermitted, name)); } } @@ -204,7 +204,7 @@ private static void ValidateCustomModifier(int n, Type[][]? custom_modifiers, st return; if (custom_modifiers.Length != n) - throw new ArgumentException(string.Format("Custom modifiers length `{0}' does not match the size of the arguments", custom_modifiers.Length)); + throw new ArgumentException(string.Format(SR.Argument_CustomModifierLengthInvalidLength, custom_modifiers.Length)); foreach (Type[] parameter_modifiers in custom_modifiers) { @@ -217,7 +217,7 @@ private static void ValidateCustomModifier(int n, Type[][]? custom_modifiers, st private static Exception MissingFeature() { - throw new NotImplementedException("Mono does not currently support setting modOpt/modReq through SignatureHelper"); + throw new NotImplementedException(SR.NotImplemented_NoSupportForModOpt); } // FIXME: "Currently we ignore requiredCustomModifiers and optionalCustomModifiers" @@ -389,17 +389,17 @@ internal static SignatureHelper GetMethodSigHelper(Module? mod, CallingConventio Type[]? parameters) { if (mod != null && !(mod is ModuleBuilder)) - throw new ArgumentException("ModuleBuilder is expected"); + throw new ArgumentException(SR.ArgumentException_ModuleBuilderExpected); returnType ??= typeof(void); if (returnType.IsUserType) - throw new NotSupportedException("User defined subclasses of System.Type are not yet supported."); + throw new NotSupportedException(SR.NotSupported_UserDefinedSubClassesOfSystemTypeNotSupported); if (parameters != null) { for (int i = 0; i < parameters.Length; ++i) if (parameters[i].IsUserType) - throw new NotSupportedException("User defined subclasses of System.Type are not yet supported."); + throw new NotSupportedException(SR.NotSupported_UserDefinedSubClassesOfSystemTypeNotSupported); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs index 1615a94d9d4f5b..9776f74bf92d88 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs @@ -477,10 +477,7 @@ public ConstructorBuilder DefineDefaultConstructor(MethodAttributes attributes) null, EmptyTypes, null); if (parent_constructor == null) { - throw new NotSupportedException("Parent does" - + " not have a default constructor." - + " The default constructor must be" - + " explicitly defined."); + throw new NotSupportedException(SR.NotSupported_NoParentDefaultConstructor); } ConstructorBuilder cb = DefineConstructor(attributes, @@ -520,7 +517,7 @@ public MethodBuilder DefineMethod(string name, MethodAttributes attributes, Call !((attributes & MethodAttributes.Abstract) != 0) || !((attributes & MethodAttributes.Virtual) != 0)) && !(((attributes & MethodAttributes.Static) != 0))) - throw new ArgumentException("Interface method must be abstract and virtual."); + throw new ArgumentException(SR.InvalidOperation_BadInterfaceNotAbstractAndVirtual); returnType ??= typeof(void); MethodBuilder res = new MethodBuilder(this, name, attributes, @@ -552,9 +549,9 @@ public MethodBuilder DefinePInvokeMethod( 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."); + throw new ArgumentException(SR.Argument_BadPInvokeMethod); if (IsInterface) - throw new ArgumentException("PInvoke methods cannot exist on interfaces."); + throw new ArgumentException(SR.Argument_BadPInvokeOnInterface); check_not_created(); MethodBuilder res @@ -583,7 +580,7 @@ public void DefineMethodOverride(MethodInfo methodInfoBody, MethodInfo methodInf ArgumentNullException.ThrowIfNull(methodInfoDeclaration); check_not_created(); if (methodInfoBody.DeclaringType != this) - throw new ArgumentException("method body must belong to this type"); + throw new ArgumentException(SR.Argument_MethodBodyMustBelongToType); if (methodInfoBody is MethodBuilder mb) { @@ -595,7 +592,7 @@ public FieldBuilder DefineField(string fieldName, Type type, Type[]? requiredCus { check_name(nameof(fieldName), fieldName); if (type == typeof(void)) - throw new ArgumentException("Bad field type in defining field."); + throw new ArgumentException(SR.Argument_BadFieldType); check_not_created(); FieldBuilder res = new FieldBuilder(this, fieldName, type, attributes, requiredCustomModifiers, optionalCustomModifiers); @@ -759,19 +756,19 @@ public Type CreateType() if (parent != null) { if (parent.IsSealed) - throw new TypeLoadException("Could not load type '" + fullname.DisplayName + "' from assembly '" + Assembly + "' because the parent type is sealed."); + throw new TypeLoadException(string.Format(SR.TypeLoad_AssemblySealedParentTypeError, fullname.DisplayName, Assembly)); if (parent.IsGenericTypeDefinition) throw new BadImageFormatException(); } if (parent == typeof(Enum) && methods != null) - throw new TypeLoadException("Could not load type '" + fullname.DisplayName + "' from assembly '" + Assembly + "' because it is an enum with methods."); + throw new TypeLoadException(string.Format(SR.TypeLoad_AssemblyEnumContainsMethodsError, fullname.DisplayName, Assembly)); if (interfaces != null) { foreach (Type iface in interfaces) { if (iface.IsNestedPrivate && iface.Assembly != Assembly) - throw new TypeLoadException("Could not load type '" + fullname.DisplayName + "' from assembly '" + Assembly + "' because it is implements the inaccessible interface '" + iface.FullName + "'."); + throw new TypeLoadException(string.Format( SR.TypeLoad_AssemblyInaccessibleInterfaceError, fullname.DisplayName, Assembly, iface.FullName )); if (iface.IsGenericTypeDefinition) throw new BadImageFormatException(); if (!iface.IsInterface) @@ -788,7 +785,7 @@ public Type CreateType() { MethodBuilder mb = (MethodBuilder)(methods[i]); if (is_concrete && mb.IsAbstract) - throw new InvalidOperationException("Type is concrete but has abstract method " + mb); + throw new InvalidOperationException(string.Format(SR.InvalidOperation_AbstractMethod, mb)); mb.check_override(); mb.fixup(); } @@ -857,7 +854,7 @@ internal static void ResolveUserTypes(Type?[]? types) { t = t.UnderlyingSystemType; if (t != null && ((t.GetType().Assembly != typeof(int).Assembly) || (t is TypeDelegator))) - throw new NotSupportedException("User defined subclasses of System.Type are not yet supported."); + throw new NotSupportedException(SR.NotSupported_UserDefinedSubClassesOfSystemTypeNotSupported); return t; } else @@ -1307,11 +1304,11 @@ public override Type MakeGenericType(params Type[] typeArguments) //return base.MakeGenericType (typeArguments); if (!IsGenericTypeDefinition) - throw new InvalidOperationException("not a generic type definition"); + throw new InvalidOperationException(SR.InvalidOperation_NotGenericType); ArgumentNullException.ThrowIfNull(typeArguments); if (generic_params!.Length != typeArguments.Length) - throw new ArgumentException(string.Format("The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter.", generic_params.Length, typeArguments.Length), nameof(typeArguments)); + throw new ArgumentException(string.Format(SR.Argument_GenericArgumentsOverflow, generic_params.Length, typeArguments.Length, nameof(typeArguments))); foreach (Type t in typeArguments) { @@ -1354,7 +1351,7 @@ public void SetCustomAttribute(CustomAttributeBuilder customBuilder) LayoutKind.Auto => TypeAttributes.AutoLayout, LayoutKind.Explicit => TypeAttributes.ExplicitLayout, LayoutKind.Sequential => TypeAttributes.SequentialLayout, - _ => throw new Exception("Error in customattr"), // we should ignore it since it can be any value anyway... + _ => throw new Exception(SR.Exception_ErrorInCustomAttr), // we should ignore it since it can be any value anyway... }; Type ctor_type = customBuilder.Ctor is ConstructorBuilder builder ? builder.parameters![0] : customBuilder.Ctor.GetParametersInternal()[0].ParameterType; @@ -1500,7 +1497,7 @@ public FieldBuilder DefineUninitializedData(string name, int size, FieldAttribut { ArgumentException.ThrowIfNullOrEmpty(name); if ((size <= 0) || (size > 0x3f0000)) - throw new ArgumentException("Data size must be > 0 and < 0x3f0000"); + throw new ArgumentException(SR.Argument_BadSizeForData); check_not_created(); string typeName = "$ArrayType$" + size; @@ -1530,7 +1527,7 @@ public void SetParent([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes if ((attrs & TypeAttributes.Interface) != 0) { if ((attrs & TypeAttributes.Abstract) == 0) - throw new InvalidOperationException("Interface must be declared abstract."); + throw new InvalidOperationException(SR.InvalidOperation_BadInterfaceNotAbstract); this.parent = null; } else @@ -1555,7 +1552,7 @@ internal int get_next_table_index(int table, int count) public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type interfaceType) { if (created == null) - throw new NotSupportedException("This method is not implemented for incomplete types."); + throw new NotSupportedException(SR.NotSupported_IncompleteTypes); return created.GetInterfaceMap(interfaceType); } @@ -1582,13 +1579,13 @@ internal bool is_created private static Exception not_supported() { - return new NotSupportedException("The invoked member is not supported in a dynamic module."); + return new NotSupportedException(SR.NotSupported_DynamicModule); } internal void check_not_created() { if (is_created) - throw new InvalidOperationException("Unable to change after type has been created."); + throw new InvalidOperationException(SR.NotSupported_DynamicModule); } private void check_created() @@ -1661,7 +1658,7 @@ public override Type[] GetGenericArguments() public override Type GetGenericTypeDefinition() { if (generic_params == null) - throw new InvalidOperationException("Type is not generic"); + throw new InvalidOperationException(SR.InvalidOperation_NotGenericType); return this; } @@ -1741,20 +1738,20 @@ public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] nam public static ConstructorInfo GetConstructor(Type type, ConstructorInfo constructor) { if (!IsValidGetMethodType(type)) - throw new ArgumentException(SR.Argument_MustBeTypeBuilder, nameof(type)); + throw new ArgumentException(string.Format(SR.Argument_MustBeTypeBuilder, nameof(type))); if (type is TypeBuilder && type.ContainsGenericParameters) type = type.MakeGenericType(type.GetGenericArguments()); if (!constructor.DeclaringType!.IsGenericTypeDefinition) - throw new ArgumentException(SR.Argument_ConstructorNeedGenericDeclaringType, nameof(constructor)); + throw new ArgumentException(string.Format(SR.Argument_ConstructorNeedGenericDeclaringType, nameof(constructor))); if (constructor.DeclaringType != type.GetGenericTypeDefinition()) - throw new ArgumentException(SR.Argument_InvalidConstructorDeclaringType, nameof(type)); + throw new ArgumentException(string.Format(SR.Argument_InvalidConstructorDeclaringType, nameof(type))); ConstructorInfo res = type.GetConstructor(constructor); if (res == null) - throw new ArgumentException("constructor not found"); + throw new ArgumentException(SR.Argument_ConstructorNotFound); return res; } @@ -1788,7 +1785,7 @@ private static bool IsValidGetMethodType(Type type) public static MethodInfo GetMethod(Type type, MethodInfo method) { if (!IsValidGetMethodType(type)) - throw new ArgumentException(SR.Argument_MustBeTypeBuilder, nameof(type)); + throw new ArgumentException(string.Format(SR.Argument_MustBeTypeBuilder, nameof(type))); if (type is TypeBuilder && type.ContainsGenericParameters) type = type.MakeGenericType(type.GetGenericArguments()); @@ -1804,7 +1801,7 @@ public static MethodInfo GetMethod(Type type, MethodInfo method) MethodInfo res = type.GetMethod(method); if (res == null) - throw new ArgumentException(string.Format("method {0} not found in type {1}", method.Name, type)); + throw new ArgumentException(string.Format(SR.Argument_MethodNotFoundInType, method.Name, type)); return res; } @@ -1814,23 +1811,23 @@ public static MethodInfo GetMethod(Type type, MethodInfo method) public static FieldInfo GetField(Type type, FieldInfo field) { if (!IsValidGetMethodType(type)) - throw new ArgumentException(SR.Argument_MustBeTypeBuilder, nameof(type)); + throw new ArgumentException(string.Format(SR.Argument_MustBeTypeBuilder, nameof(type))); if (type is TypeBuilder && type.ContainsGenericParameters) type = type.MakeGenericType(type.GetGenericArguments()); if (!field.DeclaringType!.IsGenericTypeDefinition) - throw new ArgumentException(SR.Argument_FieldNeedGenericDeclaringType, nameof(field)); + throw new ArgumentException(string.Format(SR.Argument_FieldNeedGenericDeclaringType, nameof(field))); if (field.DeclaringType != type.GetGenericTypeDefinition()) - throw new ArgumentException(SR.Argument_InvalidFieldDeclaringType, nameof(type)); + throw new ArgumentException(string.Format(SR.Argument_InvalidFieldDeclaringType, nameof(type))); if (field is FieldOnTypeBuilderInst) - throw new ArgumentException("The specified field must be declared on a generic type definition.", nameof(field)); + throw new ArgumentException(string.Format(SR.Argument_FieldNeedGenericDeclaringType, nameof(field))); FieldInfo res = type.GetField(field); if (res == null) - throw new System.Exception("field not found"); + throw new System.Exception(SR.MissingField); else return res; } @@ -1963,7 +1960,7 @@ internal static bool SetConstantValue(Type destType, object? value, ref object? destValue = ticks; return true; default: - throw new ArgumentException(type!.ToString() + " is not a supported constant type."); + throw new ArgumentException(string.Format(SR.Argument_ConstantNotSupported, type!.ToString())); } } else @@ -1979,7 +1976,7 @@ internal static bool SetConstantValue(Type destType, object? value, ref object? private static void throw_argument_ConstantDoesntMatch() { - throw new ArgumentException("Constant does not match the defined type."); + throw new ArgumentException(SR.Argument_ConstantDoesntMatch); } public override bool IsTypeDefinition => true; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs index 3cc5d84c030057..c0b0bc9cb01bf8 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs @@ -558,7 +558,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(SR.NotSupported_UserTypesNotSupportedUnderFullAot); } } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs index 537b06c37d1406..d070cc892c1cc2 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs @@ -24,7 +24,7 @@ public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTyp throw new ArgumentException(SR.Argument_InvalidHandle); FieldInfo fi = internal_from_handle_type(handle.Value, declaringType.Value); if (fi == null) - throw new ArgumentException("The field handle and the type handle are incompatible."); + throw new ArgumentException(SR.Argument_FieldAndTypeHandleIncompatibility); return fi; } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs index f59e3e204b8377..64aa6e12fbf7bd 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs @@ -219,10 +219,10 @@ public override int MetadataToken internal static EventInfo GetEventFromHandle(Mono.RuntimeEventHandle handle, RuntimeTypeHandle reflectedType) { if (handle.Value == IntPtr.Zero) - throw new ArgumentException("The handle is invalid."); + throw new ArgumentException(SR.Argument_InvalidHandle); EventInfo ei = internal_from_handle_type(handle.Value, reflectedType.Value); if (ei == null) - throw new ArgumentException("The event handle and the type handle are incompatible."); + throw new ArgumentException(SR.Argument_FieldAndTypeHandleIncompatibility); return ei; } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs index 40265d7b9a2702..30892df010ebd9 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs @@ -201,12 +201,9 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) if (!IsStatic) { if (obj == null) - throw new TargetException("Non-static field requires a target"); + throw new TargetException(SR.Target_NonStaticFieldRequirement); if (!DeclaringType!.IsAssignableFrom(obj.GetType())) - throw new ArgumentException(string.Format( - "Field {0} defined on type {1} is not a field on the target object which is of type {2}.", - Name, DeclaringType, obj.GetType()), - nameof(obj)); + throw new ArgumentException(string.Format(SR.Arg_FieldDeclTarget, Name, DeclaringType, obj.GetType(), nameof(obj))); } if (!IsLiteral) @@ -228,15 +225,12 @@ public override void SetValue(object? obj, object? val, BindingFlags invokeAttr, if (!IsStatic) { if (obj == null) - throw new TargetException("Non-static field requires a target"); + throw new TargetException(SR.Target_NonStaticFieldRequirement); if (!DeclaringType!.IsAssignableFrom(obj.GetType())) - throw new ArgumentException(string.Format( - "Field {0} defined on type {1} is not a field on the target object which is of type {2}.", - Name, DeclaringType, obj.GetType()), - nameof(obj)); + throw new ArgumentException(SR.Arg_FieldDeclTarget); } if (IsLiteral) - throw new FieldAccessException("Cannot set a constant field"); + throw new FieldAccessException(SR.FieldAccess_CannotSetConstantField); binder ??= Type.DefaultBinder; CheckGeneric(); @@ -277,7 +271,7 @@ private void CheckGeneric() { Type? declaringType = DeclaringType; if (declaringType != null && declaringType.ContainsGenericParameters) - throw new InvalidOperationException("Late bound operations cannot be performed on fields with types for which Type.ContainsGenericParameters is true."); + throw new InvalidOperationException(SR.InvalidOperation_GenericParametersAlreadySet); } public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other) => HasSameMetadataDefinitionAsCore(other); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs index 08f30f04fca829..69e04aa57b1e81 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs @@ -622,11 +622,11 @@ public override MethodInfo MakeGenericMethod(Type[] methodInstantiation) ArgumentNullException.ThrowIfNull(methodInstantiation); if (!IsGenericMethodDefinition) - throw new InvalidOperationException("not a generic method definition"); + throw new InvalidOperationException(string.Format(SR.Arg_NotGenericMethodDefinition, nameof(methodInstantiation))); /*FIXME add GetGenericArgumentsLength() internal vcall to speed this up*/ if (GetGenericArguments().Length != methodInstantiation.Length) - throw new ArgumentException("Incorrect length"); + throw new ArgumentException(string.Format(SR.Argument_IncorrectLength, nameof(methodInstantiation))); bool hasUserType = false; foreach (Type type in methodInstantiation) @@ -642,12 +642,12 @@ public override MethodInfo MakeGenericMethod(Type[] methodInstantiation) if (RuntimeFeature.IsDynamicCodeSupported) return new MethodOnTypeBuilderInst(this, methodInstantiation); - throw new NotSupportedException("User types are not supported under full aot"); + throw new NotSupportedException(SR.NotSupported_UserTypesNotSupportedUnderFullAot); } MethodInfo ret = MakeGenericMethod_impl(methodInstantiation); if (ret == null) - throw new ArgumentException(string.Format("The method has {0} generic parameter(s) but {1} generic argument(s) were provided.", GetGenericArguments().Length, methodInstantiation.Length)); + throw new ArgumentException(string.Format(SR.Argument_GenericArgumentsOverflow, GetGenericArguments().Length, methodInstantiation.Length)); return ret; } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs index 07c63015e4bfb4..7c119d529c9ab5 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs @@ -256,7 +256,7 @@ int MetadataToken { return GetMetadataToken(); } - throw new ArgumentException("Can't produce MetadataToken for member of type " + MemberImpl.GetType()); + throw new ArgumentException(string.Format(SR.NoMetadataTokenAvailable, MemberImpl.GetType())); } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs index fa6e1c0fc45a9c..10bbf940ed65ce 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs @@ -454,7 +454,7 @@ public override void SetValue(object? obj, object? value, BindingFlags invokeAtt { MethodInfo? method = GetSetMethod(true); if (method == null) - throw new ArgumentException("Set Method not found for '" + Name + "'"); + throw new ArgumentException(string.Format(SR.Argument_SetMethodNotFound, Name)); object?[] parms; if (index == null || index.Length == 0) @@ -500,10 +500,10 @@ public override int MetadataToken internal static PropertyInfo GetPropertyFromHandle(RuntimePropertyHandle handle, RuntimeTypeHandle reflectedType) { if (handle.Value == IntPtr.Zero) - throw new ArgumentException("The handle is invalid."); + throw new ArgumentException(SR.Argument_InvalidHandle); PropertyInfo pi = internal_from_handle_type(handle.Value, reflectedType.Value); if (pi == null) - throw new ArgumentException("The property handle and the type handle are incompatible."); + throw new ArgumentException(SR.Argument_IncompatablePropertyAndTypeHandle); return pi; } } diff --git a/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs index 1025e77ebe4816..d8ec6d1d179d7e 100644 --- a/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs @@ -65,7 +65,7 @@ public static int GetHashCode(object? o) public static void RunClassConstructor(RuntimeTypeHandle type) { if (type.Value == IntPtr.Zero) - throw new ArgumentException("Handle is not initialized.", nameof(type)); + throw new ArgumentException(string.Format(SR.InvalidOperation_HandleIsNotInitialized, nameof(type))); RunClassConstructor(type.Value); } @@ -115,7 +115,7 @@ public static void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[] public static void RunModuleConstructor(ModuleHandle module) { if (module == ModuleHandle.EmptyHandle) - throw new ArgumentException("Handle is not initialized.", nameof(module)); + throw new ArgumentException(string.Format(SR.InvalidOperation_HandleIsNotInitialized, nameof(module))); RunModuleConstructor(module.Value); } diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index cbedc793bb2e7e..4957c605474f56 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -1622,7 +1622,7 @@ internal override FieldInfo GetField(FieldInfo fromNoninstanciated) { Type elementType = this.GetRootElementType(); if (ReferenceEquals(elementType, typeof(TypedReference)) || ReferenceEquals(elementType, typeof(RuntimeArgumentHandle))) - throw new NotSupportedException("NotSupported_ContainsStackPtr"); + throw new NotSupportedException(SR.NotSupported_ContainsStackPtr); if (IsValueType) { @@ -1636,7 +1636,7 @@ internal override FieldInfo GetField(FieldInfo fromNoninstanciated) // TODO: .net does more checks in unmanaged land in RuntimeTypeHandle::CreateInstance if (IsAbstract) { - throw new MissingMethodException("Cannot create an abstract class '{0}'.", FullName); + throw new MissingMethodException(string.Format(SR.MissingMethod_CannotCreateAbstractClass, FullName)); } unsafe @@ -1957,7 +1957,7 @@ public override Type MakeArrayType(int rank) public override Type MakeByRefType() { if (IsByRef) - throw new TypeLoadException("Can not call MakeByRefType on a ByRef type"); + throw new TypeLoadException(SR.TypeLoad_ResolveType); Type? type = null; var base_type = this; make_byref_type(new QCallTypeHandle(ref base_type), ObjectHandleOnStack.Create(ref type)); @@ -2114,19 +2114,19 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn RuntimeType? ifaceRtType = ifaceType as RuntimeType; if (ifaceRtType == null) - throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(ifaceType)); + throw new ArgumentException(string.Format(SR.Argument_MustBeRuntimeType, nameof(ifaceType))); InterfaceMapping res; if (!ifaceType.IsInterface) - throw new ArgumentException("Argument must be an interface.", nameof(ifaceType)); + throw new ArgumentException(string.Format(SR.Argument_MustBeInterface, nameof(ifaceType))); if (IsInterface) - throw new ArgumentException("'this' type cannot be an interface itself"); + throw new ArgumentException(SR.Argument_InterfaceMap); var this_type = this; res.TargetType = this; res.InterfaceType = ifaceType; GetInterfaceMapData(new QCallTypeHandle(ref this_type), new QCallTypeHandle(ref ifaceRtType), out res.TargetMethods, out res.InterfaceMethods); if (res.TargetMethods == null) - throw new ArgumentException("Interface not found", nameof(ifaceType)); + throw new ArgumentException(string.Format(SR.ArgumentException_InterfaceNotFound, nameof(ifaceType))); return res; } diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index 39e4a5a9544494..93c5e3a855c3ee 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs @@ -128,7 +128,7 @@ public ModuleHandle GetModuleHandle() // The check is needed because Type.GetTypeFromHandle returns null // for zero handles. if (value == IntPtr.Zero) - throw new InvalidOperationException("Object fields may not be properly initialized"); + throw new InvalidOperationException(SR.InvalidOperation_ObjectFieldsNotProperlyInitialized); return Type.GetTypeFromHandle(this)!.Module.ModuleHandle; } @@ -373,7 +373,7 @@ internal static bool IsTypeDefinition(RuntimeType type) if (typeName.Length == 0) if (throwOnError) - throw new TypeLoadException("A null or zero length string does not represent a valid Type."); + throw new TypeLoadException(SR.Arg_TypeLoadNullStr); else return null; @@ -384,7 +384,7 @@ internal static bool IsTypeDefinition(RuntimeType type) ref stackMark, ObjectHandleOnStack.Create (ref t), throwOnError, ignoreCase); if (throwOnError && t == null) - throw new TypeLoadException("Error loading '" + typeName + "'"); + throw new TypeLoadException(string.Format(SR.TypeLoad_TypeNotLoaded, typeName)); } return t; } diff --git a/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs index 413198df4ad480..e004a373ee7719 100644 --- a/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Threading/Monitor.Mono.cs @@ -88,7 +88,7 @@ public static void PulseAll(object obj) private static void ObjPulse(object obj) { if (!Monitor_test_synchronised(obj)) - throw new SynchronizationLockException("Object is not synchronized"); + throw new SynchronizationLockException(); Monitor_pulse(obj); } @@ -99,7 +99,7 @@ private static void ObjPulse(object obj) private static void ObjPulseAll(object obj) { if (!Monitor_test_synchronised(obj)) - throw new SynchronizationLockException("Object is not synchronized"); + throw new SynchronizationLockException(); Monitor_pulse_all(obj); } @@ -112,7 +112,7 @@ private static bool ObjWait(int millisecondsTimeout, object obj) if (millisecondsTimeout < 0 && millisecondsTimeout != (int)Timeout.Infinite) throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout)); if (!Monitor_test_synchronised(obj)) - throw new SynchronizationLockException("Object is not synchronized"); + throw new SynchronizationLockException(); return Monitor_wait(obj, millisecondsTimeout, true); } diff --git a/src/mono/System.Private.CoreLib/src/System/Type.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Type.Mono.cs index 8b2009154440eb..703d858c327a80 100644 --- a/src/mono/System.Private.CoreLib/src/System/Type.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Type.Mono.cs @@ -116,17 +116,17 @@ internal virtual bool IsUserType internal virtual MethodInfo GetMethod(MethodInfo fromNoninstanciated) { - throw new InvalidOperationException("can only be called in generic type"); + throw new InvalidOperationException(SR.InvalidOperation_CanOnlyBeCalledByGenericType); } internal virtual ConstructorInfo GetConstructor(ConstructorInfo fromNoninstanciated) { - throw new InvalidOperationException("can only be called in generic type"); + throw new InvalidOperationException(SR.InvalidOperation_CanOnlyBeCalledByGenericType); } internal virtual FieldInfo GetField(FieldInfo fromNoninstanciated) { - throw new InvalidOperationException("can only be called in generic type"); + throw new InvalidOperationException(SR.InvalidOperation_CanOnlyBeCalledByGenericType); } [MethodImplAttribute(MethodImplOptions.InternalCall)] diff --git a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs index 783b9b87b85f0b..367b7b680c9ded 100644 --- a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs +++ b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs @@ -252,7 +252,7 @@ internal static TypeSpec Parse(string typeName) TypeSpec res = Parse(typeName, ref pos, false, true); if (pos < typeName.Length) - throw new ArgumentException("Count not parse the whole type name", nameof(typeName)); + throw new ArgumentException(string.Format(SR.Argument_TypeParseError, nameof(typeName))); return res; } @@ -326,7 +326,7 @@ private static void SkipSpace(string name, ref int pos) private static void BoundCheck(int idx, string s) { if (idx >= s.Length) - throw new ArgumentException("Invalid generic arguments spec", "typeName"); + throw new ArgumentException(SR.Argument_InvalidGenericArg); } private static ITypeIdentifier ParsedTypeIdentifier(string displayName) @@ -379,7 +379,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo case '*': case '[': if (name[pos] != '[' && is_recurse) - throw new ArgumentException("Generic argument can't be byref or pointer type", "typeName"); + throw new ArgumentException(SR.Argument_GenericArgumentCannotBeByrefOrPointerType); data.AddName(name.Substring(name_start, pos - name_start)); name_start = pos + 1; in_modifiers = true; @@ -406,13 +406,13 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo { case '&': if (data.is_byref) - throw new ArgumentException("Can't have a byref of a byref", "typeName"); + throw new ArgumentException(SR.Argument_CannotHaveAByrefOfByref); data.is_byref = true; break; case '*': if (data.is_byref) - throw new ArgumentException("Can't have a pointer to a byref type", "typeName"); + throw new ArgumentException(SR.Argument_CannotPointToByrefType); // take subsequent '*'s too int pointer_level = 1; while (pos + 1 < name.Length && name[pos + 1] == '*') @@ -429,7 +429,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo while (end < name.Length && name[end] != ']') ++end; if (end >= name.Length) - throw new ArgumentException("Unmatched ']' while parsing generic argument assembly name"); + throw new ArgumentException(SR.Argument_UnmatchedSquareBracketWhileParsingGenericArgAssemblyName); data.assembly_name = name.Substring(pos + 1, end - pos - 1).Trim(); p = end; return data; @@ -447,17 +447,17 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo break; case '[': if (data.is_byref) - throw new ArgumentException("Byref qualifier must be the last one of a type", "typeName"); + throw new ArgumentException(SR.Argument_ByrefQualifierMustBeLastOneOfAType); ++pos; if (pos >= name.Length) - throw new ArgumentException("Invalid array/generic spec", "typeName"); + throw new ArgumentException(SR.Argument_InvalidArrayType); SkipSpace(name, ref pos); if (name[pos] != ',' && name[pos] != '*' && name[pos] != ']') {//generic args List args = new List(); if (data.HasModifiers) - throw new ArgumentException("generic args after array spec or pointer type", "typeName"); + throw new ArgumentException(SR.Arg_GenericArguments); while (pos < name.Length) { @@ -472,7 +472,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo if (name[pos] == ']') ++pos; else - throw new ArgumentException("Unclosed assembly-qualified type name at " + name[pos], "typeName"); + throw new ArgumentException(string.Format(SR.Argument_UnclosedAssemblyQualifiedTypeName, name[pos])); BoundCheck(pos, name); } @@ -481,11 +481,11 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo if (name[pos] == ',') ++pos; // skip ',' to the start of the next arg else - throw new ArgumentException("Invalid generic arguments separator " + name[pos], "typeName"); + throw new ArgumentException(string.Format(SR.Argument_InvalidGenericArgumentsSeparator, name[pos])); } if (pos >= name.Length || name[pos] != ']') - throw new ArgumentException("Error parsing generic params spec", "typeName"); + throw new ArgumentException(SR.Argument_GenericParsingError); data.generic_params = args; } else @@ -497,11 +497,11 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo if (name[pos] == '*') { if (bound) - throw new ArgumentException("Array spec cannot have 2 bound dimensions", "typeName"); + throw new ArgumentException(SR.Argument_ArrayCannotBeBoundTo2Dimensions); bound = true; } else if (name[pos] != ',') - throw new ArgumentException("Invalid character in array spec " + name[pos], "typeName"); + throw new ArgumentException(string.Format(SR.Argument_InvalidCharInArraySpecification, name[pos])); else ++dimensions; @@ -509,9 +509,9 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo SkipSpace(name, ref pos); } if (pos >= name.Length || name[pos] != ']') - throw new ArgumentException("Error parsing array spec", "typeName"); + throw new ArgumentException(SR.Argument_ArrayParsingError); if (dimensions > 1 && bound) - throw new ArgumentException("Invalid array spec, multi-dimensional array cannot be bound", "typeName"); + throw new ArgumentException(SR.Argument_MultiDimensionalArrayCannotBeBound); data.AddModifier(new IArraySpec(dimensions, bound)); } @@ -522,9 +522,9 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo p = pos; return data; } - throw new ArgumentException("Unmatched ']'", "typeName"); + throw new ArgumentException(SR.Argument_UnmatchedSquareBracketWhileParsingGenericArgAssemblyName); default: - throw new ArgumentException("Bad type def, can't handle '" + name[pos] + "'" + " at " + pos, "typeName"); + throw new ArgumentException(string.Format(SR.Argument_BadTypeDef, name[pos], pos)); } } } From e276c2286ca27f4e1f6513c370fde23e19614861 Mon Sep 17 00:00:00 2001 From: databunks Date: Mon, 14 Nov 2022 23:07:36 +0000 Subject: [PATCH 02/22] Fixed byref naming/text value Fixed 2nd parameter for argumentExceptions --- .../src/Resources/Strings.resx | 43 +++++++++---------- .../Emit/ConstructorBuilder.Mono.cs | 2 +- .../Reflection/Emit/DerivedTypes.Mono.cs | 6 +-- .../Reflection/Emit/ILGenerator.Mono.cs | 4 +- .../Reflection/Emit/MethodBuilder.Mono.cs | 2 +- .../Emit/MethodOnTypeBuilderInst.cs | 2 +- .../Reflection/Emit/ModuleBuilder.Mono.cs | 2 +- .../System/Reflection/Emit/SignatureHelper.cs | 4 +- .../Reflection/Emit/TypeBuilder.Mono.cs | 18 ++++---- .../src/System/Reflection/RuntimeFieldInfo.cs | 4 +- .../CompilerServices/RuntimeHelpers.Mono.cs | 4 +- .../src/System/RuntimeType.Mono.cs | 8 ++-- .../src/System/TypeSpec.cs | 34 +++++++-------- 13 files changed, 66 insertions(+), 67 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index b3d0d8ff998821..e79c2e78fcd934 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -853,7 +853,7 @@ Interface maps for generic interfaces on arrays cannot be retrieved. - Array or pointer types are not valid. Name: {0}. + Array or pointer types are not valid. Error parsing array spec. @@ -933,9 +933,8 @@ An invalid type was used as a custom attribute constructor argument, field or property. - - - Cannot create an array type of a byref type. + + Cannot create a byref type of an already byref type. Can't have a pointer to a byref type. @@ -974,7 +973,7 @@ Null is not a valid constant value for this type. - The specified constructor must be declared on a generic type definition. Name of constructor: {0}. + The specified constructor must be declared on a generic type definition. Constructor not found. @@ -1100,7 +1099,7 @@ The field handle and the type handle are incompatible. - The specified field must be declared on a generic type definition. Name of field: {0} + The specified field must be declared on a generic type definition. GenericArguments[{0}], '{1}', on '{2}' violates the constraint of type '{3}'. @@ -1109,7 +1108,7 @@ The number of generic arguments provided doesn't equal the arity of the generic type definition. - The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter. Name of type arguments: {2} + The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter. Generic argument can't be byref or pointer type. @@ -1121,7 +1120,7 @@ Error parsing generic params spec. - Open Generic Type not permitted. Name: {0} + Open Generic Type not permitted. Get Method not found for '{Name}' @@ -1166,7 +1165,7 @@ The property handle and the type handle are incompatible. - Incorrect length {0}. + Incorrect length. 'this' type cannot be an interface itself. @@ -1217,7 +1216,7 @@ Unable to translate Unicode character \\u{0:X4} at index {1} to specified code page. - The specified constructor must be declared on the generic type definition of the specified type. Name of type: {0} + The specified constructor must be declared on the generic type definition of the specified type. The ConstructorInfo object is not valid. @@ -1260,7 +1259,7 @@ The value '{0}' is not valid for this usage of the type {1}. - The specified field must be declared on the generic type definition of the specified type. Name of type: {0} + The specified field must be declared on the generic type definition of the specified type. Combining FileMode: {0} with FileAccess: {1} is invalid. @@ -1269,7 +1268,7 @@ Value of flags is invalid. - Invalid generic arguments spec + Invalid generic arguments spec. Invalid generic arguments separator {0} @@ -1338,7 +1337,7 @@ Null character in path. - Elements of the parameterTypes array cannot be null. Name of parameter type: {0}. + Elements of the parameterTypes array cannot be null. The given culture name '{0}' cannot be used to locate a resource file. Resource filenames must consist of only letters, numbers, hyphens or underscores. @@ -1428,10 +1427,10 @@ MethodInfo must be a runtime MethodInfo object. - Type must be a runtime Type object {0}. + Type must be a runtime Type object. - 'type' must contain a TypeBuilder as a generic argument. Name of builder type: {0}. + 'type' must contain a TypeBuilder as a generic argument. Type passed in must be derived from System.Attribute or System.Attribute itself. @@ -1440,7 +1439,7 @@ The specified structure must be blittable or have layout information. - Argument must be an interface {0}. + Argument must be an interface. 'overlapped' has already been freed. @@ -1545,7 +1544,7 @@ Parameter {0} does not have a valid value. - Could not parse the type name: {0}. + Could not parse the type name. 'preAllocated' is already in use. @@ -1638,10 +1637,10 @@ The specified type must be visible from COM. - Type should be an exception type. Name of exception type: {0}. + Type should be an exception type. - Type should have a default constructor. Name of exception type: {0}. + Type should have a default constructor. The type must not be imported from COM. @@ -1692,7 +1691,7 @@ The buffer is not associated with this pool and may not be returned to it. - Interface not found {0}. + Interface not found. ModuleBuilder is expected. @@ -2671,7 +2670,7 @@ Type definition of the global function has been completed. - Handle is not initialized. Name of type: {0} + Handle is not initialized. Handle is not pinned. @@ -4256,7 +4255,7 @@ The type '{0}' was created by a custom ReflectionContext and cannot be used here. - type can't be a byref type. Name of type: {0} + Type can't be a byref type. Cannot create a byref of a byref: {0} diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs index c6190cfb59ff31..1c7db0249550ae 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs @@ -70,7 +70,7 @@ internal ConstructorBuilder(TypeBuilder tb, MethodAttributes attributes, Calling { for (int i = 0; i < parameterTypes.Length; ++i) if (parameterTypes[i] == null) - throw new ArgumentException(string.Format(SR.Argument_NullParameterTypes, nameof(parameterTypes))); + throw new ArgumentException(SR.Argument_NullParameterTypes, nameof(parameterTypes)); this.parameters = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs index fb5bf6349a4e1c..b6c1125716a8fc 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs @@ -453,17 +453,17 @@ protected override bool IsByRefImpl() public override Type MakeArrayType() { - throw new ArgumentException(SR.Argument_CannotCreateArrayTypeOfByref); + throw new ArgumentException(SR.Argument_CannotCreateByrefTypeOfExistingByrefType); } public override Type MakeArrayType(int rank) { - throw new ArgumentException(SR.Argument_CannotCreateArrayTypeOfByref); + throw new ArgumentException(SR.Argument_CannotCreateByrefTypeOfExistingByrefType); } public override Type MakeByRefType() { - throw new ArgumentException(SR.Argument_CannotCreateArrayTypeOfByref); + throw new ArgumentException(SR.Argument_CannotCreateByrefTypeOfExistingByrefType); } public override Type MakePointerType() diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs index b083b09c59dcbb..d7c8b166c8c8b3 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs @@ -898,10 +898,10 @@ public virtual void ThrowException([DynamicallyAccessedMembers(DynamicallyAccess ArgumentNullException.ThrowIfNull(excType); if (!((excType == typeof(Exception)) || excType.IsSubclassOf(typeof(Exception)))) - throw new ArgumentException(string.Format(SR.Argument_TypeMustBeOfExceptionType, nameof(excType))); + throw new ArgumentException(SR.Argument_TypeMustBeOfExceptionType, nameof(excType)); ConstructorInfo? ctor = excType.GetConstructor(Type.EmptyTypes); if (ctor == null) - throw new ArgumentException(string.Format(SR.Argument_TypeMustHaveDefaultConstructor, nameof(excType))); + throw new ArgumentException(SR.Argument_TypeMustHaveDefaultConstructor, nameof(excType)); Emit(OpCodes.Newobj, ctor); Emit(OpCodes.Throw); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs index c63321190f8588..ade90f60c404db 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs @@ -93,7 +93,7 @@ internal MethodBuilder(TypeBuilder tb, string name, MethodAttributes attributes, { for (int i = 0; i < parameterTypes.Length; ++i) if (parameterTypes[i] == null) - throw new ArgumentException(string.Format(SR.Argument_NullParameterTypes, nameof(parameterTypes))); + throw new ArgumentException(SR.Argument_NullParameterTypes, nameof(parameterTypes)); this.parameters = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs index f4c4c0a1dab5de..83d6e006623110 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs @@ -256,7 +256,7 @@ public override MethodInfo MakeGenericMethod(params Type[] methodInstantiation) ArgumentNullException.ThrowIfNull(methodInstantiation); if (base_method.GetGenericArguments().Length != methodInstantiation.Length) - throw new ArgumentException(string.Format(SR.Argument_IncorrectLength, nameof(methodInstantiation))); + throw new ArgumentException(SR.Argument_IncorrectLength, nameof(methodInstantiation)); foreach (Type type in methodInstantiation) { diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs index 38dfeef4d45787..cd575bee885b44 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs @@ -540,7 +540,7 @@ internal static int GetTypeToken(Type type) { ArgumentNullException.ThrowIfNull(type); if (type.IsByRef) - throw new ArgumentException(string.Format(SR.Argument_CannotBeByRefType, nameof(type))); + throw new ArgumentException(SR.Argument_CannotBeByRefType, nameof(type)); return type.MetadataToken; } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs index 14552a243169fc..93354591d0a0fb 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs @@ -192,9 +192,9 @@ private static void ValidateParameterModifiers(string name, Type[] parameter_mod { ArgumentNullException.ThrowIfNull(modifier, name); if (modifier.IsArray) - throw new ArgumentException(string.Format(SR.Argument_ArraysInvalid, name)); + throw new ArgumentException(SR.Argument_ArraysInvalid, name); if (modifier.ContainsGenericParameters) - throw new ArgumentException(string.Format(SR.Argument_OpenGenericTypeNotPermitted, name)); + throw new ArgumentException(SR.Argument_OpenGenericTypeNotPermitted, name); } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs index 9776f74bf92d88..0414f078191022 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs @@ -1308,7 +1308,7 @@ public override Type MakeGenericType(params Type[] typeArguments) ArgumentNullException.ThrowIfNull(typeArguments); if (generic_params!.Length != typeArguments.Length) - throw new ArgumentException(string.Format(SR.Argument_GenericArgumentsOverflow, generic_params.Length, typeArguments.Length, nameof(typeArguments))); + throw new ArgumentException(string.Format(SR.Argument_GenericArgumentsOverflow, generic_params.Length, typeArguments.Length), nameof(typeArguments)); foreach (Type t in typeArguments) { @@ -1738,16 +1738,16 @@ public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] nam public static ConstructorInfo GetConstructor(Type type, ConstructorInfo constructor) { if (!IsValidGetMethodType(type)) - throw new ArgumentException(string.Format(SR.Argument_MustBeTypeBuilder, nameof(type))); + throw new ArgumentException(SR.Argument_MustBeTypeBuilder, nameof(type)); if (type is TypeBuilder && type.ContainsGenericParameters) type = type.MakeGenericType(type.GetGenericArguments()); if (!constructor.DeclaringType!.IsGenericTypeDefinition) - throw new ArgumentException(string.Format(SR.Argument_ConstructorNeedGenericDeclaringType, nameof(constructor))); + throw new ArgumentException(SR.Argument_ConstructorNeedGenericDeclaringType, nameof(constructor)); if (constructor.DeclaringType != type.GetGenericTypeDefinition()) - throw new ArgumentException(string.Format(SR.Argument_InvalidConstructorDeclaringType, nameof(type))); + throw new ArgumentException(SR.Argument_InvalidConstructorDeclaringType, nameof(type)); ConstructorInfo res = type.GetConstructor(constructor); if (res == null) @@ -1785,7 +1785,7 @@ private static bool IsValidGetMethodType(Type type) public static MethodInfo GetMethod(Type type, MethodInfo method) { if (!IsValidGetMethodType(type)) - throw new ArgumentException(string.Format(SR.Argument_MustBeTypeBuilder, nameof(type))); + throw new ArgumentException(SR.Argument_MustBeTypeBuilder, nameof(type)); if (type is TypeBuilder && type.ContainsGenericParameters) type = type.MakeGenericType(type.GetGenericArguments()); @@ -1811,19 +1811,19 @@ public static MethodInfo GetMethod(Type type, MethodInfo method) public static FieldInfo GetField(Type type, FieldInfo field) { if (!IsValidGetMethodType(type)) - throw new ArgumentException(string.Format(SR.Argument_MustBeTypeBuilder, nameof(type))); + throw new ArgumentException(SR.Argument_MustBeTypeBuilder, nameof(type)); if (type is TypeBuilder && type.ContainsGenericParameters) type = type.MakeGenericType(type.GetGenericArguments()); if (!field.DeclaringType!.IsGenericTypeDefinition) - throw new ArgumentException(string.Format(SR.Argument_FieldNeedGenericDeclaringType, nameof(field))); + throw new ArgumentException(SR.Argument_FieldNeedGenericDeclaringType, nameof(field)); if (field.DeclaringType != type.GetGenericTypeDefinition()) - throw new ArgumentException(string.Format(SR.Argument_InvalidFieldDeclaringType, nameof(type))); + throw new ArgumentException(SR.Argument_InvalidFieldDeclaringType, nameof(type)); if (field is FieldOnTypeBuilderInst) - throw new ArgumentException(string.Format(SR.Argument_FieldNeedGenericDeclaringType, nameof(field))); + throw new ArgumentException(SR.Argument_FieldNeedGenericDeclaringType, nameof(field)); FieldInfo res = type.GetField(field); if (res == null) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs index 30892df010ebd9..fec4ff905cf21e 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs @@ -203,7 +203,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) if (obj == null) throw new TargetException(SR.Target_NonStaticFieldRequirement); if (!DeclaringType!.IsAssignableFrom(obj.GetType())) - throw new ArgumentException(string.Format(SR.Arg_FieldDeclTarget, Name, DeclaringType, obj.GetType(), nameof(obj))); + throw new ArgumentException(string.Format(SR.Arg_FieldDeclTarget, Name, DeclaringType, obj.GetType()), nameof(obj)); } if (!IsLiteral) @@ -227,7 +227,7 @@ public override void SetValue(object? obj, object? val, BindingFlags invokeAttr, if (obj == null) throw new TargetException(SR.Target_NonStaticFieldRequirement); if (!DeclaringType!.IsAssignableFrom(obj.GetType())) - throw new ArgumentException(SR.Arg_FieldDeclTarget); + throw new ArgumentException(string.Format(SR.Arg_FieldDeclTarget, Name, DeclaringType, obj.GetType()), nameof(obj)); } if (IsLiteral) throw new FieldAccessException(SR.FieldAccess_CannotSetConstantField); diff --git a/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs index d8ec6d1d179d7e..9d49d158a457f1 100644 --- a/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs @@ -65,7 +65,7 @@ public static int GetHashCode(object? o) public static void RunClassConstructor(RuntimeTypeHandle type) { if (type.Value == IntPtr.Zero) - throw new ArgumentException(string.Format(SR.InvalidOperation_HandleIsNotInitialized, nameof(type))); + throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(type)); RunClassConstructor(type.Value); } @@ -115,7 +115,7 @@ public static void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[] public static void RunModuleConstructor(ModuleHandle module) { if (module == ModuleHandle.EmptyHandle) - throw new ArgumentException(string.Format(SR.InvalidOperation_HandleIsNotInitialized, nameof(module))); + throw new ArgumentException(SR.InvalidOperation_HandleIsNotInitialized, nameof(module)); RunModuleConstructor(module.Value); } diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index 4957c605474f56..1cdab97bbd67df 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -1970,7 +1970,7 @@ public override Type MakeByRefType() public override Type MakePointerType() { if (IsByRef) - throw new TypeLoadException($"Could not load type '{GetType()}' from assembly '{AssemblyQualifiedName}"); + throw new TypeLoadException(string.Format(SR.ClassLoad_General, GetType(), AssemblyQualifiedName)); Type? type = null; var base_type = this; make_pointer_type(new QCallTypeHandle(ref base_type), ObjectHandleOnStack.Create(ref type)); @@ -2114,11 +2114,11 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn RuntimeType? ifaceRtType = ifaceType as RuntimeType; if (ifaceRtType == null) - throw new ArgumentException(string.Format(SR.Argument_MustBeRuntimeType, nameof(ifaceType))); + throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(ifaceType)); InterfaceMapping res; if (!ifaceType.IsInterface) - throw new ArgumentException(string.Format(SR.Argument_MustBeInterface, nameof(ifaceType))); + throw new ArgumentException(SR.Argument_MustBeInterface, nameof(ifaceType)); if (IsInterface) throw new ArgumentException(SR.Argument_InterfaceMap); var this_type = this; @@ -2126,7 +2126,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn res.InterfaceType = ifaceType; GetInterfaceMapData(new QCallTypeHandle(ref this_type), new QCallTypeHandle(ref ifaceRtType), out res.TargetMethods, out res.InterfaceMethods); if (res.TargetMethods == null) - throw new ArgumentException(string.Format(SR.ArgumentException_InterfaceNotFound, nameof(ifaceType))); + throw new ArgumentException(SR.ArgumentException_InterfaceNotFound, nameof(ifaceType)); return res; } diff --git a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs index 367b7b680c9ded..ef0accc8a39c18 100644 --- a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs +++ b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs @@ -252,7 +252,7 @@ internal static TypeSpec Parse(string typeName) TypeSpec res = Parse(typeName, ref pos, false, true); if (pos < typeName.Length) - throw new ArgumentException(string.Format(SR.Argument_TypeParseError, nameof(typeName))); + throw new ArgumentException(SR.Argument_TypeParseError, nameof(typeName)); return res; } @@ -326,7 +326,7 @@ private static void SkipSpace(string name, ref int pos) private static void BoundCheck(int idx, string s) { if (idx >= s.Length) - throw new ArgumentException(SR.Argument_InvalidGenericArg); + throw new ArgumentException(SR.Argument_InvalidGenericArg, "typeName"); } private static ITypeIdentifier ParsedTypeIdentifier(string displayName) @@ -379,7 +379,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo case '*': case '[': if (name[pos] != '[' && is_recurse) - throw new ArgumentException(SR.Argument_GenericArgumentCannotBeByrefOrPointerType); + throw new ArgumentException(SR.Argument_GenericArgumentCannotBeByrefOrPointerType, "typeName"); data.AddName(name.Substring(name_start, pos - name_start)); name_start = pos + 1; in_modifiers = true; @@ -406,13 +406,13 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo { case '&': if (data.is_byref) - throw new ArgumentException(SR.Argument_CannotHaveAByrefOfByref); + throw new ArgumentException(SR.Argument_CannotHaveAByrefOfByref, "typeName"); data.is_byref = true; break; case '*': if (data.is_byref) - throw new ArgumentException(SR.Argument_CannotPointToByrefType); + throw new ArgumentException(SR.Argument_CannotPointToByrefType, "typeName"); // take subsequent '*'s too int pointer_level = 1; while (pos + 1 < name.Length && name[pos + 1] == '*') @@ -447,17 +447,17 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo break; case '[': if (data.is_byref) - throw new ArgumentException(SR.Argument_ByrefQualifierMustBeLastOneOfAType); + throw new ArgumentException(SR.Argument_ByrefQualifierMustBeLastOneOfAType, "typeName"); ++pos; if (pos >= name.Length) - throw new ArgumentException(SR.Argument_InvalidArrayType); + throw new ArgumentException(SR.Argument_InvalidArrayType, "typeName"); SkipSpace(name, ref pos); if (name[pos] != ',' && name[pos] != '*' && name[pos] != ']') {//generic args List args = new List(); if (data.HasModifiers) - throw new ArgumentException(SR.Arg_GenericArguments); + throw new ArgumentException(SR.Arg_GenericArguments, "typeName"); while (pos < name.Length) { @@ -472,7 +472,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo if (name[pos] == ']') ++pos; else - throw new ArgumentException(string.Format(SR.Argument_UnclosedAssemblyQualifiedTypeName, name[pos])); + throw new ArgumentException(string.Format(SR.Argument_UnclosedAssemblyQualifiedTypeName, name[pos]), "typeName"); BoundCheck(pos, name); } @@ -481,11 +481,11 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo if (name[pos] == ',') ++pos; // skip ',' to the start of the next arg else - throw new ArgumentException(string.Format(SR.Argument_InvalidGenericArgumentsSeparator, name[pos])); + throw new ArgumentException(string.Format(SR.Argument_InvalidGenericArgumentsSeparator, name[pos]), "typeName"); } if (pos >= name.Length || name[pos] != ']') - throw new ArgumentException(SR.Argument_GenericParsingError); + throw new ArgumentException(SR.Argument_GenericParsingError, "typeName"); data.generic_params = args; } else @@ -497,11 +497,11 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo if (name[pos] == '*') { if (bound) - throw new ArgumentException(SR.Argument_ArrayCannotBeBoundTo2Dimensions); + throw new ArgumentException(SR.Argument_ArrayCannotBeBoundTo2Dimensions, "typeName"); bound = true; } else if (name[pos] != ',') - throw new ArgumentException(string.Format(SR.Argument_InvalidCharInArraySpecification, name[pos])); + throw new ArgumentException(string.Format(SR.Argument_InvalidCharInArraySpecification, name[pos]), "typeName"); else ++dimensions; @@ -509,9 +509,9 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo SkipSpace(name, ref pos); } if (pos >= name.Length || name[pos] != ']') - throw new ArgumentException(SR.Argument_ArrayParsingError); + throw new ArgumentException(SR.Argument_ArrayParsingError, "typeName"); if (dimensions > 1 && bound) - throw new ArgumentException(SR.Argument_MultiDimensionalArrayCannotBeBound); + throw new ArgumentException(SR.Argument_MultiDimensionalArrayCannotBeBound, "typeName"); data.AddModifier(new IArraySpec(dimensions, bound)); } @@ -522,9 +522,9 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo p = pos; return data; } - throw new ArgumentException(SR.Argument_UnmatchedSquareBracketWhileParsingGenericArgAssemblyName); + throw new ArgumentException(SR.Argument_UnmatchedSquareBracketWhileParsingGenericArgAssemblyName, "typeName"); default: - throw new ArgumentException(string.Format(SR.Argument_BadTypeDef, name[pos], pos)); + throw new ArgumentException(string.Format(SR.Argument_BadTypeDef, name[pos], pos), "typeName"); } } } From bf792d9f9dfd683e0154a3cfbef51af28d18258d Mon Sep 17 00:00:00 2001 From: databunks Date: Tue, 15 Nov 2022 01:02:53 +0000 Subject: [PATCH 03/22] Fixed ByRef Arguments & string.format -> SR.Format --- .../src/Resources/Strings.resx | 3 ++ .../src/Mono/HotReload.cs | 2 +- .../src/System/ModuleHandle.cs | 6 +-- .../Reflection/Emit/AssemblyBuilder.Mono.cs | 4 +- .../Emit/ConstructorBuilder.Mono.cs | 2 +- .../Emit/CustomAttributeBuilder.Mono.cs | 40 +++++++++---------- .../Reflection/Emit/DerivedTypes.Mono.cs | 4 +- .../Reflection/Emit/ILGenerator.Mono.cs | 2 +- .../Reflection/Emit/MethodBuilder.Mono.cs | 4 +- .../Emit/PropertyOnTypeBuilderInst.cs | 2 +- .../System/Reflection/Emit/SignatureHelper.cs | 2 +- .../Reflection/Emit/TypeBuilder.Mono.cs | 14 +++---- .../src/System/Reflection/RuntimeAssembly.cs | 2 +- .../src/System/Reflection/RuntimeFieldInfo.cs | 6 +-- .../Reflection/RuntimeMethodInfo.Mono.cs | 6 +-- .../src/System/Reflection/RuntimeModule.cs | 4 +- .../System/Reflection/RuntimeParameterInfo.cs | 2 +- .../System/Reflection/RuntimePropertyInfo.cs | 2 +- .../src/System/RuntimeType.Mono.cs | 4 +- .../src/System/RuntimeTypeHandle.cs | 2 +- .../src/System/TypeSpec.cs | 8 ++-- 21 files changed, 62 insertions(+), 59 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index e79c2e78fcd934..d9318a25a48932 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -936,6 +936,9 @@ Cannot create a byref type of an already byref type. + + Cannot create an array type of a byref type. + Can't have a pointer to a byref type. diff --git a/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs b/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs index 5c839efd3c5010..e851e385d0ec63 100644 --- a/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs +++ b/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs @@ -100,7 +100,7 @@ private FieldStore (object? loc) public static FieldStore Create (RuntimeTypeHandle type) { - Type t = Type.GetTypeFromHandle(type) ?? throw new ArgumentException(string.Format(SR.Arg_NullTypeHandleReferenceException, nameof(type))); + Type t = Type.GetTypeFromHandle(type) ?? throw new ArgumentException(SR.Format(SR.Arg_NullTypeHandleReferenceException, nameof(type))); object? loc; if (t.IsPrimitive || t.IsValueType) loc = RuntimeHelpers.GetUninitializedObject(t); diff --git a/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs b/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs index c30bf25582a3a5..19239ea2b4e133 100644 --- a/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs +++ b/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs @@ -71,7 +71,7 @@ public RuntimeTypeHandle ResolveTypeHandle(int typeToken, RuntimeTypeHandle[]? t throw new ArgumentNullException(string.Empty, "Invalid handle"); IntPtr res = RuntimeModule.ResolveTypeToken(value, typeToken, ptrs_from_handles(typeInstantiationContext), ptrs_from_handles(methodInstantiationContext), out _); if (res == IntPtr.Zero) - throw new TypeLoadException(string.Format("Could not load type '0x{0:x}' from assembly '0x{1:x}'", typeToken, value.ToInt64())); + throw new TypeLoadException(SR.Format("Could not load type '0x{0:x}' from assembly '0x{1:x}'", typeToken, value.ToInt64())); else return new RuntimeTypeHandle(res); } @@ -83,7 +83,7 @@ public RuntimeMethodHandle ResolveMethodHandle(int methodToken, RuntimeTypeHandl throw new ArgumentNullException(string.Empty, "Invalid handle"); IntPtr res = RuntimeModule.ResolveMethodToken(value, methodToken, ptrs_from_handles(typeInstantiationContext), ptrs_from_handles(methodInstantiationContext), out _); if (res == IntPtr.Zero) - throw new Exception(string.Format("Could not load method '0x{0:x}' from assembly '0x{1:x}'", methodToken, value.ToInt64())); + throw new Exception(SR.Format("Could not load method '0x{0:x}' from assembly '0x{1:x}'", methodToken, value.ToInt64())); else return new RuntimeMethodHandle(res); } @@ -96,7 +96,7 @@ public RuntimeFieldHandle ResolveFieldHandle(int fieldToken, RuntimeTypeHandle[] IntPtr res = RuntimeModule.ResolveFieldToken(value, fieldToken, ptrs_from_handles(typeInstantiationContext), ptrs_from_handles(methodInstantiationContext), out _); if (res == IntPtr.Zero) - throw new Exception(string.Format("Could not load field '0x{0:x}' from assembly '0x{1:x}'", fieldToken, value.ToInt64())); + throw new Exception(SR.Format("Could not load field '0x{0:x}' from assembly '0x{1:x}'", fieldToken, value.ToInt64())); else return new RuntimeFieldHandle(res); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs index 7c5de218b3c3c4..62a0143f9c199e 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs @@ -208,7 +208,7 @@ private AssemblyBuilder(AssemblyName n, AssemblyBuilderAccess access) aname = (AssemblyName)n.Clone(); if (!Enum.IsDefined(typeof(AssemblyBuilderAccess), access)) - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, + throw new ArgumentException(SR.Format(CultureInfo.InvariantCulture, "Argument value {0} is not valid.", (int)access), nameof(access)); @@ -336,7 +336,7 @@ internal static Type MakeGenericType(Type gtd, Type[] typeArguments) => if (res is TypeBuilder) { if (throwOnError) - throw new TypeLoadException(string.Format("Could not load type '{0}' from assembly '{1}'", name, this.name)); + throw new TypeLoadException(SR.Format("Could not load type '{0}' from assembly '{1}'", name, this.name)); return null; } return res; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs index 1c7db0249550ae..2ba215fc05bf69 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs @@ -319,7 +319,7 @@ internal void fixup() if (((attrs & (MethodAttributes.Abstract | MethodAttributes.PinvokeImpl)) == 0) && ((iattrs & (MethodImplAttributes.Runtime | MethodImplAttributes.InternalCall)) == 0)) { if ((ilgen == null) || (ilgen.ILOffset == 0)) - throw new InvalidOperationException(string.Format(SR.InvalidOperation_MethodDoesNotHaveBody, Name)); + throw new InvalidOperationException(SR.Format(SR.InvalidOperation_MethodDoesNotHaveBody, Name)); } if (IsStatic && ((call_conv & CallingConventions.VarArgs) != 0 || diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs index 7aa2579ea534c4..ff28b3cce8f12b 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs @@ -198,11 +198,11 @@ private void Initialize(ConstructorInfo con, object?[] constructorArgs, { Type t = fi.DeclaringType!; if ((atype != t) && (!t.IsSubclassOf(atype)) && (!atype.IsSubclassOf(t))) - throw new ArgumentException(string.Format(SR.Argument_FieldDoesNotBelongToConstructorClass, fi.Name)); + throw new ArgumentException(SR.Format(SR.Argument_FieldDoesNotBelongToConstructorClass, fi.Name)); if (!IsValidType(fi.FieldType)) - throw new ArgumentException(string.Format(SR.Argument_FieldDoesNotHaveAValidType, fi.Name)); + throw new ArgumentException(SR.Format(SR.Argument_FieldDoesNotHaveAValidType, fi.Name)); if (!IsValidValue(fi.FieldType, fieldValues[i])) - throw new ArgumentException(string.Format(SR.Argument_FieldDoesNotHaveAValidValue, fi.Name)); + throw new ArgumentException(SR.Format(SR.Argument_FieldDoesNotHaveAValidValue, fi.Name)); // FIXME: Check enums and TypeBuilders as well if (fieldValues[i] != null) // IsEnum does not seem to work on TypeBuilders @@ -213,7 +213,7 @@ private void Initialize(ConstructorInfo con, object?[] constructorArgs, // MS.NET allows this // if (!fi.FieldType.IsArray) - throw new ArgumentException(string.Format(SR.Argument_UnmatchedFieldValueAndType, fi.Name, fi.FieldType)); + throw new ArgumentException(SR.Format(SR.Argument_UnmatchedFieldValueAndType, fi.Name, fi.FieldType)); } i++; } @@ -222,19 +222,19 @@ private void Initialize(ConstructorInfo con, object?[] constructorArgs, foreach (PropertyInfo pi in namedProperties) { if (!pi.CanWrite) - throw new ArgumentException(string.Format(SR.Argument_PropertyMissingSetter, pi.Name)); + throw new ArgumentException(SR.Format(SR.Argument_PropertyMissingSetter, pi.Name)); Type t = pi.DeclaringType!; if ((atype != t) && (!t.IsSubclassOf(atype)) && (!atype.IsSubclassOf(t))) - throw new ArgumentException(string.Format(SR.Argument_PropertyClassUnmatchedWithConstructor, pi.Name)); + throw new ArgumentException(SR.Format(SR.Argument_PropertyClassUnmatchedWithConstructor, pi.Name)); if (!IsValidType(pi.PropertyType)) - throw new ArgumentException(string.Format(SR.Argument_PropertyInvalidType, pi.Name)); + throw new ArgumentException(SR.Format(SR.Argument_PropertyInvalidType, pi.Name)); if (!IsValidValue(pi.PropertyType, propertyValues[i])) - throw new ArgumentException(string.Format(SR.Argument_PropertyInvalidValue, pi.Name)); + throw new ArgumentException(SR.Format(SR.Argument_PropertyInvalidValue, pi.Name)); if (propertyValues[i] != null) { if (!(pi.PropertyType is TypeBuilder) && !pi.PropertyType.IsEnum && !pi.PropertyType.IsInstanceOfType(propertyValues[i])) if (!pi.PropertyType.IsArray) - throw new ArgumentException(string.Format(SR.Argument_PropertyUnmatchingPropertyType, pi.Name, pi.PropertyType, propertyValues[i])); + throw new ArgumentException(SR.Format(SR.Argument_PropertyUnmatchingPropertyType, pi.Name, pi.PropertyType, propertyValues[i])); } i++; } @@ -246,17 +246,17 @@ private void Initialize(ConstructorInfo con, object?[] constructorArgs, { Type paramType = pi.ParameterType; if (!IsValidType(paramType)) - throw new ArgumentException(string.Format(SR.Argument_ParameterInvalidType, i)); + throw new ArgumentException(SR.Format(SR.Argument_ParameterInvalidType, i)); if (!IsValidValue(paramType, constructorArgs[i])) - throw new ArgumentException(string.Format(SR.Argument_ParameterInvalidValue, i)); + throw new ArgumentException(SR.Format(SR.Argument_ParameterInvalidValue, i)); if (constructorArgs[i] != null) { if (!(paramType is TypeBuilder) && !paramType.IsEnum && !paramType.IsInstanceOfType(constructorArgs[i])) if (!paramType.IsArray) - throw new ArgumentException(string.Format(SR.Argument_ParameterHasUnmatchedArgumentValue, i, paramType, constructorArgs[i])); + throw new ArgumentException(SR.Format(SR.Argument_ParameterHasUnmatchedArgumentValue, i, paramType, constructorArgs[i])); if (!IsValidParam(constructorArgs[i]!, paramType)) - throw new ArgumentException(string.Format(SR.Argument_CustomAttributeInvalidType, constructorArgs[i]!.GetType())); + throw new ArgumentException(SR.Format(SR.Argument_CustomAttributeInvalidType, constructorArgs[i]!.GetType())); } } i++; @@ -401,7 +401,7 @@ internal static UnmanagedMarshal get_umarshal(CustomAttributeBuilder customBuild marshalCookie = decode_string(data, pos, out pos)!; break; default: - throw new Exception(string.Format(SR.Exception_UnknownMarshalAsAttributeField, named_name)); + throw new Exception(SR.Format(SR.Exception_UnknownMarshalAsAttributeField, named_name)); } } @@ -449,7 +449,7 @@ private static Type elementTypeToType(int elementType) => 0x0c => typeof(float), 0x0d => typeof(double), 0x0e => typeof(string), - _ => throw new Exception(string.Format(SR.Exception_UnknownElementType, elementType)), + _ => throw new Exception(SR.Format(SR.Exception_UnknownElementType, elementType)), }; private static object? decode_cattr_value(Type t, byte[] data, int pos, out int rpos) @@ -478,9 +478,9 @@ private static Type elementTypeToType(int elementType) => if (subtype >= 0x02 && subtype <= 0x0e) return decode_cattr_value(elementTypeToType(subtype), data, pos, out rpos); else - throw new Exception(string.Format(SR.Exception_UnhandledSubType, subtype)); + throw new Exception(SR.Format(SR.Exception_UnhandledSubType, subtype)); default: - throw new Exception(string.Format(SR.Exception_UnhandledFixMeType, t)); + throw new Exception(SR.Format(SR.Exception_UnhandledFixMeType, t)); } } @@ -506,7 +506,7 @@ internal static CustomAttributeInfo decode_cattr(CustomAttributeBuilder customBu // Prolog if (data.Length < 2) - throw new Exception(string.Format(SR.Exception_InvalidCustomAttributeLength, data.Length)); + throw new Exception(SR.Format(SR.Exception_InvalidCustomAttributeLength, data.Length)); if ((data[0] != 0x1) || (data[1] != 0x00)) throw new Exception(SR.Exception_InvalidProlog); pos = 2; @@ -545,7 +545,7 @@ internal static CustomAttributeInfo decode_cattr(CustomAttributeBuilder customBu /* Field */ FieldInfo? fi = ctor.DeclaringType!.GetField(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (fi == null) - throw new Exception(string.Format(SR.Exception_EmptyFieldForCustomAttributeType, ctor.DeclaringType, name)); + throw new Exception(SR.Format(SR.Exception_EmptyFieldForCustomAttributeType, ctor.DeclaringType, name)); object? val = decode_cattr_value(fi.FieldType, data, pos, out pos); if (enum_type_name != null) @@ -558,7 +558,7 @@ internal static CustomAttributeInfo decode_cattr(CustomAttributeBuilder customBu } else // FIXME: - throw new Exception(string.Format(SR.Exception_UnknownNamedType, named_type)); + throw new Exception(SR.Format(SR.Exception_UnknownNamedType, named_type)); } return info; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs index b6c1125716a8fc..6d4cce0c1f4c9b 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs @@ -453,12 +453,12 @@ protected override bool IsByRefImpl() public override Type MakeArrayType() { - throw new ArgumentException(SR.Argument_CannotCreateByrefTypeOfExistingByrefType); + throw new ArgumentException(SR.Argument_CannotCreateArrayOfByrefType); } public override Type MakeArrayType(int rank) { - throw new ArgumentException(SR.Argument_CannotCreateByrefTypeOfExistingByrefType); + throw new ArgumentException(SR.Argument_CannotCreateArrayOfByrefType); } public override Type MakeByRefType() diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs index d7c8b166c8c8b3..99e43e3ce5d3fc 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs @@ -917,7 +917,7 @@ internal void label_fixup(MethodBase mb) for (int i = 0; i < num_fixups; ++i) { if (labels![fixups![i].label_idx].addr < 0) - throw new ArgumentException(string.Format(SR.Argument_LabelUnmarked, fixups[i].label_idx + 1, mb.Name)); + throw new ArgumentException(SR.Format(SR.Argument_LabelUnmarked, fixups[i].label_idx + 1, mb.Name)); // Diff is the offset from the end of the jump instruction to the address of the label int diff = labels[fixups[i].label_idx].addr - (fixups[i].pos + fixups[i].offset); if (fixups[i].offset == 1) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs index ade90f60c404db..6fe889747d6166 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs @@ -351,7 +351,7 @@ internal void check_override() foreach (MethodInfo m in override_methods) { if (m.IsVirtual && !IsVirtual) - throw new TypeLoadException(string.Format("Method '{0}' override '{1}' but it is not virtual", name, m)); + throw new TypeLoadException(SR.Format("Method '{0}' override '{1}' but it is not virtual", name, m)); } } } @@ -363,7 +363,7 @@ internal void fixup() // do not allow zero length method body on MS.NET 2.0 (and higher) if (((ilgen == null) || (ilgen.ILOffset == 0)) && (code == null || code.Length == 0)) throw new InvalidOperationException( - string.Format("Method '{0}.{1}' does not have a method body.", + SR.Format("Method '{0}.{1}' does not have a method body.", DeclaringType!.FullName, Name)); } ilgen?.label_fixup(this); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs index 0a172d3696c6b0..abd16fb0cdec30 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs @@ -140,7 +140,7 @@ public override ParameterInfo[] GetIndexParameters() public override string ToString() { - return string.Format("{0} {1}", PropertyType, Name); + return SR.Format("{0} {1}", PropertyType, Name); } public override object? GetValue(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? index, CultureInfo? culture) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs index 93354591d0a0fb..6c9dd1a113b68a 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs @@ -204,7 +204,7 @@ private static void ValidateCustomModifier(int n, Type[][]? custom_modifiers, st return; if (custom_modifiers.Length != n) - throw new ArgumentException(string.Format(SR.Argument_CustomModifierLengthInvalidLength, custom_modifiers.Length)); + throw new ArgumentException(SR.Format(SR.Argument_CustomModifierLengthInvalidLength, custom_modifiers.Length)); foreach (Type[] parameter_modifiers in custom_modifiers) { diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs index 0414f078191022..b40429eb302666 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs @@ -756,19 +756,19 @@ public Type CreateType() if (parent != null) { if (parent.IsSealed) - throw new TypeLoadException(string.Format(SR.TypeLoad_AssemblySealedParentTypeError, fullname.DisplayName, Assembly)); + throw new TypeLoadException(SR.Format(SR.TypeLoad_AssemblySealedParentTypeError, fullname.DisplayName, Assembly)); if (parent.IsGenericTypeDefinition) throw new BadImageFormatException(); } if (parent == typeof(Enum) && methods != null) - throw new TypeLoadException(string.Format(SR.TypeLoad_AssemblyEnumContainsMethodsError, fullname.DisplayName, Assembly)); + throw new TypeLoadException(SR.Format(SR.TypeLoad_AssemblyEnumContainsMethodsError, fullname.DisplayName, Assembly)); if (interfaces != null) { foreach (Type iface in interfaces) { if (iface.IsNestedPrivate && iface.Assembly != Assembly) - throw new TypeLoadException(string.Format( SR.TypeLoad_AssemblyInaccessibleInterfaceError, fullname.DisplayName, Assembly, iface.FullName )); + throw new TypeLoadException(SR.Format( SR.TypeLoad_AssemblyInaccessibleInterfaceError, fullname.DisplayName, Assembly, iface.FullName )); if (iface.IsGenericTypeDefinition) throw new BadImageFormatException(); if (!iface.IsInterface) @@ -785,7 +785,7 @@ public Type CreateType() { MethodBuilder mb = (MethodBuilder)(methods[i]); if (is_concrete && mb.IsAbstract) - throw new InvalidOperationException(string.Format(SR.InvalidOperation_AbstractMethod, mb)); + throw new InvalidOperationException(SR.Format(SR.InvalidOperation_AbstractMethod, mb)); mb.check_override(); mb.fixup(); } @@ -1308,7 +1308,7 @@ public override Type MakeGenericType(params Type[] typeArguments) ArgumentNullException.ThrowIfNull(typeArguments); if (generic_params!.Length != typeArguments.Length) - throw new ArgumentException(string.Format(SR.Argument_GenericArgumentsOverflow, generic_params.Length, typeArguments.Length), nameof(typeArguments)); + throw new ArgumentException(SR.Format(SR.Argument_GenericArgumentsOverflow, generic_params.Length, typeArguments.Length), nameof(typeArguments)); foreach (Type t in typeArguments) { @@ -1801,7 +1801,7 @@ public static MethodInfo GetMethod(Type type, MethodInfo method) MethodInfo res = type.GetMethod(method); if (res == null) - throw new ArgumentException(string.Format(SR.Argument_MethodNotFoundInType, method.Name, type)); + throw new ArgumentException(SR.Format(SR.Argument_MethodNotFoundInType, method.Name, type)); return res; } @@ -1960,7 +1960,7 @@ internal static bool SetConstantValue(Type destType, object? value, ref object? destValue = ticks; return true; default: - throw new ArgumentException(string.Format(SR.Argument_ConstantNotSupported, type!.ToString())); + throw new ArgumentException(SR.Format(SR.Argument_ConstantNotSupported, type!.ToString())); } } else diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 26a0efaee44d21..cf510e9ac13f26 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -428,7 +428,7 @@ public override Assembly GetSatelliteAssembly(CultureInfo culture, Version? vers if (res == assembly) res = null; if (res == null && throwOnFileNotFound) - throw new FileNotFoundException(string.Format(culture, SR.IO_FileNotFound_FileName, an.Name)); + throw new FileNotFoundException(SR.Format(culture, SR.IO_FileNotFound_FileName, an.Name)); return res; } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs index fec4ff905cf21e..578c84f7b9fc10 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs @@ -203,7 +203,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) if (obj == null) throw new TargetException(SR.Target_NonStaticFieldRequirement); if (!DeclaringType!.IsAssignableFrom(obj.GetType())) - throw new ArgumentException(string.Format(SR.Arg_FieldDeclTarget, Name, DeclaringType, obj.GetType()), nameof(obj)); + throw new ArgumentException(SR.Format(SR.Arg_FieldDeclTarget, Name, DeclaringType, obj.GetType()), nameof(obj)); } if (!IsLiteral) @@ -214,7 +214,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) public override string ToString() { - return string.Format("{0} {1}", FieldType, name); + return SR.Format("{0} {1}", FieldType, name); } [MethodImplAttribute(MethodImplOptions.InternalCall)] @@ -227,7 +227,7 @@ public override void SetValue(object? obj, object? val, BindingFlags invokeAttr, if (obj == null) throw new TargetException(SR.Target_NonStaticFieldRequirement); if (!DeclaringType!.IsAssignableFrom(obj.GetType())) - throw new ArgumentException(string.Format(SR.Arg_FieldDeclTarget, Name, DeclaringType, obj.GetType()), nameof(obj)); + throw new ArgumentException(SR.Format(SR.Arg_FieldDeclTarget, Name, DeclaringType, obj.GetType()), nameof(obj)); } if (IsLiteral) throw new FieldAccessException(SR.FieldAccess_CannotSetConstantField); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs index 69e04aa57b1e81..465918c628e97c 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs @@ -622,11 +622,11 @@ public override MethodInfo MakeGenericMethod(Type[] methodInstantiation) ArgumentNullException.ThrowIfNull(methodInstantiation); if (!IsGenericMethodDefinition) - throw new InvalidOperationException(string.Format(SR.Arg_NotGenericMethodDefinition, nameof(methodInstantiation))); + throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericMethodDefinition, nameof(methodInstantiation))); /*FIXME add GetGenericArgumentsLength() internal vcall to speed this up*/ if (GetGenericArguments().Length != methodInstantiation.Length) - throw new ArgumentException(string.Format(SR.Argument_IncorrectLength, nameof(methodInstantiation))); + throw new ArgumentException(SR.Format(SR.Argument_IncorrectLength, nameof(methodInstantiation))); bool hasUserType = false; foreach (Type type in methodInstantiation) @@ -647,7 +647,7 @@ public override MethodInfo MakeGenericMethod(Type[] methodInstantiation) MethodInfo ret = MakeGenericMethod_impl(methodInstantiation); if (ret == null) - throw new ArgumentException(string.Format(SR.Argument_GenericArgumentsOverflow, GetGenericArguments().Length, methodInstantiation.Length)); + throw new ArgumentException(SR.Format(SR.Argument_GenericArgumentsOverflow, GetGenericArguments().Length, methodInstantiation.Length)); return ret; } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs index a4ee059ee1616c..44577f2e660604 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs @@ -370,9 +370,9 @@ internal static Exception resolve_token_exception(Module module, int metadataTok internal static Exception resolve_token_exception(string name, int metadataToken, ResolveTokenError error, string tokenType) { if (error == ResolveTokenError.OutOfRange) - return new ArgumentOutOfRangeException(nameof(metadataToken), string.Format("Token 0x{0:x} is not valid in the scope of module {1}", metadataToken, name)); + return new ArgumentOutOfRangeException(nameof(metadataToken), SR.Format("Token 0x{0:x} is not valid in the scope of module {1}", metadataToken, name)); else - return new ArgumentException(string.Format("Token 0x{0:x} is not a valid {1} token in the scope of module {2}", metadataToken, tokenType, name), nameof(metadataToken)); + return new ArgumentException(SR.Format("Token 0x{0:x} is not a valid {1} token in the scope of module {2}", metadataToken, tokenType, name), nameof(metadataToken)); } internal static IntPtr[]? ptrs_from_types(Type[]? types) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs index 7c119d529c9ab5..0a47c3bfa7af2d 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs @@ -256,7 +256,7 @@ int MetadataToken { return GetMetadataToken(); } - throw new ArgumentException(string.Format(SR.NoMetadataTokenAvailable, MemberImpl.GetType())); + throw new ArgumentException(SR.Format(SR.NoMetadataTokenAvailable, MemberImpl.GetType())); } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs index 10bbf940ed65ce..bd628a30c7f0b7 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs @@ -454,7 +454,7 @@ public override void SetValue(object? obj, object? value, BindingFlags invokeAtt { MethodInfo? method = GetSetMethod(true); if (method == null) - throw new ArgumentException(string.Format(SR.Argument_SetMethodNotFound, Name)); + throw new ArgumentException(SR.Format(SR.Argument_SetMethodNotFound, Name)); object?[] parms; if (index == null || index.Length == 0) diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index 1cdab97bbd67df..07f48ef136d589 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -1636,7 +1636,7 @@ internal override FieldInfo GetField(FieldInfo fromNoninstanciated) // TODO: .net does more checks in unmanaged land in RuntimeTypeHandle::CreateInstance if (IsAbstract) { - throw new MissingMethodException(string.Format(SR.MissingMethod_CannotCreateAbstractClass, FullName)); + throw new MissingMethodException(SR.Format(SR.MissingMethod_CannotCreateAbstractClass, FullName)); } unsafe @@ -1970,7 +1970,7 @@ public override Type MakeByRefType() public override Type MakePointerType() { if (IsByRef) - throw new TypeLoadException(string.Format(SR.ClassLoad_General, GetType(), AssemblyQualifiedName)); + throw new TypeLoadException(SR.Format(SR.ClassLoad_General, GetType(), AssemblyQualifiedName)); Type? type = null; var base_type = this; make_pointer_type(new QCallTypeHandle(ref base_type), ObjectHandleOnStack.Create(ref type)); diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index 93c5e3a855c3ee..8c68159a86dbdf 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs @@ -384,7 +384,7 @@ internal static bool IsTypeDefinition(RuntimeType type) ref stackMark, ObjectHandleOnStack.Create (ref t), throwOnError, ignoreCase); if (throwOnError && t == null) - throw new TypeLoadException(string.Format(SR.TypeLoad_TypeNotLoaded, typeName)); + throw new TypeLoadException(SR.Format(SR.TypeLoad_TypeNotLoaded, typeName)); } return t; } diff --git a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs index ef0accc8a39c18..03fc8dce17cb3c 100644 --- a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs +++ b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs @@ -472,7 +472,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo if (name[pos] == ']') ++pos; else - throw new ArgumentException(string.Format(SR.Argument_UnclosedAssemblyQualifiedTypeName, name[pos]), "typeName"); + throw new ArgumentException(SR.Format(SR.Argument_UnclosedAssemblyQualifiedTypeName, name[pos]), "typeName"); BoundCheck(pos, name); } @@ -481,7 +481,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo if (name[pos] == ',') ++pos; // skip ',' to the start of the next arg else - throw new ArgumentException(string.Format(SR.Argument_InvalidGenericArgumentsSeparator, name[pos]), "typeName"); + throw new ArgumentException(SR.Format(SR.Argument_InvalidGenericArgumentsSeparator, name[pos]), "typeName"); } if (pos >= name.Length || name[pos] != ']') @@ -501,7 +501,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo bound = true; } else if (name[pos] != ',') - throw new ArgumentException(string.Format(SR.Argument_InvalidCharInArraySpecification, name[pos]), "typeName"); + throw new ArgumentException(SR.Format(SR.Argument_InvalidCharInArraySpecification, name[pos]), "typeName"); else ++dimensions; @@ -524,7 +524,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo } throw new ArgumentException(SR.Argument_UnmatchedSquareBracketWhileParsingGenericArgAssemblyName, "typeName"); default: - throw new ArgumentException(string.Format(SR.Argument_BadTypeDef, name[pos], pos), "typeName"); + throw new ArgumentException(SR.Format(SR.Argument_BadTypeDef, name[pos], pos), "typeName"); } } } From 9838ae595a05b11e2432081c589571faf0778ed3 Mon Sep 17 00:00:00 2001 From: databunks Date: Wed, 23 Nov 2022 18:47:43 +0000 Subject: [PATCH 04/22] fixes SRformat only used in exceptions & resx refs --- .../System.Private.CoreLib/src/Resources/Strings.resx | 9 +++++++++ .../System.Private.CoreLib/src/System/ModuleHandle.cs | 6 +++--- .../src/System/Reflection/Emit/AssemblyBuilder.Mono.cs | 2 +- .../src/System/Reflection/Emit/MethodBuilder.Mono.cs | 4 ++-- .../System/Reflection/Emit/PropertyOnTypeBuilderInst.cs | 2 +- .../src/System/Reflection/RuntimeFieldInfo.cs | 2 +- .../src/System/Reflection/RuntimeModule.cs | 4 ++-- .../src/System/TypeLoadException.Mono.cs | 2 +- 8 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index d9318a25a48932..a36fa21091caa7 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -2988,6 +2988,9 @@ Method '{0}.{1}' not found. + + Method '{0}.{1}' does not have a method body. + Cannot create an abstract class '{0}'. @@ -4176,6 +4179,9 @@ Could not load type '{0}' from assembly '{1}'. + + Could not load type '0x{0:x}' from assembly '0x{1:x}'. + '{0}' from assembly '{1}' has too many dimensions. @@ -4275,6 +4281,9 @@ The type '{0}' cannot be found in assembly '{1}'. + + Method '{0}' override '{1}' but it is not virtual. + Cannot load assembly '{0}'. No metadata found for this assembly. diff --git a/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs b/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs index 19239ea2b4e133..1617bae1e68277 100644 --- a/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs +++ b/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs @@ -71,7 +71,7 @@ public RuntimeTypeHandle ResolveTypeHandle(int typeToken, RuntimeTypeHandle[]? t throw new ArgumentNullException(string.Empty, "Invalid handle"); IntPtr res = RuntimeModule.ResolveTypeToken(value, typeToken, ptrs_from_handles(typeInstantiationContext), ptrs_from_handles(methodInstantiationContext), out _); if (res == IntPtr.Zero) - throw new TypeLoadException(SR.Format("Could not load type '0x{0:x}' from assembly '0x{1:x}'", typeToken, value.ToInt64())); + throw new TypeLoadException(SR.Format(SR.ClassLoad_General_Hex, typeToken, value.ToInt64())); else return new RuntimeTypeHandle(res); } @@ -83,7 +83,7 @@ public RuntimeMethodHandle ResolveMethodHandle(int methodToken, RuntimeTypeHandl throw new ArgumentNullException(string.Empty, "Invalid handle"); IntPtr res = RuntimeModule.ResolveMethodToken(value, methodToken, ptrs_from_handles(typeInstantiationContext), ptrs_from_handles(methodInstantiationContext), out _); if (res == IntPtr.Zero) - throw new Exception(SR.Format("Could not load method '0x{0:x}' from assembly '0x{1:x}'", methodToken, value.ToInt64())); + throw new Exception(SR.Format(SR.ClassLoad_General_Hex, methodToken, value.ToInt64())); else return new RuntimeMethodHandle(res); } @@ -96,7 +96,7 @@ public RuntimeFieldHandle ResolveFieldHandle(int fieldToken, RuntimeTypeHandle[] IntPtr res = RuntimeModule.ResolveFieldToken(value, fieldToken, ptrs_from_handles(typeInstantiationContext), ptrs_from_handles(methodInstantiationContext), out _); if (res == IntPtr.Zero) - throw new Exception(SR.Format("Could not load field '0x{0:x}' from assembly '0x{1:x}'", fieldToken, value.ToInt64())); + throw new Exception(SR.Format(SR.ClassLoad_General_Hex, fieldToken, value.ToInt64())); else return new RuntimeFieldHandle(res); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs index 62a0143f9c199e..35090215e5b657 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs @@ -336,7 +336,7 @@ internal static Type MakeGenericType(Type gtd, Type[] typeArguments) => if (res is TypeBuilder) { if (throwOnError) - throw new TypeLoadException(SR.Format("Could not load type '{0}' from assembly '{1}'", name, this.name)); + throw new TypeLoadException(SR.Format(SR.ClassLoad_General, name, this.name)); return null; } return res; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs index 6fe889747d6166..53e27a8078fa73 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs @@ -351,7 +351,7 @@ internal void check_override() foreach (MethodInfo m in override_methods) { if (m.IsVirtual && !IsVirtual) - throw new TypeLoadException(SR.Format("Method '{0}' override '{1}' but it is not virtual", name, m)); + throw new TypeLoadException(SR.Format(SR.TypeLoad_MethodOverrideNotVirtual, name, m)); } } } @@ -363,7 +363,7 @@ internal void fixup() // do not allow zero length method body on MS.NET 2.0 (and higher) if (((ilgen == null) || (ilgen.ILOffset == 0)) && (code == null || code.Length == 0)) throw new InvalidOperationException( - SR.Format("Method '{0}.{1}' does not have a method body.", + SR.Format(SR.MissingMethod_Body, DeclaringType!.FullName, Name)); } ilgen?.label_fixup(this); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs index abd16fb0cdec30..0a172d3696c6b0 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/PropertyOnTypeBuilderInst.cs @@ -140,7 +140,7 @@ public override ParameterInfo[] GetIndexParameters() public override string ToString() { - return SR.Format("{0} {1}", PropertyType, Name); + return string.Format("{0} {1}", PropertyType, Name); } public override object? GetValue(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? index, CultureInfo? culture) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs index 578c84f7b9fc10..f09bec79c77bb9 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs @@ -214,7 +214,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) public override string ToString() { - return SR.Format("{0} {1}", FieldType, name); + return string.Format("{0} {1}", FieldType, name); } [MethodImplAttribute(MethodImplOptions.InternalCall)] diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs index 44577f2e660604..74ef00dc7f8c2b 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs @@ -370,9 +370,9 @@ internal static Exception resolve_token_exception(Module module, int metadataTok internal static Exception resolve_token_exception(string name, int metadataToken, ResolveTokenError error, string tokenType) { if (error == ResolveTokenError.OutOfRange) - return new ArgumentOutOfRangeException(nameof(metadataToken), SR.Format("Token 0x{0:x} is not valid in the scope of module {1}", metadataToken, name)); + return new ArgumentOutOfRangeException(nameof(metadataToken), SR.Format(SR.Argument_InvalidToken, metadataToken, name)); else - return new ArgumentException(SR.Format("Token 0x{0:x} is not a valid {1} token in the scope of module {2}", metadataToken, tokenType, name), nameof(metadataToken)); + return new ArgumentException(SR.Format(SR.Argument_ResolveType, metadataToken, tokenType, name), nameof(metadataToken)); } internal static IntPtr[]? ptrs_from_types(Type[]? types) diff --git a/src/mono/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs b/src/mono/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs index a531a773e515bc..12f3ae39a8616d 100644 --- a/src/mono/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs @@ -24,7 +24,7 @@ private void SetMessageField() return; } - _message = SR.Format("Could not load type '{0}' from assembly '{1}'.", _className, _assemblyName ?? SR.IO_UnknownFileName); + _message = string.Format(SR.ClassLoad_General, _className, _assemblyName ?? SR.IO_UnknownFileName); } } } From 3eeec78e1b2f85791ffa62914a67f51b598949c5 Mon Sep 17 00:00:00 2001 From: databunks Date: Wed, 23 Nov 2022 18:51:24 +0000 Subject: [PATCH 05/22] fixing small typo --- .../System.Private.CoreLib/src/System/TypeLoadException.Mono.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs b/src/mono/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs index 12f3ae39a8616d..9f4f4ced458b04 100644 --- a/src/mono/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/TypeLoadException.Mono.cs @@ -24,7 +24,7 @@ private void SetMessageField() return; } - _message = string.Format(SR.ClassLoad_General, _className, _assemblyName ?? SR.IO_UnknownFileName); + _message = SR.Format(SR.ClassLoad_General, _className, _assemblyName ?? SR.IO_UnknownFileName); } } } From 98392ba75a6925922bb2e293d932c2a2b94c0ba9 Mon Sep 17 00:00:00 2001 From: databunks Date: Sun, 4 Dec 2022 13:57:20 +0000 Subject: [PATCH 06/22] de-duplication + suggested changes --- .../System/Reflection/Emit/ModuleBuilder.cs | 4 +- .../src/Resources/Strings.resx | 135 +++--------------- .../src/Mono/HotReload.cs | 2 +- .../src/System/ArgIterator.cs | 6 +- .../src/System/Reflection/CustomAttribute.cs | 14 +- .../Emit/ConstructorBuilder.Mono.cs | 4 +- .../Emit/CustomAttributeBuilder.Mono.cs | 8 +- .../Reflection/Emit/DerivedTypes.Mono.cs | 6 +- .../Reflection/Emit/ILGenerator.Mono.cs | 20 +-- .../Reflection/Emit/MethodBuilder.Mono.cs | 6 +- .../Emit/MethodOnTypeBuilderInst.cs | 2 +- .../Reflection/Emit/ModuleBuilder.Mono.cs | 4 +- .../System/Reflection/Emit/SignatureHelper.cs | 10 +- .../Reflection/Emit/TypeBuilder.Mono.cs | 18 ++- .../Emit/TypeBuilderInstantiation.cs | 2 +- .../src/System/Reflection/RuntimeFieldInfo.cs | 6 +- .../Reflection/RuntimeMethodInfo.Mono.cs | 4 +- .../System/Reflection/RuntimeParameterInfo.cs | 2 +- .../src/System/RuntimeType.Mono.cs | 18 +-- .../src/System/RuntimeTypeHandle.cs | 3 +- .../src/System/Type.Mono.cs | 6 +- .../src/System/TypeSpec.cs | 8 +- 22 files changed, 94 insertions(+), 194 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs index 5737bfc484baac..2754ad40d53321 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs @@ -799,7 +799,7 @@ public MethodBuilder DefinePInvokeMethod(string name, string dllName, string ent // Global methods must be static. if ((attributes & MethodAttributes.Static) == 0) { - throw new ArgumentException(SR.Argument_GlobalFunctionHasToBeStatic); + throw new ArgumentException(SR.Argument_GlobalMethodsMustBeStatic); } return _globalTypeBuilder.DefinePInvokeMethod(name, dllName, entryName, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet); @@ -829,7 +829,7 @@ private MethodBuilder DefineGlobalMethodNoLock(string name, MethodAttributes att ArgumentException.ThrowIfNullOrEmpty(name); if ((attributes & MethodAttributes.Static) == 0) { - throw new ArgumentException(SR.Argument_GlobalFunctionHasToBeStatic); + throw new ArgumentException(SR.Argument_GlobalMethodsMustBeStatic); } return _globalTypeBuilder.DefineMethod(name, attributes, callingConvention, diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index a36fa21091caa7..858c8454531ae1 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -160,7 +160,7 @@ The serialization stream contains no inner exceptions. - (Inner Exception #{0}) + (Inner Exception #{0}) This text is prepended to each inner exception description during aggregate exception formatting @@ -280,9 +280,6 @@ Delegates must be of the same type. - - DllName cannot be empty. - Dll was not found. @@ -329,7 +326,7 @@ External component has thrown an exception. - EnC: Expected a primitive, valuetype, class or interface field + EnC: Expected a primitive, valuetype, class or interface field. Attempted to access a field that is not accessible by the caller. @@ -358,8 +355,8 @@ One of the identified items was in an invalid format. - - Generic arguments after array spec or pointer type + + Generic arguments after array spec or pointer type. Method must be called on a Type for which Type.IsGenericParameter is false. @@ -657,9 +654,6 @@ Object reference not set to an instance of an object. - - Type handle was null {0}. - Object type cannot be converted to target type. @@ -846,9 +840,6 @@ 'handle' has already been bound to the thread pool, or was not opened for asynchronous I/O. - - Array spec cannot have 2 bound dimensions. - Interface maps for generic interfaces on arrays cannot be retrieved. @@ -931,13 +922,7 @@ An invalid type was used as a custom attribute constructor argument, field or property. - An invalid type was used as a custom attribute constructor argument, field or property. - - - Cannot create a byref type of an already byref type. - - - Cannot create an array type of a byref type. + Byref qualifier must be the last one of a type. Can't have a pointer to a byref type. @@ -951,9 +936,6 @@ Can't have a byref of a byref. - - Can't have a pointer to a byref type - {0} is not a supported code page. @@ -978,9 +960,6 @@ The specified constructor must be declared on a generic type definition. - - Constructor not found. - Conversion buffer overflow. @@ -1011,14 +990,11 @@ Resolved assembly's simple name should be the same as of the requested assembly. - - Cannot emit a CustomAttribute with argument of type {0}. - Customized cultures cannot be passed by LCID, only by name. - Custom modifiers length `{0}' does not match the size of the arguments. + Custom modifiers length '{0}' does not match the size of the arguments. The binary data must result in a DateTime with ticks between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. @@ -1080,9 +1056,6 @@ The argument type, '{0}', is not the same as the enum type '{1}'. - - Do not supply an exception type for filter clause. - Cannot change fallback when buffer is not empty. Previous Convert() call left data in the fallback buffer. @@ -1110,9 +1083,6 @@ The number of generic arguments provided doesn't equal the arity of the generic type definition. - - The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter. - Generic argument can't be byref or pointer type. @@ -1125,11 +1095,8 @@ Open Generic Type not permitted. - - Get Method not found for '{Name}' - - - Global members must be static. + + Global methods must be static. Must be an array type. @@ -1168,7 +1135,7 @@ The property handle and the type handle are incompatible. - Incorrect length. + Incorrect Argument length. 'this' type cannot be an interface itself. @@ -1339,9 +1306,6 @@ Null character in path. - - Elements of the parameterTypes array cannot be null. - The given culture name '{0}' cannot be used to locate a resource file. Resource filenames must consist of only letters, numbers, hyphens or underscores. @@ -1399,15 +1363,9 @@ Method '{0}' has a generic declaring type '{1}'. Explicitly provide the declaring type to GetTokenFor. - - Method is not a generic method definition. - The specified method cannot be dynamic or global and must be declared on a generic type definition. - - Method {0} not found in type {1}. - '{0}' cannot be greater than {1}. @@ -1415,7 +1373,7 @@ Two arrays, {0} and {1}, must be of the same size. - was missing default constructor. + Was missing default constructor. Argument must be initialized to false @@ -1430,7 +1388,7 @@ MethodInfo must be a runtime MethodInfo object. - Type must be a runtime Type object. + 'type' must contain a TypeBuilder as a generic argument. 'type' must contain a TypeBuilder as a generic argument. @@ -1441,9 +1399,6 @@ The specified structure must be blittable or have layout information. - - Argument must be an interface. - 'overlapped' has already been freed. @@ -1531,14 +1486,11 @@ The DateStart property must come before the DateEnd property. - - Output streams do not support TypeBuilders. - Path cannot be the empty string or all whitespace. - Value of argument {0} + does not match parameter type: {1} -> {2}. + Value of argument {0} does not match parameter type: {1} -> {2}. Parameter {0} does not have a valid type. @@ -1642,9 +1594,6 @@ Type should be an exception type. - - Type should have a default constructor. - The type must not be imported from COM. @@ -1676,7 +1625,7 @@ Local passed in does not belong to this ILGenerator. - Unmatched ']' while parsing generic argument assembly name + Unmatched ']' while parsing generic argument assembly name Non-matching symbol scope. @@ -1696,9 +1645,6 @@ Interface not found. - - ModuleBuilder is expected. - The object is not an array with the same number of elements as the array to compare it to. @@ -2096,9 +2042,6 @@ The SyncRoot property may not be used for the synchronization of concurrent collections. - - Invalid custom attribute format. - Task {2} completed. @@ -2306,10 +2249,6 @@ Event {0} was called with a different type as defined (argument "{1}"). This may cause the event to be displayed incorrectly. - - Error in customattr. - - Custom attribute type '{0}' doesn't contain a field named '{1}' @@ -2325,20 +2264,14 @@ Prolog invalid. - - Unknown element type '{0}'. - Unknown named type: {0} Unknown MarshalAsAttribute field: {0}. - - FIXME: Type {0} not yet handled in decode_cattr_value. - - Subtype '{0}' of type object not yet handled in decode_cattr_value + Subtype '{0}' of type object not yet handled Exception of type '{0}' was thrown. @@ -2346,9 +2279,6 @@ An exception was not handled in an AsyncLocal<T> notification callback. - - Cannot set a constant field - Could not resolve assembly '{0}'. @@ -2571,7 +2501,7 @@ Object cannot be stored in an array of this type. - Type is concrete but has abstract method {0} + Type is concrete but has abstract method {0}. AsyncFlowControl objects can be used to restore flow only on a Context that had its flow suppressed. @@ -2663,9 +2593,6 @@ The generic parameters are already defined on this MethodBuilder. - - can only be called in generic type. - OSVersion's call to GetVersionEx failed. @@ -2684,18 +2611,12 @@ Failed to compare two elements in the array. - - Iterator is at an invalid position - Type definition of the method is complete. The signature of the MethodBuilder can no longer be modified because an operation on the MethodBuilder caused the methodDef token to be created. For example, a call to SetCustomAttribute requires the methodDef token to emit the CustomAttribute token. - - Method '{0}' does not have a method body. - Method already has a body. @@ -2751,9 +2672,6 @@ The requested operation is invalid when called on a null ModuleHandle. - - Object fields may not be properly initialized. - Local variable scope was not properly closed. @@ -2991,9 +2909,6 @@ Method '{0}.{1}' does not have a method body. - - Cannot create an abstract class '{0}'. - The satellite assembly named "{1}" for fallback culture "{0}" either could not be found or could not be loaded. This is generally a setup problem. Please consider reinstalling or repairing the application. @@ -3049,7 +2964,7 @@ A non-collectible assembly may not reference a collectible assembly. - An element type cannot contain a stack pointer + An element type cannot contain a stack pointer. CreateInstance cannot be used with an object of type TypeBuilder. @@ -3102,9 +3017,6 @@ Methods with UnmanagedCallersOnlyAttribute cannot be used as delegate target. - - User defined subclasses of System.Type are not yet supported. - No data is available for encoding {0}. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. @@ -3129,9 +3041,6 @@ Cannot resolve {0} to a TypeInfo object. - - Not in an exception block - This feature is not implemented. @@ -3204,9 +3113,6 @@ Stream does not support writing. - - User types are not supported under full aot. - Custom marshalers for value types are not currently supported. @@ -3964,7 +3870,7 @@ The value cannot be an empty string. - FrameworkName is invalid. + FrameworkName is invalid. FrameworkName version component is invalid. @@ -4167,9 +4073,6 @@ Attempted to load a type that was not created during ahead of time compilation. - - Field {0} defined on type {1} is not a field on the target object which is of type {2}. - A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property. @@ -4249,7 +4152,7 @@ Type names passed to Assembly.GetType() must not specify an assembly. - There is no metadata token available for the given member, MemberImplementationType: {0}. + There is no metadata token available for the given member. The type '{0}' may not be used as a type argument. @@ -4264,7 +4167,7 @@ The type '{0}' was created by a custom ReflectionContext and cannot be used here. - Type can't be a byref type. + Type can't be a byref type. Cannot create a byref of a byref: {0} diff --git a/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs b/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs index e851e385d0ec63..c69f84e062970e 100644 --- a/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs +++ b/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs @@ -100,7 +100,7 @@ private FieldStore (object? loc) public static FieldStore Create (RuntimeTypeHandle type) { - Type t = Type.GetTypeFromHandle(type) ?? throw new ArgumentException(SR.Format(SR.Arg_NullTypeHandleReferenceException, nameof(type))); + Type t = Type.GetTypeFromHandle(type) ?? throw new ArgumentException(SR.Arg_InvalidHandle, nameof(type)); object? loc; if (t.IsPrimitive || t.IsValueType) loc = RuntimeHelpers.GetUninitializedObject(t); diff --git a/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs b/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs index abb941cfe77fe3..950aaeecfc987d 100644 --- a/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs +++ b/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs @@ -59,7 +59,7 @@ public override int GetHashCode() public TypedReference GetNextArg() { if (num_args == next_arg) - throw new InvalidOperationException(SR.InvalidOperation_InvalidIteratorPosition); + throw new InvalidOperationException(SR.InvalidOperation_EnumEnded); TypedReference result = default; unsafe { @@ -75,7 +75,7 @@ public TypedReference GetNextArg() public TypedReference GetNextArg(RuntimeTypeHandle rth) { if (num_args == next_arg) - throw new InvalidOperationException(SR.InvalidOperation_InvalidIteratorPosition); + throw new InvalidOperationException(SR.InvalidOperation_EnumEnded); TypedReference result = default; unsafe { @@ -90,7 +90,7 @@ public TypedReference GetNextArg(RuntimeTypeHandle rth) public RuntimeTypeHandle GetNextArgType() { if (num_args == next_arg) - throw new InvalidOperationException(SR.InvalidOperation_InvalidIteratorPosition); + throw new InvalidOperationException(SR.InvalidOperation_EnumEnded); return new RuntimeTypeHandle(IntGetNextArgType()); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs index 82461cd4b23d9e..ca99785ccf5f9a 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs @@ -158,7 +158,7 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type if (!inherit && res.Length == 1) { if (res[0] == null) - throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); + throw new CustomAttributeFormatException(SR.Arg_CustomAttributeFormatException); if (attributeType != null) { @@ -206,7 +206,7 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type foreach (object attr in res) { if (attr == null) - throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); + throw new CustomAttributeFormatException(SR.Arg_CustomAttributeFormatException); } var result = new Attribute[res.Length]; res.CopyTo(result, 0); @@ -217,7 +217,7 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type foreach (object attr in res) { if (attr == null) - throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); + throw new CustomAttributeFormatException(SR.Arg_CustomAttributeFormatException); Type attrType = attr.GetType(); if (attributeType != null && !attributeType.IsAssignableFrom(attrType)) @@ -244,7 +244,7 @@ internal static object[] GetCustomAttributes(ICustomAttributeProvider obj, Type { AttributeUsageAttribute usage; if (attr == null) - throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); + throw new CustomAttributeFormatException(SR.Arg_CustomAttributeFormatException); Type attrType = attr.GetType(); if (attributeType != null) @@ -376,7 +376,7 @@ internal static IList GetCustomAttributesData(ICustomAttrib foreach (CustomAttributeData attrData in res) { if (attrData == null) - throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); + throw new CustomAttributeFormatException(SR.Arg_CustomAttributeFormatException); } var result = new CustomAttributeData[res.Count]; @@ -389,7 +389,7 @@ internal static IList GetCustomAttributesData(ICustomAttrib foreach (CustomAttributeData attrData in res) { if (attrData == null) - throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); + throw new CustomAttributeFormatException(SR.Arg_CustomAttributeFormatException); if (!attributeType.IsAssignableFrom(attrData.AttributeType)) continue; a.Add(attrData); @@ -410,7 +410,7 @@ internal static IList GetCustomAttributesData(ICustomAttrib { AttributeUsageAttribute usage; if (attrData == null) - throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat); + throw new CustomAttributeFormatException(SR.Arg_CustomAttributeFormatException); Type attrType = attrData.AttributeType; if (attributeType != null) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs index 2ba215fc05bf69..8940600f0075c6 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs @@ -70,7 +70,7 @@ internal ConstructorBuilder(TypeBuilder tb, MethodAttributes attributes, Calling { for (int i = 0; i < parameterTypes.Length; ++i) if (parameterTypes[i] == null) - throw new ArgumentException(SR.Argument_NullParameterTypes, nameof(parameterTypes)); + throw new ArgumentException(SR.ArgumentNull_TypeRequiredByResourceScope, nameof(parameterTypes)); this.parameters = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); @@ -319,7 +319,7 @@ internal void fixup() if (((attrs & (MethodAttributes.Abstract | MethodAttributes.PinvokeImpl)) == 0) && ((iattrs & (MethodImplAttributes.Runtime | MethodImplAttributes.InternalCall)) == 0)) { if ((ilgen == null) || (ilgen.ILOffset == 0)) - throw new InvalidOperationException(SR.Format(SR.InvalidOperation_MethodDoesNotHaveBody, Name)); + throw new InvalidOperationException(SR.Format(SR.InvalidOperation_BadEmptyMethodBody, Name)); } if (IsStatic && ((call_conv & CallingConventions.VarArgs) != 0 || diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs index ff28b3cce8f12b..b0c0d3f4f698d3 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs @@ -256,7 +256,7 @@ private void Initialize(ConstructorInfo con, object?[] constructorArgs, if (!paramType.IsArray) throw new ArgumentException(SR.Format(SR.Argument_ParameterHasUnmatchedArgumentValue, i, paramType, constructorArgs[i])); if (!IsValidParam(constructorArgs[i]!, paramType)) - throw new ArgumentException(SR.Format(SR.Argument_CustomAttributeInvalidType, constructorArgs[i]!.GetType())); + throw new ArgumentException(SR.Format(SR.Argument_BadParameterTypeForCAB, constructorArgs[i]!.GetType())); } } i++; @@ -449,7 +449,7 @@ private static Type elementTypeToType(int elementType) => 0x0c => typeof(float), 0x0d => typeof(double), 0x0e => typeof(string), - _ => throw new Exception(SR.Format(SR.Exception_UnknownElementType, elementType)), + _ => throw new Exception(SR.Format(SR.ArgumentException_InvalidArrayElementType, elementType)), }; private static object? decode_cattr_value(Type t, byte[] data, int pos, out int rpos) @@ -478,9 +478,9 @@ private static Type elementTypeToType(int elementType) => if (subtype >= 0x02 && subtype <= 0x0e) return decode_cattr_value(elementTypeToType(subtype), data, pos, out rpos); else - throw new Exception(SR.Format(SR.Exception_UnhandledSubType, subtype)); + throw new Exception(SR.Exception_UnhandledSubType); default: - throw new Exception(SR.Format(SR.Exception_UnhandledFixMeType, t)); + throw new Exception("FIXME: Type " + t + " not yet handled in decode_cattr_value."); } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs index 6d4cce0c1f4c9b..c8e3664857b515 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/DerivedTypes.Mono.cs @@ -453,17 +453,17 @@ protected override bool IsByRefImpl() public override Type MakeArrayType() { - throw new ArgumentException(SR.Argument_CannotCreateArrayOfByrefType); + throw new ArgumentException(SR.NotSupported_ByRefLikeArray); } public override Type MakeArrayType(int rank) { - throw new ArgumentException(SR.Argument_CannotCreateArrayOfByrefType); + throw new ArgumentException(SR.NotSupported_ByRefLikeArray); } public override Type MakeByRefType() { - throw new ArgumentException(SR.Argument_CannotCreateByrefTypeOfExistingByrefType); + throw new ArgumentException(SR.CannotCreateByRefOfByRef); } public override Type MakePointerType() diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs index 99e43e3ce5d3fc..9619fe0c88289b 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs @@ -346,13 +346,13 @@ private void InternalEndClause() public virtual void BeginCatchBlock(Type? exceptionType) { if (!InExceptionBlock) - throw new NotSupportedException(SR.NotSupported_NotInAnExceptionBlock); + throw new NotSupportedException(SR.Argument_NotInExceptionBlock); if (exceptionType != null && exceptionType.IsUserType) - throw new NotSupportedException(SR.NotSupported_UserDefinedSubClassesOfSystemTypeNotSupported); + throw new NotSupportedException(SR.PlatformNotSupported_ITypeInfo); if (ex_handlers![cur_block].LastClauseType() == ILExceptionBlock.FILTER_START) { if (exceptionType != null) - throw new ArgumentException(SR.Argument_ExceptionSuppliedForFilterClause); + throw new ArgumentException(SR.Argument_ShouldNotSpecifyExceptionType); Emit(OpCodes.Endfilter); ex_handlers[cur_block].PatchFilterClause(code_len); } @@ -372,7 +372,7 @@ public virtual void BeginCatchBlock(Type? exceptionType) public virtual void BeginExceptFilterBlock() { if (!InExceptionBlock) - throw new NotSupportedException(SR.NotSupported_NotInAnExceptionBlock); + throw new NotSupportedException(SR.Argument_NotInExceptionBlock); InternalEndClause(); ex_handlers![cur_block].AddFilter(code_len); @@ -403,7 +403,7 @@ public virtual Label BeginExceptionBlock() public virtual void BeginFaultBlock() { if (!InExceptionBlock) - throw new NotSupportedException(SR.NotSupported_NotInAnExceptionBlock); + throw new NotSupportedException(SR.Argument_NotInExceptionBlock); if (ex_handlers![cur_block].LastClauseType() == ILExceptionBlock.FILTER_START) { @@ -419,7 +419,7 @@ public virtual void BeginFaultBlock() public virtual void BeginFinallyBlock() { if (!InExceptionBlock) - throw new NotSupportedException(SR.NotSupported_NotInAnExceptionBlock); + throw new NotSupportedException(SR.Argument_NotInExceptionBlock); InternalEndClause(); @@ -446,7 +446,7 @@ public virtual LocalBuilder DeclareLocal(Type localType, bool pinned) { ArgumentNullException.ThrowIfNull(localType); if (localType.IsUserType) - throw new NotSupportedException(SR.NotSupported_UserDefinedSubClassesOfSystemTypeNotSupported); + throw new NotSupportedException(SR.PlatformNotSupported_ITypeInfo); LocalBuilder res = new LocalBuilder(localType, this); res.is_pinned = pinned; @@ -848,7 +848,7 @@ public virtual void EmitWriteLine(LocalBuilder localBuilder) { ArgumentNullException.ThrowIfNull(localBuilder); if (localBuilder.LocalType is TypeBuilder) - throw new ArgumentException(SR.Argument_OutputStreamsNotSupportingTypeBuilders); + throw new NotSupportedException(SR.NotSupported_OutputStreamUsingTypeBuilder); // The MS implementation does not check for valuetypes here but it // should. Emit(OpCodes.Ldloc, localBuilder); @@ -866,7 +866,7 @@ public virtual void EmitWriteLine(string value) public virtual void EndExceptionBlock() { if (!InExceptionBlock) - throw new NotSupportedException(SR.NotSupported_NotInAnExceptionBlock); + throw new NotSupportedException(SR.Argument_NotInExceptionBlock); if (ex_handlers![cur_block].LastClauseType() == ILExceptionBlock.FILTER_START) throw new InvalidOperationException(SR.Argument_BadExceptionCodeGen); @@ -901,7 +901,7 @@ public virtual void ThrowException([DynamicallyAccessedMembers(DynamicallyAccess throw new ArgumentException(SR.Argument_TypeMustBeOfExceptionType, nameof(excType)); ConstructorInfo? ctor = excType.GetConstructor(Type.EmptyTypes); if (ctor == null) - throw new ArgumentException(SR.Argument_TypeMustHaveDefaultConstructor, nameof(excType)); + throw new ArgumentException(SR.Argument_MissingDefaultConstructor, nameof(excType)); Emit(OpCodes.Newobj, ctor); Emit(OpCodes.Throw); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs index 53e27a8078fa73..c297711a929fbd 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodBuilder.Mono.cs @@ -93,7 +93,7 @@ internal MethodBuilder(TypeBuilder tb, string name, MethodAttributes attributes, { for (int i = 0; i < parameterTypes.Length; ++i) if (parameterTypes[i] == null) - throw new ArgumentException(SR.Argument_NullParameterTypes, nameof(parameterTypes)); + throw new ArgumentException(SR.ArgumentNull_TypeRequiredByResourceScope, nameof(parameterTypes)); this.parameters = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); @@ -418,7 +418,7 @@ public void SetCustomAttribute(CustomAttributeBuilder customBuilder) pi_dll = (string?)attr.ctorArgs[0]; if (pi_dll == null || pi_dll.Length == 0) - throw new ArgumentException(SR.Arg_DllNameNotFound); + throw new ArgumentException(SR.Arg_DllNotFoundException); native_cc = Runtime.InteropServices.CallingConvention.Winapi; @@ -545,7 +545,7 @@ private static Exception NotSupported() public override MethodInfo MakeGenericMethod(params Type[] typeArguments) { if (!IsGenericMethodDefinition) - throw new InvalidOperationException(SR.Argument_MethodIsNotAGenericMethodDefinition); + throw new InvalidOperationException(SR.Argument_NeedGenericMethodDefinition); ArgumentNullException.ThrowIfNull(typeArguments); foreach (Type type in typeArguments) { diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs index 83d6e006623110..9847e6fe1cd825 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs @@ -251,7 +251,7 @@ public override CallingConventions CallingConvention public override MethodInfo MakeGenericMethod(params Type[] methodInstantiation) { if (!base_method.IsGenericMethodDefinition || (method_arguments != null)) - throw new InvalidOperationException(SR.Argument_MethodIsNotAGenericMethodDefinition); + throw new InvalidOperationException(SR.Argument_NeedGenericMethodDefinition); ArgumentNullException.ThrowIfNull(methodInstantiation); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs index cd575bee885b44..0d9dff6b86bc2a 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs @@ -204,7 +204,7 @@ public MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes { ArgumentNullException.ThrowIfNull(name); if ((attributes & MethodAttributes.Static) == 0) - throw new ArgumentException(SR.Argument_GlobalFunctionHasToBeStatic); + throw new ArgumentException(SR.Argument_GlobalMethodsMustBeStatic); if (global_type_created) throw new InvalidOperationException(SR.InvalidOperation_GlobalsHaveBeenCreated); CreateGlobalType(); @@ -219,7 +219,7 @@ public MethodBuilder DefinePInvokeMethod(string name, string dllName, string ent { ArgumentNullException.ThrowIfNull(name); if ((attributes & MethodAttributes.Static) == 0) - throw new ArgumentException(SR.Argument_GlobalFunctionHasToBeStatic); + throw new ArgumentException(SR.Argument_GlobalMethodsMustBeStatic); if (global_type_created) throw new InvalidOperationException(SR.InvalidOperation_GlobalsHaveBeenCreated); CreateGlobalType(); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs index 6c9dd1a113b68a..545fe9f9420e98 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs @@ -72,7 +72,7 @@ internal SignatureHelper(ModuleBuilder? module, SignatureHelperType type) public static SignatureHelper GetFieldSigHelper(Module? mod) { if (mod != null && !(mod is ModuleBuilder)) - throw new ArgumentException(SR.ArgumentException_ModuleBuilderExpected); + throw new NotSupportedException(SR.NotSupported_MustBeModuleBuilder); return new SignatureHelper((ModuleBuilder?)mod, SignatureHelperType.HELPER_FIELD); } @@ -80,7 +80,7 @@ public static SignatureHelper GetFieldSigHelper(Module? mod) public static SignatureHelper GetLocalVarSigHelper(Module? mod) { if (mod != null && !(mod is ModuleBuilder)) - throw new ArgumentException(SR.ArgumentException_ModuleBuilderExpected); + throw new NotSupportedException(SR.NotSupported_MustBeModuleBuilder); return new SignatureHelper((ModuleBuilder?)mod, SignatureHelperType.HELPER_LOCAL); } @@ -389,17 +389,17 @@ internal static SignatureHelper GetMethodSigHelper(Module? mod, CallingConventio Type[]? parameters) { if (mod != null && !(mod is ModuleBuilder)) - throw new ArgumentException(SR.ArgumentException_ModuleBuilderExpected); + throw new NotSupportedException(SR.NotSupported_MustBeModuleBuilder); returnType ??= typeof(void); if (returnType.IsUserType) - throw new NotSupportedException(SR.NotSupported_UserDefinedSubClassesOfSystemTypeNotSupported); + throw new NotSupportedException(SR.PlatformNotSupported_ITypeInfo); if (parameters != null) { for (int i = 0; i < parameters.Length; ++i) if (parameters[i].IsUserType) - throw new NotSupportedException(SR.NotSupported_UserDefinedSubClassesOfSystemTypeNotSupported); + throw new NotSupportedException(SR.PlatformNotSupported_ITypeInfo); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs index b40429eb302666..e3ba4af5bd7955 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs @@ -854,7 +854,7 @@ internal static void ResolveUserTypes(Type?[]? types) { t = t.UnderlyingSystemType; if (t != null && ((t.GetType().Assembly != typeof(int).Assembly) || (t is TypeDelegator))) - throw new NotSupportedException(SR.NotSupported_UserDefinedSubClassesOfSystemTypeNotSupported); + throw new NotSupportedException(SR.PlatformNotSupported_ITypeInfo); return t; } else @@ -1308,7 +1308,7 @@ public override Type MakeGenericType(params Type[] typeArguments) ArgumentNullException.ThrowIfNull(typeArguments); if (generic_params!.Length != typeArguments.Length) - throw new ArgumentException(SR.Format(SR.Argument_GenericArgumentsOverflow, generic_params.Length, typeArguments.Length), nameof(typeArguments)); + throw new ArgumentException(SR.Format(SR.Argument_NotEnoughGenArguments, generic_params.Length, typeArguments.Length), nameof(typeArguments)); foreach (Type t in typeArguments) { @@ -1351,7 +1351,7 @@ public void SetCustomAttribute(CustomAttributeBuilder customBuilder) LayoutKind.Auto => TypeAttributes.AutoLayout, LayoutKind.Explicit => TypeAttributes.ExplicitLayout, LayoutKind.Sequential => TypeAttributes.SequentialLayout, - _ => throw new Exception(SR.Exception_ErrorInCustomAttr), // we should ignore it since it can be any value anyway... + _ => throw new Exception(SR.Argument_InvalidKindOfTypeForCA), // we should ignore it since it can be any value anyway... }; Type ctor_type = customBuilder.Ctor is ConstructorBuilder builder ? builder.parameters![0] : customBuilder.Ctor.GetParametersInternal()[0].ParameterType; @@ -1750,8 +1750,8 @@ public static ConstructorInfo GetConstructor(Type type, ConstructorInfo construc throw new ArgumentException(SR.Argument_InvalidConstructorDeclaringType, nameof(type)); ConstructorInfo res = type.GetConstructor(constructor); - if (res == null) - throw new ArgumentException(SR.Argument_ConstructorNotFound); + + Debug.Assert(res != null); return res; } @@ -1800,8 +1800,8 @@ public static MethodInfo GetMethod(Type type, MethodInfo method) throw new ArgumentException(SR.Argument_InvalidMethodDeclaringType, nameof(type)); MethodInfo res = type.GetMethod(method); - if (res == null) - throw new ArgumentException(SR.Format(SR.Argument_MethodNotFoundInType, method.Name, type)); + + Debug.Assert(res != null); return res; } @@ -1821,9 +1821,7 @@ public static FieldInfo GetField(Type type, FieldInfo field) if (field.DeclaringType != type.GetGenericTypeDefinition()) throw new ArgumentException(SR.Argument_InvalidFieldDeclaringType, nameof(type)); - - if (field is FieldOnTypeBuilderInst) - throw new ArgumentException(SR.Argument_FieldNeedGenericDeclaringType, nameof(field)); + Debug.Assert((field is FieldOnTypeBuilderInst)); FieldInfo res = type.GetField(field); if (res == null) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs index c0b0bc9cb01bf8..02a016195f239b 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs @@ -558,7 +558,7 @@ abstract class TypeBuilderInstantiation : TypeInfo { internal static Type MakeGenericType (Type type, Type[] typeArguments) { - throw new NotSupportedException(SR.NotSupported_UserTypesNotSupportedUnderFullAot); + throw new NotSupportedException(SR.PlatformNotSupported_ReflectionEmit); } } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs index f09bec79c77bb9..f32863994b13d3 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs @@ -201,7 +201,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) if (!IsStatic) { if (obj == null) - throw new TargetException(SR.Target_NonStaticFieldRequirement); + throw new TargetException(SR.RFLCT_Targ_StatFldReqTarg); if (!DeclaringType!.IsAssignableFrom(obj.GetType())) throw new ArgumentException(SR.Format(SR.Arg_FieldDeclTarget, Name, DeclaringType, obj.GetType()), nameof(obj)); } @@ -225,12 +225,12 @@ public override void SetValue(object? obj, object? val, BindingFlags invokeAttr, if (!IsStatic) { if (obj == null) - throw new TargetException(SR.Target_NonStaticFieldRequirement); + throw new TargetException(SR.RFLCT_Targ_StatFldReqTarg); if (!DeclaringType!.IsAssignableFrom(obj.GetType())) throw new ArgumentException(SR.Format(SR.Arg_FieldDeclTarget, Name, DeclaringType, obj.GetType()), nameof(obj)); } if (IsLiteral) - throw new FieldAccessException(SR.FieldAccess_CannotSetConstantField); + throw new FieldAccessException(SR.Acc_ReadOnly); binder ??= Type.DefaultBinder; CheckGeneric(); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs index 465918c628e97c..5fd60dfb684071 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs @@ -642,12 +642,12 @@ public override MethodInfo MakeGenericMethod(Type[] methodInstantiation) if (RuntimeFeature.IsDynamicCodeSupported) return new MethodOnTypeBuilderInst(this, methodInstantiation); - throw new NotSupportedException(SR.NotSupported_UserTypesNotSupportedUnderFullAot); + throw new NotSupportedException(SR.PlatformNotSupported_ReflectionEmit); } MethodInfo ret = MakeGenericMethod_impl(methodInstantiation); if (ret == null) - throw new ArgumentException(SR.Format(SR.Argument_GenericArgumentsOverflow, GetGenericArguments().Length, methodInstantiation.Length)); + throw new ArgumentException(SR.Format(SR.Argument_NotEnoughGenArguments, GetGenericArguments().Length, methodInstantiation.Length)); return ret; } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs index 0a47c3bfa7af2d..ff88ac01ba03f6 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs @@ -256,7 +256,7 @@ int MetadataToken { return GetMetadataToken(); } - throw new ArgumentException(SR.Format(SR.NoMetadataTokenAvailable, MemberImpl.GetType())); + throw new ArgumentException(SR.NoMetadataTokenAvailable); } } diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index 07f48ef136d589..346e1f5bc8e26f 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -1636,7 +1636,7 @@ internal override FieldInfo GetField(FieldInfo fromNoninstanciated) // TODO: .net does more checks in unmanaged land in RuntimeTypeHandle::CreateInstance if (IsAbstract) { - throw new MissingMethodException(SR.Format(SR.MissingMethod_CannotCreateAbstractClass, FullName)); + throw new MissingMethodException(SR.Format(SR.Acc_CreateAbst, FullName)); } unsafe @@ -2104,29 +2104,29 @@ private RuntimePropertyInfo[] GetPropertiesByName(string? name, BindingFlags bin } } - public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type ifaceType) + public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type interfaceType) { if (IsGenericParameter) throw new InvalidOperationException(SR.Arg_GenericParameter); - ArgumentNullException.ThrowIfNull(ifaceType); + ArgumentNullException.ThrowIfNull(interfaceType); - RuntimeType? ifaceRtType = ifaceType as RuntimeType; + RuntimeType? ifaceRtType = interfaceType as RuntimeType; if (ifaceRtType == null) - throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(ifaceType)); + throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(interfaceType)); InterfaceMapping res; - if (!ifaceType.IsInterface) - throw new ArgumentException(SR.Argument_MustBeInterface, nameof(ifaceType)); + if (!interfaceType.IsInterface) + throw new ArgumentException(SR.Arg_MustBeInterface, nameof(interfaceType)); if (IsInterface) throw new ArgumentException(SR.Argument_InterfaceMap); var this_type = this; res.TargetType = this; - res.InterfaceType = ifaceType; + res.InterfaceType = interfaceType; GetInterfaceMapData(new QCallTypeHandle(ref this_type), new QCallTypeHandle(ref ifaceRtType), out res.TargetMethods, out res.InterfaceMethods); if (res.TargetMethods == null) - throw new ArgumentException(SR.ArgumentException_InterfaceNotFound, nameof(ifaceType)); + throw new ArgumentException(SR.Arg_NotFoundIFace, nameof(interfaceType)); return res; } diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index 8c68159a86dbdf..5613a8ca36a12e 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs @@ -124,11 +124,10 @@ internal static TypeAttributes GetAttributes(RuntimeType type) public ModuleHandle GetModuleHandle() { - // Although MS' runtime is crashing here, we prefer throwing an exception. // The check is needed because Type.GetTypeFromHandle returns null // for zero handles. if (value == IntPtr.Zero) - throw new InvalidOperationException(SR.InvalidOperation_ObjectFieldsNotProperlyInitialized); + throw new ArgumentException(SR.Arg_InvalidHandle); return Type.GetTypeFromHandle(this)!.Module.ModuleHandle; } diff --git a/src/mono/System.Private.CoreLib/src/System/Type.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Type.Mono.cs index 703d858c327a80..9504643cec7081 100644 --- a/src/mono/System.Private.CoreLib/src/System/Type.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Type.Mono.cs @@ -116,17 +116,17 @@ internal virtual bool IsUserType internal virtual MethodInfo GetMethod(MethodInfo fromNoninstanciated) { - throw new InvalidOperationException(SR.InvalidOperation_CanOnlyBeCalledByGenericType); + throw new InvalidOperationException(SR.InvalidOperation_NotGenericType); } internal virtual ConstructorInfo GetConstructor(ConstructorInfo fromNoninstanciated) { - throw new InvalidOperationException(SR.InvalidOperation_CanOnlyBeCalledByGenericType); + throw new InvalidOperationException(SR.InvalidOperation_NotGenericType); } internal virtual FieldInfo GetField(FieldInfo fromNoninstanciated) { - throw new InvalidOperationException(SR.InvalidOperation_CanOnlyBeCalledByGenericType); + throw new InvalidOperationException(SR.InvalidOperation_NotGenericType); } [MethodImplAttribute(MethodImplOptions.InternalCall)] diff --git a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs index 03fc8dce17cb3c..2486c88ad3d946 100644 --- a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs +++ b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs @@ -406,13 +406,13 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo { case '&': if (data.is_byref) - throw new ArgumentException(SR.Argument_CannotHaveAByrefOfByref, "typeName"); + throw new ArgumentException(SR.Format(SR.CannotCreatePointerOfByRef, data.TypeName), "typeName"); data.is_byref = true; break; case '*': if (data.is_byref) - throw new ArgumentException(SR.Argument_CannotPointToByrefType, "typeName"); + throw new ArgumentException(SR.Format(SR.CannotCreatePointerOfByRef, data.TypeName), "typeName"); // take subsequent '*'s too int pointer_level = 1; while (pos + 1 < name.Length && name[pos + 1] == '*') @@ -457,7 +457,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo {//generic args List args = new List(); if (data.HasModifiers) - throw new ArgumentException(SR.Arg_GenericArguments, "typeName"); + throw new ArgumentException(SR.Arg_GenericArgumentsAfterArrayOrPointerType, "typeName"); while (pos < name.Length) { @@ -497,7 +497,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo if (name[pos] == '*') { if (bound) - throw new ArgumentException(SR.Argument_ArrayCannotBeBoundTo2Dimensions, "typeName"); + throw new ArgumentException(SR.Argument_MultiDimensionalArrayCannotBeBound, "typeName"); bound = true; } else if (name[pos] != ',') From 37a5ea797ffaae903ad9cacfcf700a486bcd7ce2 Mon Sep 17 00:00:00 2001 From: databunks Date: Fri, 16 Dec 2022 14:20:57 +0000 Subject: [PATCH 07/22] Remaining strings fix --- .../src/System/Reflection/Emit/ILGenerator.cs | 2 +- .../src/Resources/Strings.resx | 14 ++++---------- .../src/System/Collections/Generic/Queue.cs | 2 +- .../Collections/ObjectModel/CollectionHelpers.cs | 4 ++-- .../Collections/ObjectModel/ReadOnlyDictionary.cs | 4 ++-- .../src/System/ThrowHelper.cs | 2 +- .../src/System/Delegate.Mono.cs | 2 +- .../src/System/Reflection/Emit/ILGenerator.Mono.cs | 2 +- .../Reflection/Emit/MethodOnTypeBuilderInst.cs | 2 +- .../System/Reflection/RuntimeMethodInfo.Mono.cs | 4 ++-- .../System.Private.CoreLib/src/System/TypeSpec.cs | 2 +- 11 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs index 7b250203612316..93aa112ab11d95 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs @@ -1204,7 +1204,7 @@ public virtual void ThrowException([DynamicallyAccessedMembers(DynamicallyAccess ConstructorInfo? con = excType.GetConstructor(Type.EmptyTypes); if (con == null) { - throw new ArgumentException(SR.Argument_MissingDefaultConstructor); + throw new ArgumentException(SR.Arg_NoDefCTorWithoutTypeName); } Emit(OpCodes.Newobj, con); Emit(OpCodes.Throw); diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 858c8454531ae1..4d957787dffc4a 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -160,7 +160,7 @@ The serialization stream contains no inner exceptions. - (Inner Exception #{0}) + (Inner Exception #{0}) This text is prepended to each inner exception description during aggregate exception formatting @@ -1134,9 +1134,6 @@ The property handle and the type handle are incompatible. - - Incorrect Argument length. - 'this' type cannot be an interface itself. @@ -1158,8 +1155,8 @@ Length of the array must be {0}. - - Array type is invalid. + + Array type is incompatible. Invalid array spec, multi-dimensional array cannot be bound. @@ -1372,9 +1369,6 @@ Two arrays, {0} and {1}, must be of the same size. - - Was missing default constructor. - Argument must be initialized to false @@ -1388,7 +1382,7 @@ MethodInfo must be a runtime MethodInfo object. - 'type' must contain a TypeBuilder as a generic argument. + Type must be a runtime Type object. 'type' must contain a TypeBuilder as a generic argument. diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs index 7a793902166a02..0a7e7e79168d81 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs @@ -164,7 +164,7 @@ void ICollection.CopyTo(Array array, int index) } catch (ArrayTypeMismatchException) { - throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array)); + throw new ArgumentException(SR.Argument_IncompatibleArrayType, nameof(array)); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/CollectionHelpers.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/CollectionHelpers.cs index ee843c0035732f..d84958d4f0aaad 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/CollectionHelpers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/CollectionHelpers.cs @@ -50,7 +50,7 @@ internal static void CopyTo(ICollection collection, Array array, int index // We can't cast array of value type to object[], so we don't support widening of primitive types here. if (array is not object?[] objects) { - throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array)); + throw new ArgumentException(SR.Argument_IncompatibleArrayType, nameof(array)); } try @@ -62,7 +62,7 @@ internal static void CopyTo(ICollection collection, Array array, int index } catch (ArrayTypeMismatchException) { - throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array)); + throw new ArgumentException(SR.Argument_IncompatibleArrayType, nameof(array)); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs index 31fd226ea0aa7e..d13a7198f07493 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs @@ -193,7 +193,7 @@ void ICollection.CopyTo(Array array, int index) object[]? objects = array as object[]; if (objects == null) { - throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array)); + throw new ArgumentException(SR.Argument_IncompatibleArrayType, nameof(array)); } try @@ -205,7 +205,7 @@ void ICollection.CopyTo(Array array, int index) } catch (ArrayTypeMismatchException) { - throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array)); + throw new ArgumentException(SR.Argument_IncompatibleArrayType, nameof(array)); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs index 1f0e03112c8f2b..d67b2fe50d8758 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs @@ -440,7 +440,7 @@ internal static void ThrowOutOfMemoryException() [DoesNotReturn] internal static void ThrowArgumentException_Argument_InvalidArrayType() { - throw new ArgumentException(SR.Argument_InvalidArrayType); + throw new ArgumentException(SR.Argument_IncompatibleArrayType); } [DoesNotReturn] diff --git a/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs index b38170f8bc5b4f..65435d74314d0c 100644 --- a/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs @@ -427,7 +427,7 @@ private static bool IsArgumentTypeMatchWithThis(Type delArgType, Type argType, b protected virtual object? DynamicInvokeImpl(object?[]? args) { - MethodInfo _method = Method ?? throw new NullReferenceException (SR.NullReference_This); + MethodInfo _method = Method; object? target = _target; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs index 9619fe0c88289b..42f45f5a319185 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs @@ -901,7 +901,7 @@ public virtual void ThrowException([DynamicallyAccessedMembers(DynamicallyAccess throw new ArgumentException(SR.Argument_TypeMustBeOfExceptionType, nameof(excType)); ConstructorInfo? ctor = excType.GetConstructor(Type.EmptyTypes); if (ctor == null) - throw new ArgumentException(SR.Argument_MissingDefaultConstructor, nameof(excType)); + throw new ArgumentException(SR.Arg_NoDefCTorWithoutTypeName, nameof(excType)); Emit(OpCodes.Newobj, ctor); Emit(OpCodes.Throw); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs index 9847e6fe1cd825..cce34a46546d87 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInst.cs @@ -256,7 +256,7 @@ public override MethodInfo MakeGenericMethod(params Type[] methodInstantiation) ArgumentNullException.ThrowIfNull(methodInstantiation); if (base_method.GetGenericArguments().Length != methodInstantiation.Length) - throw new ArgumentException(SR.Argument_IncorrectLength, nameof(methodInstantiation)); + throw new ArgumentException(SR.Format(SR.Argument_NotEnoughGenArguments, base_method.GetGenericArguments().Length, methodInstantiation.Length)); foreach (Type type in methodInstantiation) { diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs index 5fd60dfb684071..052b863058ac06 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs @@ -626,7 +626,7 @@ public override MethodInfo MakeGenericMethod(Type[] methodInstantiation) /*FIXME add GetGenericArgumentsLength() internal vcall to speed this up*/ if (GetGenericArguments().Length != methodInstantiation.Length) - throw new ArgumentException(SR.Format(SR.Argument_IncorrectLength, nameof(methodInstantiation))); + throw new ArgumentException(SR.Format(SR.Argument_NotEnoughGenArguments, GetGenericArguments().Length, methodInstantiation.Length)); bool hasUserType = false; foreach (Type type in methodInstantiation) @@ -645,7 +645,7 @@ public override MethodInfo MakeGenericMethod(Type[] methodInstantiation) throw new NotSupportedException(SR.PlatformNotSupported_ReflectionEmit); } - MethodInfo ret = MakeGenericMethod_impl(methodInstantiation); + MethodInfo ret = MakeGenericMethod_impl(methodInstantiation); if (ret == null) throw new ArgumentException(SR.Format(SR.Argument_NotEnoughGenArguments, GetGenericArguments().Length, methodInstantiation.Length)); return ret; diff --git a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs index 2486c88ad3d946..40264ba625407d 100644 --- a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs +++ b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs @@ -450,7 +450,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo throw new ArgumentException(SR.Argument_ByrefQualifierMustBeLastOneOfAType, "typeName"); ++pos; if (pos >= name.Length) - throw new ArgumentException(SR.Argument_InvalidArrayType, "typeName"); + throw new ArgumentException(SR.Argument_IncompatibleArrayType, "typeName"); SkipSpace(name, ref pos); if (name[pos] != ',' && name[pos] != '*' && name[pos] != ']') From 7bd69872cb29011a87a8c51529e8d016433b5936 Mon Sep 17 00:00:00 2001 From: databunks Date: Fri, 16 Dec 2022 14:41:46 +0000 Subject: [PATCH 08/22] global members merge conflict fix --- .../src/System/Reflection/Emit/ModuleBuilder.cs | 4 ++-- .../System.Private.CoreLib/src/Resources/Strings.resx | 4 ++-- .../src/System/Reflection/Emit/ModuleBuilder.Mono.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs index 2754ad40d53321..c696a64d75b2e3 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs @@ -799,7 +799,7 @@ public MethodBuilder DefinePInvokeMethod(string name, string dllName, string ent // Global methods must be static. if ((attributes & MethodAttributes.Static) == 0) { - throw new ArgumentException(SR.Argument_GlobalMethodsMustBeStatic); + throw new ArgumentException(SR.Argument_GlobalMembersMustBeStatic); } return _globalTypeBuilder.DefinePInvokeMethod(name, dllName, entryName, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet); @@ -829,7 +829,7 @@ private MethodBuilder DefineGlobalMethodNoLock(string name, MethodAttributes att ArgumentException.ThrowIfNullOrEmpty(name); if ((attributes & MethodAttributes.Static) == 0) { - throw new ArgumentException(SR.Argument_GlobalMethodsMustBeStatic); + throw new ArgumentException(SR.Argument_GlobalMembersMustBeStatic); } return _globalTypeBuilder.DefineMethod(name, attributes, callingConvention, diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 4d957787dffc4a..652cdcbdb32fa1 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -1095,8 +1095,8 @@ Open Generic Type not permitted. - - Global methods must be static. + + Global members must be static. Must be an array type. diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs index 0d9dff6b86bc2a..ccd3099b224817 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.Mono.cs @@ -204,7 +204,7 @@ public MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes { ArgumentNullException.ThrowIfNull(name); if ((attributes & MethodAttributes.Static) == 0) - throw new ArgumentException(SR.Argument_GlobalMethodsMustBeStatic); + throw new ArgumentException(SR.Argument_GlobalMembersMustBeStatic); if (global_type_created) throw new InvalidOperationException(SR.InvalidOperation_GlobalsHaveBeenCreated); CreateGlobalType(); @@ -219,7 +219,7 @@ public MethodBuilder DefinePInvokeMethod(string name, string dllName, string ent { ArgumentNullException.ThrowIfNull(name); if ((attributes & MethodAttributes.Static) == 0) - throw new ArgumentException(SR.Argument_GlobalMethodsMustBeStatic); + throw new ArgumentException(SR.Argument_GlobalMembersMustBeStatic); if (global_type_created) throw new InvalidOperationException(SR.InvalidOperation_GlobalsHaveBeenCreated); CreateGlobalType(); From 7f67478f8dcffd0f4e69607df0ec2b995040be49 Mon Sep 17 00:00:00 2001 From: databunks Date: Fri, 16 Dec 2022 14:58:56 +0000 Subject: [PATCH 09/22] Remaining Merge Conflict fixes --- .../System.Private.CoreLib/src/Resources/Strings.resx | 3 --- src/mono/System.Private.CoreLib/src/System/ArgIterator.cs | 2 +- src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs | 6 +++--- .../src/System/Reflection/Emit/EventBuilder.Mono.cs | 2 +- .../src/System/Reflection/Emit/ILGenerator.Mono.cs | 2 +- .../src/System/Reflection/Emit/TypeBuilder.Mono.cs | 2 +- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 652cdcbdb32fa1..5c7c1643a424c7 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -3044,9 +3044,6 @@ The given Variant type is not supported by this OleAut function. - - Only Call and CallVirt are allowed - Cannot create arrays of open type. diff --git a/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs b/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs index 950aaeecfc987d..1209465f604ced 100644 --- a/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs +++ b/src/mono/System.Private.CoreLib/src/System/ArgIterator.cs @@ -47,7 +47,7 @@ public void End() public override bool Equals(object? o) { - throw new NotSupportedException(SR.PlatformNotSupported_ArgIterator); + throw new NotSupportedException(SR.NotSupported_NYI); } public override int GetHashCode() diff --git a/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs index 65435d74314d0c..d40e212a672fa2 100644 --- a/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Delegate.Mono.cs @@ -427,7 +427,7 @@ private static bool IsArgumentTypeMatchWithThis(Type delArgType, Type argType, b protected virtual object? DynamicInvokeImpl(object?[]? args) { - MethodInfo _method = Method; + MethodInfo method = Method; object? target = _target; @@ -451,7 +451,7 @@ private static bool IsArgumentTypeMatchWithThis(Type delArgType, Type argType, b } } - if (_method.IsStatic) + if (method.IsStatic) { // // The delegate is bound to _target @@ -482,7 +482,7 @@ private static bool IsArgumentTypeMatchWithThis(Type delArgType, Type argType, b } } - return _method.Invoke(target, args); + return method.Invoke(target, args); } public override bool Equals([NotNullWhen(true)] object? obj) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs index deb9015c0c0d1a..ef7aec4fcd37d2 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/EventBuilder.Mono.cs @@ -140,7 +140,7 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) private void RejectIfCreated() { if (typeb.is_created) - throw new InvalidOperationException(SR.InvalidOperation_TypeHasBeenCreated); + throw new InvalidOperationException(SR.InvalidOperation_MethodBaked); } } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs index 42f45f5a319185..c72a227e4bbb63 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs @@ -790,7 +790,7 @@ public virtual void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[]? optio ArgumentNullException.ThrowIfNull(methodInfo); short value = opcode.Value; if (!(value == OpCodes.Call.Value || value == OpCodes.Callvirt.Value)) - throw new NotSupportedException(SR.NotSupported_OnlyCallAndCallVirtAllowed); + throw new NotSupportedException(SR.Argument_NotMethodCallOpcode); if ((methodInfo.CallingConvention & CallingConventions.VarArgs) == 0) optionalParameterTypes = null; if (optionalParameterTypes != null) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs index e3ba4af5bd7955..41e271a84f411e 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.Mono.cs @@ -1958,7 +1958,7 @@ internal static bool SetConstantValue(Type destType, object? value, ref object? destValue = ticks; return true; default: - throw new ArgumentException(SR.Format(SR.Argument_ConstantNotSupported, type!.ToString())); + throw new ArgumentException(SR.Format(SR.Argument_ConstantNotSupported, type)); } } else From cf88b720f5431b4cc91a048107961d49f8ea0b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 23 Jan 2023 17:20:47 +0100 Subject: [PATCH 10/22] Apply suggestions from code review --- .../System.Private.CoreLib/src/Resources/Strings.resx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index cd5e34e17f4ab8..0ff1b7128f4852 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -326,7 +326,7 @@ External component has thrown an exception. - EnC: Expected a primitive, valuetype, class or interface field. + EnC: Expected a primitive, valuetype, class or interface field. Attempted to access a field that is not accessible by the caller. @@ -356,7 +356,7 @@ One of the identified items was in an invalid format. - Generic arguments after array spec or pointer type. + Generic arguments after array spec or pointer type. Method must be called on a Type for which Type.IsGenericParameter is false. @@ -847,7 +847,7 @@ Array or pointer types are not valid. - Error parsing array spec. + Error parsing array spec. Attribute names must be unique. @@ -1157,6 +1157,7 @@ Invalid array spec, multi-dimensional array cannot be bound. + Target array type is not compatible with the type of items in the collection. @@ -1618,7 +1619,7 @@ Local passed in does not belong to this ILGenerator. - Unmatched ']' while parsing generic argument assembly name + Unmatched ']' while parsing generic argument assembly name Non-matching symbol scope. @@ -2948,7 +2949,7 @@ A non-collectible assembly may not reference a collectible assembly. - An element type cannot contain a stack pointer. + An element type cannot contain a stack pointer. CreateInstance cannot be used with an object of type TypeBuilder. From 4ee4128343cbf350597610c3bec5b4e212f066f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 20 Mar 2023 12:27:25 +0100 Subject: [PATCH 11/22] Fix merge conflicts --- .../System.Private.CoreLib/src/Resources/Strings.resx | 5 ++++- .../Reflection/Emit/MethodOnTypeBuilderInstantiation.Mono.cs | 2 +- .../src/System/Reflection/RuntimeMethodInfo.Mono.cs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 59520a4dcf5d8d..675887cb6ce9fd 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -1244,7 +1244,7 @@ Value of flags is invalid. - Invalid generic arguments spec. + The generic type parameter was not valid Invalid generic arguments separator {0} @@ -1378,6 +1378,9 @@ Two arrays, {0} and {1}, must be of the same size. + + was missing default constructor. + Argument must be initialized to false diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInstantiation.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInstantiation.Mono.cs index d7581944ca64f2..f0c730920df848 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInstantiation.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/MethodOnTypeBuilderInstantiation.Mono.cs @@ -98,7 +98,7 @@ public override MethodInfo MakeGenericMethod(params Type[] typeArgs) ArgumentNullException.ThrowIfNull(typeArgs); if (_method.GetGenericArguments().Length != typeArgs.Length) - throw new ArgumentException(SR.Format(SR.Argument_NotEnoughGenArguments, base_method.GetGenericArguments().Length, methodInstantiation.Length)); + throw new ArgumentException(SR.Format(SR.Argument_NotEnoughGenArguments, _method.GetGenericArguments().Length, typeArgs.Length)); foreach (Type type in typeArgs) { diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs index cc2139be3a5a28..be08cf1c9a0ebd 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs @@ -645,7 +645,7 @@ public override MethodInfo MakeGenericMethod(Type[] methodInstantiation) throw new NotSupportedException(SR.PlatformNotSupported_ReflectionEmit); } - MethodInfo ret = MakeGenericMethod_impl(methodInstantiation); + MethodInfo ret = MakeGenericMethod_impl(methodInstantiation); if (ret == null) throw new ArgumentException(SR.Format(SR.Argument_NotEnoughGenArguments, GetGenericArguments().Length, methodInstantiation.Length)); return ret; From 061e2ead55918aff84fa073f4cf4a24771cbb87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 20 Mar 2023 12:35:32 +0100 Subject: [PATCH 12/22] PR feedback --- .../System.Private.CoreLib/src/Resources/Strings.resx | 3 +++ src/mono/System.Private.CoreLib/src/System/TypeSpec.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 675887cb6ce9fd..65ed17829d9a99 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -1170,6 +1170,9 @@ Target array type is not compatible with the type of items in the collection. + + Invalid array/generic spec. + The given assembly name was invalid. diff --git a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs index 40264ba625407d..2486c88ad3d946 100644 --- a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs +++ b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs @@ -450,7 +450,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo throw new ArgumentException(SR.Argument_ByrefQualifierMustBeLastOneOfAType, "typeName"); ++pos; if (pos >= name.Length) - throw new ArgumentException(SR.Argument_IncompatibleArrayType, "typeName"); + throw new ArgumentException(SR.Argument_InvalidArrayType, "typeName"); SkipSpace(name, ref pos); if (name[pos] != ',' && name[pos] != '*' && name[pos] != ']') From 44af1bae5e0666911317a5de2853bef5e308e97f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 20 Mar 2023 12:39:48 +0100 Subject: [PATCH 13/22] Fix Argument_MissingDefaultConstructor usages --- .../src/System/Reflection/Emit/ILGenerator.cs | 4 ++-- src/coreclr/debug/ee/funceval.cpp | 2 +- .../System.Private.CoreLib/src/Resources/Strings.resx | 3 --- .../src/System/Reflection/Emit/ILGenerator.Mono.cs | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs index 2556b7271f5057..727fc5f5ca2a58 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs @@ -1189,12 +1189,12 @@ public virtual void ThrowException([DynamicallyAccessedMembers(DynamicallyAccess if (!excType.IsSubclassOf(typeof(Exception)) && excType != typeof(Exception)) { - throw new ArgumentException(SR.Argument_NotExceptionType); + throw new ArgumentException(SR.Argument_NotExceptionType, nameof(excType)); } ConstructorInfo? con = excType.GetConstructor(Type.EmptyTypes); if (con == null) { - throw new ArgumentException(SR.Arg_NoDefCTorWithoutTypeName); + throw new ArgumentException(SR.Arg_NoDefCTorWithoutTypeName, nameof(excType)); } Emit(OpCodes.Newobj, con); Emit(OpCodes.Throw); diff --git a/src/coreclr/debug/ee/funceval.cpp b/src/coreclr/debug/ee/funceval.cpp index afd8dfeff38238..7844edbe8b306d 100644 --- a/src/coreclr/debug/ee/funceval.cpp +++ b/src/coreclr/debug/ee/funceval.cpp @@ -1708,7 +1708,7 @@ void ResolveFuncEvalGenericArgInfo(DebuggerEval *pDE) // If this is a new object operation, then we should have a .ctor. if ((pDE->m_evalType == DB_IPCE_FET_NEW_OBJECT) && !pDE->m_md->IsCtor()) { - COMPlusThrow(kArgumentException, W("Argument_MissingDefaultConstructor")); + COMPlusThrow(kArgumentException, W("Arg_NoDefCTorWithoutTypeName")); } pDE->m_md->EnsureActive(); diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 65ed17829d9a99..c5057dcff1dec7 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -1381,9 +1381,6 @@ Two arrays, {0} and {1}, must be of the same size. - - was missing default constructor. - Argument must be initialized to false diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs index 487879c456dff0..9ccf03acdeb20c 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs @@ -901,7 +901,7 @@ public virtual void ThrowException([DynamicallyAccessedMembers(DynamicallyAccess throw new ArgumentException(SR.Argument_NotExceptionType, nameof(excType)); ConstructorInfo? ctor = excType.GetConstructor(Type.EmptyTypes); if (ctor == null) - throw new ArgumentException(SR.Argument_MissingDefaultConstructor, nameof(excType)); + throw new ArgumentException(SR.Arg_NoDefCTorWithoutTypeName, nameof(excType)); Emit(OpCodes.Newobj, ctor); Emit(OpCodes.Throw); } From 5f8c0189f358adab976817c10ffeb62ea82bb530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 20 Mar 2023 13:25:10 +0100 Subject: [PATCH 14/22] Fix remaining usages of exception strings --- .../src/Resources/Strings.resx | 15 +++++++++++++++ .../src/Mono/RuntimeMarshal.cs | 2 +- .../src/System/Array.Mono.cs | 4 ++-- .../src/System/ModuleHandle.cs | 8 ++++---- .../Reflection/Emit/RuntimeMethodBuilder.Mono.cs | 2 +- .../Reflection/Emit/RuntimeTypeBuilder.Mono.cs | 8 ++++---- .../src/System/Reflection/RuntimePropertyInfo.cs | 4 ++-- .../Runtime/InteropServices/Marshal.Mono.cs | 8 ++++---- 8 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index c5057dcff1dec7..0390587ac28086 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -1840,6 +1840,9 @@ A valid UTF32 value is between 0x000000 and 0x10ffff, inclusive, and should not include surrogate codepoint values (0x00d800 ~ 0x00dfff). + + Value does not refer to a valid string. + The specified length exceeds maximum capacity of SecureString. @@ -2045,6 +2048,18 @@ The SyncRoot property may not be used for the synchronization of concurrent collections. + + Custom marshaler '{0}' implements multiple static GetInstance methods that take a single string parameter. + + + Custom marshaler '{0}' does not implement a static GetInstance method that takes a single string parameter and returns an ICustomMarshaler. + + + Custom marshaler '{0}' contains unassigned generic type parameter(s). + + + A call to GetInstance() for custom marshaler '{0}' returned null, which is not allowed. + Task {2} completed. diff --git a/src/mono/System.Private.CoreLib/src/Mono/RuntimeMarshal.cs b/src/mono/System.Private.CoreLib/src/Mono/RuntimeMarshal.cs index b97aed564a279f..5e8de2bd57467c 100644 --- a/src/mono/System.Private.CoreLib/src/Mono/RuntimeMarshal.cs +++ b/src/mono/System.Private.CoreLib/src/Mono/RuntimeMarshal.cs @@ -26,7 +26,7 @@ internal static string PtrToUtf8String(IntPtr ptr) } catch (NullReferenceException) { - throw new ArgumentOutOfRangeException(nameof(ptr), "Value does not refer to a valid string."); + throw new ArgumentOutOfRangeException(nameof(ptr), SR.ArgumentOutOfRange_InvalidString); } return new string((sbyte*)ptr, 0, length, System.Text.Encoding.UTF8); diff --git a/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs index 152b609805fa28..a7a87bf15bc8e6 100644 --- a/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Array.Mono.cs @@ -122,10 +122,10 @@ private static void Copy(Array sourceArray, int sourceIndex, Array destinationAr throw new RankException(SR.Rank_MultiDimNotSupported); if (sourceIndex < 0) - throw new ArgumentOutOfRangeException(nameof(sourceIndex), "Value has to be >= 0."); + throw new ArgumentOutOfRangeException(nameof(sourceIndex), SR.ArgumentOutOfRange_NeedNonNegNum); if (destinationIndex < 0) - throw new ArgumentOutOfRangeException(nameof(destinationIndex), "Value has to be >= 0."); + throw new ArgumentOutOfRangeException(nameof(destinationIndex), SR.ArgumentOutOfRange_NeedNonNegNum); var src = sourceArray; var dst = destinationArray; diff --git a/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs b/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs index 1617bae1e68277..fb2427c70e436b 100644 --- a/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs +++ b/src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs @@ -30,7 +30,7 @@ public int MDStreamVersion get { if (value == IntPtr.Zero) - throw new ArgumentNullException(string.Empty, "Invalid handle"); + throw new ArgumentNullException(string.Empty, SR.Arg_InvalidHandle); return RuntimeModule.GetMDStreamVersion(value); } } @@ -68,7 +68,7 @@ public RuntimeTypeHandle ResolveTypeHandle(int typeToken) public RuntimeTypeHandle ResolveTypeHandle(int typeToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext) { if (value == IntPtr.Zero) - throw new ArgumentNullException(string.Empty, "Invalid handle"); + throw new ArgumentNullException(string.Empty, SR.Arg_InvalidHandle); IntPtr res = RuntimeModule.ResolveTypeToken(value, typeToken, ptrs_from_handles(typeInstantiationContext), ptrs_from_handles(methodInstantiationContext), out _); if (res == IntPtr.Zero) throw new TypeLoadException(SR.Format(SR.ClassLoad_General_Hex, typeToken, value.ToInt64())); @@ -80,7 +80,7 @@ public RuntimeTypeHandle ResolveTypeHandle(int typeToken, RuntimeTypeHandle[]? t public RuntimeMethodHandle ResolveMethodHandle(int methodToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext) { if (value == IntPtr.Zero) - throw new ArgumentNullException(string.Empty, "Invalid handle"); + throw new ArgumentNullException(string.Empty, SR.Arg_InvalidHandle); IntPtr res = RuntimeModule.ResolveMethodToken(value, methodToken, ptrs_from_handles(typeInstantiationContext), ptrs_from_handles(methodInstantiationContext), out _); if (res == IntPtr.Zero) throw new Exception(SR.Format(SR.ClassLoad_General_Hex, methodToken, value.ToInt64())); @@ -92,7 +92,7 @@ public RuntimeMethodHandle ResolveMethodHandle(int methodToken, RuntimeTypeHandl public RuntimeFieldHandle ResolveFieldHandle(int fieldToken, RuntimeTypeHandle[]? typeInstantiationContext, RuntimeTypeHandle[]? methodInstantiationContext) { if (value == IntPtr.Zero) - throw new ArgumentNullException(string.Empty, "Invalid handle"); + throw new ArgumentNullException(string.Empty, SR.Arg_InvalidHandle); IntPtr res = RuntimeModule.ResolveFieldToken(value, fieldToken, ptrs_from_handles(typeInstantiationContext), ptrs_from_handles(methodInstantiationContext), out _); if (res == IntPtr.Zero) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs index 8f792235a8eb6f..2df4946207624a 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs @@ -603,7 +603,7 @@ protected override void SetSignatureCore(Type? returnType, Type[]? returnTypeReq { for (int i = 0; i < parameterTypes.Length; ++i) if (parameterTypes[i] == null) - throw new ArgumentNullException(nameof(parameterTypes), "Elements of the parameterTypes array cannot be null"); + throw new ArgumentNullException(nameof(parameterTypes), SR.ArgumentNull_ArrayElement); this.parameters = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs index c80da77c9ea16e..bafcafd9c8989d 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs @@ -65,7 +65,7 @@ public static ConstructorInfo GetConstructor(Type type, ConstructorInfo construc ConstructorInfo res = type.GetConstructor(constructor); if (res == null) - throw new ArgumentException("constructor not found"); + throw new ArgumentException(SR.Format(SR.MissingConstructor_Name, type)); return res; } @@ -115,7 +115,7 @@ public static MethodInfo GetMethod(Type type, MethodInfo method) MethodInfo res = type.GetMethod(method); if (res == null) - throw new ArgumentException(string.Format("method {0} not found in type {1}", method.Name, type)); + throw new ArgumentException(SR.Format(SR.MissingMethod_Name, type, method.Name)); return res; } @@ -137,11 +137,11 @@ public static FieldInfo GetField(Type type, FieldInfo field) throw new ArgumentException(SR.Argument_InvalidFieldDeclaringType, nameof(type)); if (field is FieldOnTypeBuilderInstantiation) - throw new ArgumentException("The specified field must be declared on a generic type definition.", nameof(field)); + throw new ArgumentException(SR.Argument_FieldNeedGenericDeclaringType, nameof(field)); FieldInfo res = type.GetField(field); if (res == null) - throw new System.Exception("field not found"); + throw new System.Exception(SR.MissingField); else return res; } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs index bd628a30c7f0b7..ebe9efca54eee9 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs @@ -402,7 +402,7 @@ private static GetterAdapter CreateGetterDelegate(MethodInfo method) { MethodInfo? method = GetGetMethod(true); if (method == null) - throw new ArgumentException($"Get Method not found for '{Name}'"); + throw new ArgumentException(SR.Arg_GetMethNotFnd); if (!DeclaringType.IsValueType && !PropertyType.IsByRef && !method.ContainsGenericParameters) { //FIXME find a way to build an invoke delegate for value types. @@ -440,7 +440,7 @@ private static GetterAdapter CreateGetterDelegate(MethodInfo method) MethodInfo? method = GetGetMethod(true); if (method == null) - throw new ArgumentException($"Get Method not found for '{Name}'"); + throw new ArgumentException(SR.Arg_GetMethNotFnd); if (index == null || index.Length == 0) ret = method.Invoke(obj, invokeAttr, binder, null, culture); diff --git a/src/mono/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs index 602ae2999c6102..e2574f415c0de6 100644 --- a/src/mono/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Mono.cs @@ -156,18 +156,18 @@ private static unsafe void SetInvokeArgs(ref string cookie, IntPtr *params_byref } catch (AmbiguousMatchException) { - throw new ApplicationException($"Custom marshaler '{type.FullName}' implements multiple static GetInstance methods that take a single string parameter."); + throw new ApplicationException(SR.Format(SR.CustomMarshaler_MultipleGetInstanceMethods, type.FullName)); } if ((getInstanceMethod == null) || (getInstanceMethod.ReturnType != typeof(ICustomMarshaler))) { - throw new ApplicationException($"Custom marshaler '{type.FullName}' does not implement a static GetInstance method that takes a single string parameter and returns an ICustomMarshaler."); + throw new ApplicationException(SR.Format(SR.CustomMarshaler_NoGetInstanceMethod, type.FullName)); } if (getInstanceMethod.ContainsGenericParameters) { - throw new System.TypeLoadException($"Custom marshaler '{type.FullName}' contains unassigned generic type parameter(s)."); + throw new System.TypeLoadException(SR.Format(SR.CustomMarshaler_UnassignedGenericParams, type.FullName)); } Exception? exc; @@ -193,7 +193,7 @@ private static unsafe void SetInvokeArgs(ref string cookie, IntPtr *params_byref } if (result == null) - throw new ApplicationException($"A call to GetInstance() for custom marshaler '{type.FullName}' returned null, which is not allowed."); + throw new ApplicationException(SR.Format(SR.CustomMarshaler_NullReturnForGetInstance, type.FullName)); lock (cache) cache[key] = result; From 80dd63351918d9c7ac9f9d0ae6019a1a1d1a3920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 20 Mar 2023 14:03:17 +0100 Subject: [PATCH 15/22] Remove unused resources and fix one usage --- .../System.Private.CoreLib/src/Resources/Strings.resx | 6 ------ src/mono/System.Private.CoreLib/src/System/TypeSpec.cs | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 0390587ac28086..7a3cc0d1c295fd 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -933,18 +933,12 @@ Byref qualifier must be the last one of a type. - - Can't have a pointer to a byref type. - Cannot use function evaluation to create a TypedReference object. Cannot set parent to an interface. - - Can't have a byref of a byref. - {0} is not a supported code page. diff --git a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs index 2486c88ad3d946..b1609a569eaecf 100644 --- a/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs +++ b/src/mono/System.Private.CoreLib/src/System/TypeSpec.cs @@ -406,7 +406,7 @@ private static TypeSpec Parse(string name, ref int p, bool is_recurse, bool allo { case '&': if (data.is_byref) - throw new ArgumentException(SR.Format(SR.CannotCreatePointerOfByRef, data.TypeName), "typeName"); + throw new ArgumentException(SR.Format(SR.CannotCreateByRefOfByRef, data.TypeName), "typeName"); data.is_byref = true; break; From 1ef9d2742a7270dfdf4059a60451385704a8f45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 20 Mar 2023 21:08:13 +0100 Subject: [PATCH 16/22] Apply suggestions from code review Co-authored-by: Dan Moseley --- .../src/Resources/Strings.resx | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 7a3cc0d1c295fd..973627243a3529 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -335,7 +335,7 @@ External component has thrown an exception. - EnC: Expected a primitive, valuetype, class or interface field. + Edit and Continue: Expected a primitive, valuetype, class or interface field. Attempted to access a field that is not accessible by the caller. @@ -1066,13 +1066,13 @@ Cannot resolve field {0} because the declaring type of the field handle {1} is generic. Explicitly provide the declaring type to GetFieldFromHandle. - Field {0} does not belong to the same class as the constructor + Field '{0}' does not belong to the same class as the constructor. - Field {0} does not have a valid type. + Field '{0}' does not have a valid type. - Field {0} does not have a valid value. + Field '{0}' does not have a valid value. The field handle and the type handle are incompatible. @@ -1087,7 +1087,7 @@ The number of generic arguments provided doesn't equal the arity of the generic type definition. - Generic argument can't be byref or pointer type. + Generic argument can't be a byref or pointer type. Generic types are not valid. @@ -1174,7 +1174,7 @@ Not a valid calendar for the given culture. - "Invalid character in array spec: {0} + "Invalid character in array spec: '{0}'. Invalid Unicode code point found at index {0}. @@ -1244,7 +1244,7 @@ The generic type parameter was not valid - Invalid generic arguments separator {0} + Invalid generic arguments separator '{0}' Generic arguments must be provided for each generic parameter and each generic argument must be a RuntimeType. @@ -1352,7 +1352,7 @@ Integer or token was too large to be encoded. - Label #{0} is not marked in method `{1}' + Label #{0} is not marked in method '{1}'. Environment variable name or value is too long. @@ -1544,7 +1544,7 @@ The initial count for the semaphore must be greater than or equal to zero and less than the maximum count. - Set Method not found for '{0}'. + Set method not found for '{0}'. Should not specify exception type for catch clause for filter block. @@ -1604,7 +1604,7 @@ The type must be __ComObject or be derived from __ComObject. - Unclosed assembly-qualified type name at {0} + Unclosed assembly-qualified type name at '{0}'. The IL Generator cannot be used while there are unclosed exceptions. @@ -1619,13 +1619,13 @@ The UnmanagedMemoryAccessor capacity and offset would wrap around the high end of the address space. - Value of field '{0}' does not match field type: {1} + Value of field '{0}' does not match field type '{1}'. Local passed in does not belong to this ILGenerator. - Unmatched ']' while parsing generic argument assembly name + Unmatched ']' while parsing generic argument assembly name. Non-matching symbol scope. @@ -2262,7 +2262,7 @@ Event {0} was called with a different type as defined (argument "{1}"). This may cause the event to be displayed incorrectly. - Custom attribute type '{0}' doesn't contain a field named '{1}' + Custom attribute type '{0}' doesn't contain a field named '{1}'. --- End of inner exception stack trace --- @@ -2271,19 +2271,19 @@ --- End of stack trace from previous location --- - Custom attribute length is only '{0}' + Custom attribute length is only '{0}'. Prolog invalid. - Unknown named type: {0} + Unknown named type '{0}'. - Unknown MarshalAsAttribute field: {0}. + Unknown MarshalAsAttribute field '{0}'. - Subtype '{0}' of type object not yet handled + Subtype '{0}' of type object not yet handled. Exception of type '{0}' was thrown. @@ -2513,7 +2513,7 @@ Object cannot be stored in an array of this type. - Type is concrete but has abstract method {0}. + Type is concrete but has abstract method '{0}'. AsyncFlowControl objects can be used to restore flow only on a Context that had its flow suppressed. @@ -3582,10 +3582,10 @@ The type initializer for '{0}' threw an exception. - Could not load type '{0}' from assembly '{1}' because it is an enum with methods + Could not load type '{0}' from assembly '{1}' because it is an enum with methods. - "Could not load type '{0}' from assembly '{1}' because it is implements the inaccessible interface '{2}'. + Could not load type '{0}' from assembly '{1}' because it implements the inaccessible interface '{2}'. Could not load type '{0}' from assembly '{1}' because the parent type is sealed. @@ -3723,7 +3723,7 @@ PInvoke methods cannot exist on interfaces. - Bad type def, can't handle '{0}' at {1} + Bad type def, can't handle '{0}' at '{1}'. Method has been already defined. @@ -3741,7 +3741,7 @@ Precision cannot be larger than {0}. - Property '{0}' does not belong to the same class as the constructor + Property '{0}' does not belong to the same class as the constructor. Property '{0}' does not have a valid type. @@ -3753,7 +3753,7 @@ "Property '{0}' does not have a setter. - "Value of property '{0}' does not match property type: {1} -> {2} + "Value of property '{0}' does not match property type: '{1}' -> '{2}'. Cannot load hostpolicy library. AssemblyDependencyResolver is currently only supported if the runtime is hosted through hostpolicy library. @@ -4182,7 +4182,7 @@ The type '{0}' cannot be found in assembly '{1}'. - Method '{0}' override '{1}' but it is not virtual. + Method '{0}' overrides '{1}' but it is not virtual. Cannot load assembly '{0}'. No metadata found for this assembly. From 637e1e10a01a6f00e45d11326e98a60b0e94d00a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 20 Mar 2023 21:42:13 +0100 Subject: [PATCH 17/22] Deduplicate some strings --- .../src/Resources/Strings.resx | 18 +++--------------- .../src/Mono/HotReload.cs | 2 +- .../Emit/RuntimeMethodBuilder.Mono.cs | 4 +--- .../System/Reflection/RuntimePropertyInfo.cs | 2 +- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 973627243a3529..524afda99c310c 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -334,7 +334,7 @@ External component has thrown an exception. - + Edit and Continue: Expected a primitive, valuetype, class or interface field. @@ -1543,9 +1543,6 @@ The initial count for the semaphore must be greater than or equal to zero and less than the maximum count. - - Set method not found for '{0}'. - Should not specify exception type for catch clause for filter block. @@ -1591,9 +1588,6 @@ The specified type must be visible from COM. - - Type should be an exception type. - The type must not be imported from COM. @@ -1613,10 +1607,10 @@ Unknown unmanaged calling convention for function signature. - Specified unmanaged type is only valid on fields. + The UnmanagedMemoryAccessor capacity and offset would wrap around the high end of the address space. - The UnmanagedMemoryAccessor capacity and offset would wrap around the high end of the address space. + Specified unmanaged type is only valid on fields. Value of field '{0}' does not match field type '{1}'. @@ -1642,9 +1636,6 @@ The buffer is not associated with this pool and may not be returned to it. - - Interface not found. - The object is not an array with the same number of elements as the array to compare it to. @@ -2906,9 +2897,6 @@ Method '{0}.{1}' not found. - - Method '{0}.{1}' does not have a method body. - The satellite assembly named "{1}" for fallback culture "{0}" either could not be found or could not be loaded. This is generally a setup problem. Please consider reinstalling or repairing the application. diff --git a/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs b/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs index fda9deb10f6c40..0d15884fd2592d 100644 --- a/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs +++ b/src/mono/System.Private.CoreLib/src/Mono/HotReload.cs @@ -107,7 +107,7 @@ public static FieldStore Create (RuntimeTypeHandle type) else if (t.IsClass || t.IsInterface) loc = null; else - throw new ArgumentException(SR.Arg_EnC); + throw new ArgumentException(SR.Arg_EnC_ExpectedPrimitive); /* FIXME: do we want FieldStore to be pinned? */ return new FieldStore(loc); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs index 2df4946207624a..13c16c70d9318f 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs @@ -357,9 +357,7 @@ internal void fixup() { // do not allow zero length method body on MS.NET 2.0 (and higher) if (((ilgen == null) || (ilgen.ILOffset == 0)) && (code == null || code.Length == 0)) - throw new InvalidOperationException( - SR.Format(SR.MissingMethod_Body, - DeclaringType!.FullName, Name)); + throw new InvalidOperationException(SR.Format(SR.InvalidOperation_BadEmptyMethodBody, Name)); } ilgen?.label_fixup(this); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs index ebe9efca54eee9..ff28f41f9a74da 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs @@ -454,7 +454,7 @@ public override void SetValue(object? obj, object? value, BindingFlags invokeAtt { MethodInfo? method = GetSetMethod(true); if (method == null) - throw new ArgumentException(SR.Format(SR.Argument_SetMethodNotFound, Name)); + throw new ArgumentException(System.SR.Arg_SetMethNotFnd); object?[] parms; if (index == null || index.Length == 0) From 01f8e4e59cca54640aa67c0610b25b659f2adf60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 20 Mar 2023 21:49:21 +0100 Subject: [PATCH 18/22] Fixup string --- src/libraries/System.Private.CoreLib/src/Resources/Strings.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 524afda99c310c..82bdb9aabaca71 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -3735,7 +3735,7 @@ Property '{0}' does not have a valid type. - Property {0} does not have a valid value. + Property '{0}' does not have a valid value. "Property '{0}' does not have a setter. From c1b501c2e3495b3e096f886a9292e84d2e6f5d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 20 Mar 2023 22:27:58 +0100 Subject: [PATCH 19/22] Fix errors in resource strings --- .../src/Resources/Strings.resx | 6 +++--- .../Reflection/Emit/CustomAttributeBuilder.Mono.cs | 4 ++-- .../Emit/RuntimeConstructorBuilder.Mono.cs | 7 ++++--- .../Reflection/Emit/RuntimeMethodBuilder.Mono.cs | 14 ++++++++------ .../Reflection/Emit/RuntimeTypeBuilder.Mono.cs | 6 +++--- .../src/System/Reflection/Emit/SignatureHelper.cs | 4 ++-- .../src/System/Reflection/RuntimeFieldInfo.cs | 2 +- .../System/Reflection/RuntimeMethodInfo.Mono.cs | 2 +- .../src/System/RuntimeType.Mono.cs | 6 +++--- .../src/System/RuntimeTypeHandle.cs | 2 +- 10 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 82bdb9aabaca71..903d695a343015 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -3254,6 +3254,9 @@ Thread suspend is not supported on this platform. + + User defined subclasses of System.Type are not yet supported. + Postcondition failed. @@ -4163,9 +4166,6 @@ The type '{0}' cannot be found. - - The type '{0}' cannot be loaded. - The type '{0}' cannot be found in assembly '{1}'. diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs index 1c4c416b5cb761..494a2bc3b86f6f 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs @@ -420,7 +420,7 @@ internal static UnmanagedMarshal get_umarshal(CustomAttributeBuilder customBuild #endif case UnmanagedType.ByValArray: if (!is_field) - throw new ArgumentException(SR.Argument_UnmanagedMemAccessorWrapAround); + throw new ArgumentException(SR.Argument_UnmanagedTypeOnlyValidOnFields); return UnmanagedMarshal.DefineByValArray(sizeConst); case UnmanagedType.ByValTStr: @@ -451,7 +451,7 @@ private static Type elementTypeToType(int elementType) => 0x0c => typeof(float), 0x0d => typeof(double), 0x0e => typeof(string), - _ => throw new Exception(SR.Format(SR.ArgumentException_InvalidArrayElementType, elementType)), + _ => throw new Exception(SR.Format(SR.ArgumentException_InvalidTypeArgument, elementType)), }; private static object? decode_cattr_value(Type t, byte[] data, int pos, out int rpos) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeConstructorBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeConstructorBuilder.Mono.cs index db05591dcb5dc5..f9939d27b3183b 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeConstructorBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeConstructorBuilder.Mono.cs @@ -68,9 +68,10 @@ internal RuntimeConstructorBuilder(RuntimeTypeBuilder tb, MethodAttributes attri call_conv = callingConvention; if (parameterTypes != null) { - for (int i = 0; i < parameterTypes.Length; ++i) - if (parameterTypes[i] == null) - throw new ArgumentException(SR.ArgumentNull_TypeRequiredByResourceScope, nameof(parameterTypes)); + foreach (Type t in parameterTypes) + { + ArgumentNullException.ThrowIfNull(t, nameof(parameterTypes)); + } this.parameters = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs index 13c16c70d9318f..1e1aa2e325eab4 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs @@ -91,9 +91,10 @@ internal RuntimeMethodBuilder(RuntimeTypeBuilder tb, string name, MethodAttribut this.call_conv |= CallingConventions.HasThis; if (parameterTypes != null) { - for (int i = 0; i < parameterTypes.Length; ++i) - if (parameterTypes[i] == null) - throw new ArgumentException(SR.ArgumentNull_TypeRequiredByResourceScope, nameof(parameterTypes)); + foreach (Type t in parameterTypes) + { + ArgumentNullException.ThrowIfNull(t, nameof(parameterTypes)); + } this.parameters = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); @@ -599,9 +600,10 @@ protected override void SetSignatureCore(Type? returnType, Type[]? returnTypeReq { if (parameterTypes != null) { - for (int i = 0; i < parameterTypes.Length; ++i) - if (parameterTypes[i] == null) - throw new ArgumentNullException(nameof(parameterTypes), SR.ArgumentNull_ArrayElement); + foreach (Type t in parameterTypes) + { + ArgumentNullException.ThrowIfNull(t, nameof(parameterTypes)); + } this.parameters = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, this.parameters, parameterTypes.Length); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs index bafcafd9c8989d..1252a2952d86ff 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs @@ -141,7 +141,7 @@ public static FieldInfo GetField(Type type, FieldInfo field) FieldInfo res = type.GetField(field); if (res == null) - throw new System.Exception(SR.MissingField); + throw new System.Exception(SR.Format(SR.MissingField, field.Name)); else return res; } @@ -932,7 +932,7 @@ internal static void ResolveUserTypes(Type?[]? types) { t = t.UnderlyingSystemType; if (t != null && ((t.GetType().Assembly != typeof(int).Assembly) || (t is TypeDelegator))) - throw new NotSupportedException(SR.PlatformNotSupported_ITypeInfo); + throw new NotSupportedException(SR.PlatformNotSupported_UserDefinedSubclassesOfType); return t; } else @@ -1658,7 +1658,7 @@ private static NotSupportedException not_supported() internal void check_not_created() { if (is_created) - throw new InvalidOperationException(SR.NotSupported_DynamicModule); + throw new InvalidOperationException(SR.InvalidOperation_TypeHasBeenCreated); } private void check_created() diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs index aa9ad8dfd0f801..606dd993e52dd0 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs @@ -396,12 +396,12 @@ internal static SignatureHelper GetMethodSigHelper(Module? mod, CallingConventio returnType ??= typeof(void); if (returnType.IsUserType) - throw new NotSupportedException(SR.PlatformNotSupported_ITypeInfo); + throw new NotSupportedException(SR.PlatformNotSupported_UserDefinedSubclassesOfType); if (parameters != null) { for (int i = 0; i < parameters.Length; ++i) if (parameters[i].IsUserType) - throw new NotSupportedException(SR.PlatformNotSupported_ITypeInfo); + throw new NotSupportedException(SR.PlatformNotSupported_UserDefinedSubclassesOfType); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs index 3d244fa530f02e..665e83d4533f56 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs @@ -275,7 +275,7 @@ private void CheckGeneric() { Type? declaringType = DeclaringType; if (declaringType != null && declaringType.ContainsGenericParameters) - throw new InvalidOperationException(SR.InvalidOperation_GenericParametersAlreadySet); + throw new InvalidOperationException(SR.Arg_UnboundGenField); } public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other) => HasSameMetadataDefinitionAsCore(other); diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs index be08cf1c9a0ebd..13460b63cf49fe 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs @@ -622,7 +622,7 @@ public override MethodInfo MakeGenericMethod(Type[] methodInstantiation) ArgumentNullException.ThrowIfNull(methodInstantiation); if (!IsGenericMethodDefinition) - throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericMethodDefinition, nameof(methodInstantiation))); + throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericMethodDefinition, this)); /*FIXME add GetGenericArgumentsLength() internal vcall to speed this up*/ if (GetGenericArguments().Length != methodInstantiation.Length) diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index 8103ad605ef4bd..ce4801bceb54f7 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -1758,7 +1758,7 @@ internal override FieldInfo GetField(FieldInfo fromNoninstanciated) // TODO: .net does more checks in unmanaged land in RuntimeTypeHandle::CreateInstance if (IsAbstract) { - throw new MissingMethodException(SR.Format(SR.Acc_CreateAbst, FullName)); + throw new MissingMethodException(SR.Acc_CreateAbst); } unsafe @@ -2004,7 +2004,7 @@ public override Type MakeArrayType(int rank) public override Type MakeByRefType() { if (IsByRef) - throw new TypeLoadException(SR.TypeLoad_ResolveType); + throw new TypeLoadException(SR.Format(SR.CannotCreateByRefOfByRef, GetType())); Type? type = null; var base_type = this; make_byref_type(new QCallTypeHandle(ref base_type), ObjectHandleOnStack.Create(ref type)); @@ -2017,7 +2017,7 @@ public override Type MakeByRefType() public override Type MakePointerType() { if (IsByRef) - throw new TypeLoadException(SR.Format(SR.ClassLoad_General, GetType(), AssemblyQualifiedName)); + throw new TypeLoadException(SR.Format(SR.CannotCreatePointerOfByRef, GetType())); Type? type = null; var base_type = this; make_pointer_type(new QCallTypeHandle(ref base_type), ObjectHandleOnStack.Create(ref type)); diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index a68778c33e3fd7..3e69be66ea9694 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs @@ -383,7 +383,7 @@ internal static bool IsTypeDefinition(RuntimeType type) ref stackMark, ObjectHandleOnStack.Create (ref t), throwOnError, ignoreCase); if (throwOnError && t == null) - throw new TypeLoadException(SR.Format(SR.TypeLoad_TypeNotLoaded, typeName)); + throw new TypeLoadException(SR.Arg_TypeLoadException); } return t; } From f38e86ec5e8afe79be195291e03aa0787bdbaf0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 20 Mar 2023 22:36:40 +0100 Subject: [PATCH 20/22] Update src/libraries/System.Private.CoreLib/src/Resources/Strings.resx Co-authored-by: Dan Moseley --- src/libraries/System.Private.CoreLib/src/Resources/Strings.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 903d695a343015..2b96ed88532a53 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -1096,7 +1096,7 @@ Error parsing generic params spec. - Open Generic Type not permitted. + Open generic type not permitted. Global members must be static. From 5ad86224c70a8b0638b08d4b63b490f4d2ad8fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Tue, 21 Mar 2023 19:06:54 +0100 Subject: [PATCH 21/22] Remove unused resource --- .../System.Private.CoreLib/src/Resources/Strings.resx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index 2d2a48700d30b8..fd9652d6cded60 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -1825,9 +1825,6 @@ A valid UTF32 value is between 0x000000 and 0x10ffff, inclusive, and should not include surrogate codepoint values (0x00d800 ~ 0x00dfff). - - Value does not refer to a valid string. - The specified length exceeds maximum capacity of SecureString. From 6974e7c3fcd5ddcc0a1db3f42c4ffb7e0c04d5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Wed, 22 Mar 2023 22:16:07 +0100 Subject: [PATCH 22/22] A few more fixes --- .../src/Resources/Strings.resx | 20 +++++++++---------- .../Reflection/Emit/ILGenerator.Mono.cs | 4 ++-- .../Emit/RuntimeAssemblyBuilder.Mono.cs | 2 +- .../Emit/RuntimeMethodBuilder.Mono.cs | 2 +- .../Emit/RuntimeModuleBuilder.Mono.cs | 6 +++--- .../Emit/RuntimeTypeBuilder.Mono.cs | 2 +- .../src/System/Reflection/FieldInfo.Mono.cs | 2 +- .../src/System/Reflection/RuntimeEventInfo.cs | 2 +- .../System/Reflection/RuntimePropertyInfo.cs | 2 +- .../src/System/RuntimeType.Mono.cs | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx index fd9652d6cded60..3b6562ee595ef6 100644 --- a/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx +++ b/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx @@ -289,6 +289,9 @@ Dll was not found. + + DllName cannot be empty. + Duplicate objects in argument. @@ -1074,8 +1077,8 @@ Field '{0}' does not have a valid value. - - The field handle and the type handle are incompatible. + + The field, property or event handle and the type handle are incompatible. The specified field must be declared on a generic type definition. @@ -1134,9 +1137,6 @@ The specified index is out of bounds of the specified array. - - The property handle and the type handle are incompatible. - 'this' type cannot be an interface itself. @@ -1496,7 +1496,7 @@ Parameter {0} does not have a valid type. - Parameter {0} does not have a valid value. + Parameter {0} is not a valid value. Could not parse the type name. @@ -2614,8 +2614,8 @@ Method already has a body. - - Module-level methods cannot be retrieved until after the CreateGlobalFunctions method has been called for the module. + + Module-level fields or methods cannot be retrieved until after the CreateGlobalFunctions method has been called for the module. You must call Initialize on this object instance before using it. @@ -3717,7 +3717,7 @@ PInvoke methods cannot exist on interfaces. - Bad type def, can't handle '{0}' at '{1}'. + Bad type definition, can't handle '{0}' at '{1}'. Method has been already defined. @@ -4065,7 +4065,7 @@ Could not load type '{0}' from assembly '{1}'. - Could not load type '0x{0:x}' from assembly '0x{1:x}'. + Could not load type, method or field '0x{0:x}' from assembly '0x{1:x}'. '{0}' from assembly '{1}' has too many dimensions. diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs index 9ccf03acdeb20c..97236def8f52b9 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs @@ -348,7 +348,7 @@ public virtual void BeginCatchBlock(Type? exceptionType) if (!InExceptionBlock) throw new NotSupportedException(SR.Argument_NotInExceptionBlock); if (exceptionType != null && exceptionType.IsUserType) - throw new NotSupportedException(SR.PlatformNotSupported_ITypeInfo); + throw new NotSupportedException(SR.PlatformNotSupported_UserDefinedSubclassesOfType); if (ex_handlers![cur_block].LastClauseType() == ILExceptionBlock.FILTER_START) { if (exceptionType != null) @@ -446,7 +446,7 @@ public virtual LocalBuilder DeclareLocal(Type localType, bool pinned) { ArgumentNullException.ThrowIfNull(localType); if (localType.IsUserType) - throw new NotSupportedException(SR.PlatformNotSupported_ITypeInfo); + throw new NotSupportedException(SR.PlatformNotSupported_UserDefinedSubclassesOfType); LocalBuilder res = new LocalBuilder(localType, this); res.is_pinned = pinned; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeAssemblyBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeAssemblyBuilder.Mono.cs index 7acbe6a48a835f..1a425be6a96ac5 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeAssemblyBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeAssemblyBuilder.Mono.cs @@ -235,7 +235,7 @@ internal RuntimeAssemblyBuilder(AssemblyName n, AssemblyBuilderAccess access) if (!Enum.IsDefined(typeof(AssemblyBuilderAccess), access)) throw new ArgumentException(SR.Format(CultureInfo.InvariantCulture, - "Argument value {0} is not valid.", (int)access), + SR.Arg_EnumIllegalVal, (int)access), nameof(access)); name = n.Name; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs index 1e1aa2e325eab4..80e8352d04b40e 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeMethodBuilder.Mono.cs @@ -410,7 +410,7 @@ protected override void SetCustomAttributeCore(CustomAttributeBuilder customBuil pi_dll = (string?)attr.ctorArgs[0]; if (pi_dll == null || pi_dll.Length == 0) - throw new ArgumentException(SR.Arg_DllNotFoundException); + throw new ArgumentException(SR.Arg_DllNameCannotBeEmpty); native_cc = Runtime.InteropServices.CallingConvention.Winapi; diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.Mono.cs index fc8c2b1aa8c1ac..a089065434afb5 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.Mono.cs @@ -895,7 +895,7 @@ public override IList GetCustomAttributesData() public override FieldInfo? GetField(string name, BindingFlags bindingAttr) { if (!global_type_created) - throw new InvalidOperationException(SR.InvalidOperation_ModuleMethodsRelyOnCreateGlobalFunctionsMethod); + throw new InvalidOperationException(SR.InvalidOperation_ModuleFieldsMethodsRelyOnCreateGlobalFunctionsMethod); return global_type!.AsType().GetField(name, bindingAttr); } @@ -903,7 +903,7 @@ public override IList GetCustomAttributesData() public override FieldInfo[] GetFields(BindingFlags bindingFlags) { if (!global_type_created) - throw new InvalidOperationException(SR.InvalidOperation_ModuleMethodsRelyOnCreateGlobalFunctionsMethod); + throw new InvalidOperationException(SR.InvalidOperation_ModuleFieldsMethodsRelyOnCreateGlobalFunctionsMethod); return global_type!.AsType().GetFields(bindingFlags); } @@ -911,7 +911,7 @@ public override FieldInfo[] GetFields(BindingFlags bindingFlags) public override MethodInfo[] GetMethods(BindingFlags bindingFlags) { if (!global_type_created) - throw new InvalidOperationException(SR.InvalidOperation_ModuleMethodsRelyOnCreateGlobalFunctionsMethod); + throw new InvalidOperationException(SR.InvalidOperation_ModuleFieldsMethodsRelyOnCreateGlobalFunctionsMethod); return global_type!.AsType().GetMethods(bindingFlags); } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs index 1252a2952d86ff..fcfd1e14ddc9e5 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs @@ -846,7 +846,7 @@ protected override TypeInfo CreateTypeInfoCore() foreach (Type iface in interfaces) { if (iface.IsNestedPrivate && iface.Assembly != Assembly) - throw new TypeLoadException(SR.Format( SR.TypeLoad_AssemblyInaccessibleInterfaceError, fullname.DisplayName, Assembly, iface.FullName )); + throw new TypeLoadException(SR.Format(SR.TypeLoad_AssemblyInaccessibleInterfaceError, fullname.DisplayName, Assembly, iface.FullName)); if (iface.IsGenericTypeDefinition) throw new BadImageFormatException(); if (!iface.IsInterface) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs index d070cc892c1cc2..7da1a2e9465702 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/FieldInfo.Mono.cs @@ -24,7 +24,7 @@ public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle, RuntimeTyp throw new ArgumentException(SR.Argument_InvalidHandle); FieldInfo fi = internal_from_handle_type(handle.Value, declaringType.Value); if (fi == null) - throw new ArgumentException(SR.Argument_FieldAndTypeHandleIncompatibility); + throw new ArgumentException(SR.Argument_FieldPropertyEventAndTypeHandleIncompatibility); return fi; } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs index 64aa6e12fbf7bd..dd45a1d99cb265 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs @@ -222,7 +222,7 @@ internal static EventInfo GetEventFromHandle(Mono.RuntimeEventHandle handle, Run throw new ArgumentException(SR.Argument_InvalidHandle); EventInfo ei = internal_from_handle_type(handle.Value, reflectedType.Value); if (ei == null) - throw new ArgumentException(SR.Argument_FieldAndTypeHandleIncompatibility); + throw new ArgumentException(SR.Argument_FieldPropertyEventAndTypeHandleIncompatibility); return ei; } } diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs index ff28f41f9a74da..c6992481947992 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs @@ -503,7 +503,7 @@ internal static PropertyInfo GetPropertyFromHandle(RuntimePropertyHandle handle, throw new ArgumentException(SR.Argument_InvalidHandle); PropertyInfo pi = internal_from_handle_type(handle.Value, reflectedType.Value); if (pi == null) - throw new ArgumentException(SR.Argument_IncompatablePropertyAndTypeHandle); + throw new ArgumentException(SR.Argument_FieldPropertyEventAndTypeHandleIncompatibility); return pi; } } diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index ce4801bceb54f7..014aa965939049 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -1758,7 +1758,7 @@ internal override FieldInfo GetField(FieldInfo fromNoninstanciated) // TODO: .net does more checks in unmanaged land in RuntimeTypeHandle::CreateInstance if (IsAbstract) { - throw new MissingMethodException(SR.Acc_CreateAbst); + throw new MissingMethodException(SR.Format(SR.Acc_CreateAbstEx, this)); } unsafe