Skip to content

Commit 2f43856

Browse files
authored
Include namespace in the reflection error message (#98617)
1 parent 432397d commit 2f43856

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/MethodBaseInvoker.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected static void ValidateThis(object thisObject, RuntimeTypeHandle declarin
5757
throw new TargetException(SR.RFLCT_Targ_StatMethReqTarg);
5858

5959
if (!RuntimeAugments.IsAssignable(thisObject, declaringTypeHandle))
60-
throw new TargetException(SR.Format(SR.RFLCT_Targ_ITargMismatch_WithType, declaringTypeHandle.GetRuntimeTypeInfoForRuntimeTypeHandle().Name, thisObject.GetType().Name));
60+
throw new TargetException(SR.Format(SR.RFLCT_Targ_ITargMismatch_WithType, declaringTypeHandle.GetRuntimeTypeInfoForRuntimeTypeHandle(), thisObject.GetType()));
6161
}
6262
}
6363
}

src/libraries/System.Private.CoreLib/src/System/Reflection/FieldAccessor.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ internal void VerifyInitOnly()
381381
if ((_fieldInfo.Attributes & FieldAttributes.InitOnly) == FieldAttributes.InitOnly &&
382382
_fieldAccessType != FieldAccessorType.SlowPathUntilClassInitialized)
383383
{
384-
ThrowHelperFieldAccessException(_fieldInfo.Name, _fieldInfo.DeclaringType?.FullName);
384+
ThrowHelperFieldAccessException(_fieldInfo);
385385
}
386386
}
387387

@@ -480,8 +480,8 @@ private static FieldAccessorType GetIntPtrAccessorTypeForStatic()
480480
private static void ThrowHelperArgumentException(object target, FieldInfo fieldInfo) =>
481481
throw new ArgumentException(SR.Format(SR.Arg_FieldDeclTarget, fieldInfo.Name, fieldInfo.DeclaringType, target.GetType()));
482482

483-
private static void ThrowHelperFieldAccessException(string fieldName, string? declaringTypeName) =>
484-
throw new FieldAccessException(SR.Format(SR.RFLCT_CannotSetInitonlyStaticField, fieldName, declaringTypeName));
483+
private static void ThrowHelperFieldAccessException(FieldInfo fieldInfo) =>
484+
throw new FieldAccessException(SR.Format(SR.RFLCT_CannotSetInitonlyStaticField, fieldInfo.Name, fieldInfo.DeclaringType));
485485

486486
private enum FieldAccessorType
487487
{

src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvokerCommon.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ internal static void ValidateInvokeTarget(object? target, MethodBase method)
9696

9797
if (!method.DeclaringType!.IsInstanceOfType(target))
9898
{
99-
throw new TargetException(SR.Format(SR.RFLCT_Targ_ITargMismatch_WithType, method.DeclaringType.Name, target.GetType().Name));
99+
throw new TargetException(SR.Format(SR.RFLCT_Targ_ITargMismatch_WithType, method.DeclaringType, target.GetType()));
100100
}
101101
}
102102

0 commit comments

Comments
 (0)