Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mono: Replace exception strings with those stored in the resx file (#34056) #78341

Merged
merged 25 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0d46864
swapping exception strings from resx file
Nov 14, 2022
e276c22
Fixed byref naming/text value
Nov 14, 2022
bf792d9
Fixed ByRef Arguments &
Nov 15, 2022
9838ae5
fixes SRformat only used in exceptions & resx refs
Nov 23, 2022
3eeec78
fixing small typo
Nov 23, 2022
98392ba
de-duplication + suggested changes
Dec 4, 2022
37a5ea7
Remaining strings fix
Dec 16, 2022
7bd6987
global members merge conflict fix
Dec 16, 2022
7f67478
Remaining Merge Conflict fixes
Dec 16, 2022
95168c2
Merge branch 'main' into main
databunks Dec 16, 2022
cf88b72
Apply suggestions from code review
akoeplinger Jan 23, 2023
2af909b
Merge branch 'main' into databunks/main
akoeplinger Mar 20, 2023
4ee4128
Fix merge conflicts
akoeplinger Mar 20, 2023
061e2ea
PR feedback
akoeplinger Mar 20, 2023
44af1ba
Fix Argument_MissingDefaultConstructor usages
akoeplinger Mar 20, 2023
5f8c018
Fix remaining usages of exception strings
akoeplinger Mar 20, 2023
80dd633
Remove unused resources and fix one usage
akoeplinger Mar 20, 2023
1ef9d27
Apply suggestions from code review
akoeplinger Mar 20, 2023
637e1e1
Deduplicate some strings
akoeplinger Mar 20, 2023
01f8e4e
Fixup string
akoeplinger Mar 20, 2023
c1b501c
Fix errors in resource strings
akoeplinger Mar 20, 2023
f38e86e
Update src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
akoeplinger Mar 20, 2023
27fa647
Merge branch main into databunks/main
akoeplinger Mar 21, 2023
5ad8622
Remove unused resource
akoeplinger Mar 21, 2023
6974e7c
A few more fixes
akoeplinger Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 281 additions & 4 deletions src/libraries/System.Private.CoreLib/src/Resources/Strings.resx

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/mono/System.Private.CoreLib/src/Mono/HotReload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(SR.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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/mono/System.Private.CoreLib/src/System/ArgIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new InvalidOperationException(SR.InvalidOperation_InvalidIteratorPosition);
throw new InvalidOperationException(SR.InvalidOperation_EnumEnded);

Similar existing string

TypedReference result = default;
unsafe
{
Expand All @@ -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
{
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/mono/System.Private.CoreLib/src/System/ModuleHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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))
Expand All @@ -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)
Expand Down Expand Up @@ -376,7 +376,7 @@ internal static IList<CustomAttributeData> 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];
Expand All @@ -389,7 +389,7 @@ internal static IList<CustomAttributeData> 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);
Expand All @@ -410,7 +410,7 @@ internal static IList<CustomAttributeData> GetCustomAttributesData(ICustomAttrib
{
AttributeUsageAttribute usage;
if (attrData == null)
throw new CustomAttributeFormatException(Message);
throw new CustomAttributeFormatException(SR.CustomAttributeFormat_InvalidCustomAttributeFormat);

Type attrType = attrData.AttributeType;
if (attributeType != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(SR.Argument_NullParameterTypes, nameof(parameterTypes));

this.parameters = new Type[parameterTypes.Length];
Array.Copy(parameterTypes, this.parameters, parameterTypes.Length);
Expand Down Expand Up @@ -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(SR.Format(SR.InvalidOperation_MethodDoesNotHaveBody, Name));
}
if (IsStatic &&
((call_conv & CallingConventions.VarArgs) != 0 ||
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Loading