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

Added more verbose error message when calling method using reflection and target type does not match passed type #98129

Merged
merged 24 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1832ee9
Added more verbose error message when calling method using reflection…
AndyBevan Feb 7, 2024
c288b1e
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 8, 2024
a752ad9
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 8, 2024
27a9e79
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 9, 2024
a31a219
Fixed resource string as per PR comment
AndyBevan Feb 9, 2024
77bd3bc
Merge branch 'issue-97022-reflection-error-reporting' of andybevan.gi…
AndyBevan Feb 9, 2024
f862337
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 9, 2024
2661679
Fixed the test related to a resource string change
AndyBevan Feb 9, 2024
de2fa81
Merge branch 'main' of github.com:dotnet/runtime into issue-97022-ref…
AndyBevan Feb 9, 2024
23ab00b
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 9, 2024
8b8d69a
Merge branch 'issue-97022-reflection-error-reporting' of andybevan.gi…
AndyBevan Feb 9, 2024
5d03e18
Merge branch 'main' of github.com:dotnet/runtime into issue-97022-ref…
AndyBevan Feb 9, 2024
1a1d326
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 9, 2024
1f96672
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 13, 2024
65e1f9d
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 13, 2024
ecbc25c
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 13, 2024
cb86250
Merge branch 'main' of github.com:dotnet/runtime into issue-97022-ref…
AndyBevan Feb 15, 2024
5083f8c
Modified test to have a contains check rather than validating the Eng…
AndyBevan Feb 15, 2024
74760e8
Merge branch 'issue-97022-reflection-error-reporting' of andybevan.gi…
AndyBevan Feb 15, 2024
1b6fe45
Modifications to AOT implementation for validating target type when a…
AndyBevan Feb 15, 2024
705a662
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 15, 2024
181894d
Merge branch 'main' into issue-97022-reflection-error-reporting
buyaa-n Feb 16, 2024
1fde682
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 16, 2024
8e837fc
Merge branch 'main' into issue-97022-reflection-error-reporting
AndyBevan Feb 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected static void ValidateThis(object thisObject, RuntimeTypeHandle declarin
throw new TargetException(SR.RFLCT_Targ_StatMethReqTarg);

if (!RuntimeAugments.IsAssignable(thisObject, declaringTypeHandle))
throw new TargetException(SR.RFLCT_Targ_ITargMismatch);
throw new TargetException(SR.Format(SR.RFLCT_Targ_ITargMismatch_WithType, declaringTypeHandle.GetRuntimeTypeInfoForRuntimeTypeHandle().Name, thisObject.GetType().Name));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,9 @@
<data name="RFLCT_Targ_ITargMismatch" xml:space="preserve">
AndyBevan marked this conversation as resolved.
Show resolved Hide resolved
<value>Object does not match target type.</value>
</data>
<data name="RFLCT_Targ_ITargMismatch_WithType" xml:space="preserve">
danmoseley marked this conversation as resolved.
Show resolved Hide resolved
<value>Object type {0} does not match target type {1}.</value>
</data>
<data name="RFLCT_Targ_StatFldReqTarg" xml:space="preserve">
<value>Non-static field requires a target.</value>
</data>
Expand Down Expand Up @@ -4307,4 +4310,4 @@
<data name="WasmThreads_BlockingWaitNotSupportedOnJSInterop" xml:space="preserve">
<value>Blocking wait is not supported on the JS interop threads.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal static void ValidateInvokeTarget(object? target, MethodBase method)

if (!method.DeclaringType!.IsInstanceOfType(target))
{
throw new TargetException(SR.RFLCT_Targ_ITargMismatch);
throw new TargetException(SR.Format(SR.RFLCT_Targ_ITargMismatch_WithType, method.DeclaringType.Name, target.GetType().Name));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ public static void DefaultBinderNamedParametersSkippedAndOutOfOrderTest()
Assert.Equal("MethodMoreParameters", method.Name);
}

[Fact]
public void InvokeWithIncorrectTargetTypeThrowsCorrectException()
{
Type t = typeof(Sample);
object incorrectInstance = Activator.CreateInstance(t);
MethodInvoker invoker = MethodInvoker.Create(typeof(Test).GetMethod(nameof(Test.TestMethod)));

TargetException ex = Assert.Throws<TargetException>(() => invoker.Invoke(obj: incorrectInstance, "NotAnInt"));
Assert.Contains(nameof(Test), ex.Message);
Assert.Contains(nameof(Sample), ex.Message);
}

[Fact]
public static void InvokeWithNamedParameters1st2ndTest()
{
Expand Down
Loading