Skip to content

Commit

Permalink
[Runtime] Provide better diagnostics if we fail to invoke a method in…
Browse files Browse the repository at this point in the history
… CoreCLR. (#15043)

A stack trace like this isn't all that helpful:

    *** Terminating app due to uncaught exception 'System.Reflection.TargetException', reason: 'Object does not match target type. (System.Reflection.TargetException)
    at System.Reflection.RuntimeConstructorInfo.CheckConsistency(Object target)
    at System.Reflection.RuntimeConstructorInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at ObjCRuntime.Runtime.InvokeMethod(MethodBase method, Object instance, IntPtr native_parameters) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.CoreCLR.cs:line 655
    at ObjCRuntime.Runtime.InvokeMethod(MonoObject* methodobj, MonoObject* instanceobj, IntPtr native_parameters) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.CoreCLR.cs:line 552
    at ObjCRuntime.Runtime.bridge_runtime_invoke_method(MonoObject* method, MonoObject* instance, IntPtr parameters, IntPtr& exception_gchandle) in /Users/builder/azdo/_work/1/s/xamarin-macios/runtime/Delegates.generated.cs:line 1210

with this change we'll be told exactly which function we failed to call.
  • Loading branch information
rolfbjarne authored May 18, 2022
1 parent 2aae39d commit 5c08c5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ObjCRuntime/Runtime.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ static object InvokeMethod (MethodBase method, object instance, IntPtr native_pa
var ex = tie.InnerException ?? tie;
// This will re-throw the original exception and preserve the stacktrace.
ExceptionDispatchInfo.Capture (ex).Throw ();
} catch (Exception e) {
throw ErrorHelper.CreateError (8042, e, Errors.MX8042 /* An exception occurred while trying to invoke the function {0}: {1}. */, GetMethodFullName (method), e.Message);
}

// Copy any byref parameters back out again
Expand Down
9 changes: 9 additions & 0 deletions tools/mtouch/Errors.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tools/mtouch/Errors.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2164,4 +2164,11 @@
<value>Unable to create an instance of the type {0}.</value>
</data>

<data name="MX8042" xml:space="preserve">
<value>An exception occurred while trying to invoke the function {0}: {1}.</value>
<comment>
0: name of function
1: exception info
</comment>
</data>
</root>

5 comments on commit 5c08c5a

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

💻 [CI Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: 5c08c5a6899fa27d677193826d11edde4d8b1739

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

📋 [CI Build] API Diff 📋

API diff (for current PR)

ℹ️ API Diff (from PR only) (please review changes)

API diff: vsdrops gist

Xamarin
.NET
Xamarin vs .NET
iOS vs Mac Catalyst (.NET)

API diff (vs stable)

✅ API Diff from stable

API diff: vsdrops gist

Xamarin
.NET
Xamarin vs .NET
iOS vs Mac Catalyst (.NET)

Generator diff

ℹ️ Generator Diff (please review changes)

Pipeline on Agent XAMMINI-052.Monterey'
Hash: 5c08c5a6899fa27d677193826d11edde4d8b1739

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

Failed tests are:

  • xammac_tests
  • monotouch-test

Pipeline on Agent
Hash: 5c08c5a6899fa27d677193826d11edde4d8b1739

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

📚 [CI Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMMINI-053.Monterey'
Hash: 5c08c5a6899fa27d677193826d11edde4d8b1739

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

1 tests failed, 233 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug [dotnet]: TimedOut

Pipeline on Agent XAMBOT-1042.Monterey
[Runtime] Provide better diagnostics if we fail to invoke a method in CoreCLR. (#15043)

Please sign in to comment.