Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions runtime/coreclr-bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,7 @@
void
xamarin_bridge_raise_unhandled_exception_event (GCHandle exception_gchandle)
{
// There's no way to raise the AppDomain.UnhandledException event.
// https://github.com/dotnet/runtime/issues/102730
xamarin_bridge_raise_appdomain_unhandled_exception_event (exception_gchandle);
}

#endif // CORECLR_RUNTIME
8 changes: 8 additions & 0 deletions runtime/delegates.t4
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,14 @@
) {
WrappedManagedFunction = "LookupUnmanagedFunction",
},

new XDelegate ("void", "void", "xamarin_bridge_raise_appdomain_unhandled_exception_event",
"GCHandle", "IntPtr", "gchandle"
) {
WrappedManagedFunction = "RaiseAppDomainUnhandledExceptionEvent",
OnlyDynamicUsage = false,
OnlyCoreCLR = true,
},
};
delegates.CalculateLengths ();
#><#+
Expand Down
7 changes: 7 additions & 0 deletions src/ObjCRuntime/Runtime.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ static bool xamarin_locate_assembly_resource (string assembly_name, string? cult
return exceptionHandler;
}

static void RaiseAppDomainUnhandledExceptionEvent (IntPtr gchandle)
{
var exception = GetGCHandleTarget (gchandle);
if (exception is not null)
ExceptionHandling.RaiseAppDomainUnhandledExceptionEvent (exception);
}

// Size: 2 pointers
internal struct TrackedObjectInfo {
public IntPtr Handle;
Expand Down
24 changes: 24 additions & 0 deletions tests/dotnet/ExceptionalTestApp/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.InteropServices;

using Foundation;
using ObjCRuntime;

namespace MySimpleApp {
public class Program {
Expand All @@ -26,6 +27,21 @@ static int Main (string [] args)
Environment.Exit (0);
};
throw new TestCaseException ();
case 2:
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => {
if (e.ExceptionObject is TestCaseException) {
Console.WriteLine (Environment.GetEnvironmentVariable ("MAGIC_WORD"));
} else {
Console.WriteLine ($"Unexpected exception type: {e.ExceptionObject?.GetType ()}");
}
Environment.Exit (0);
};

var obj = new ThrowExceptionClass ();
var thread = new NSThread (obj, new Selector ("throwException:"), null);
thread.Start ();
System.Threading.Thread.Sleep (10000);
break;
default:
Console.WriteLine ($"Unknown test case: {testCase}");
return 3;
Expand All @@ -36,6 +52,14 @@ static int Main (string [] args)
}
}

class ThrowExceptionClass : NSObject {
[Export ("throwException:")]
public void ThrowException (NSObject obj)
{
throw new TestCaseException ();
}
}

class TestCaseException : Exception {
public TestCaseException ()
: base ("Testing, testing")
Expand Down
2 changes: 1 addition & 1 deletion tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,7 @@ public void SourcelinkTest (ApplePlatform platform, string runtimeIdentifiers, s
[Test]
// [TestCase (ApplePlatform.iOS)] // Skipping because we're not executing tvOS apps anyway (but it should work)
// [TestCase (ApplePlatform.TVOS)] // Skipping because we're not executing tvOS apps anyway (but it should work)
[TestCase (ApplePlatform.MacOSX)] // https://github.com/dotnet/runtime/issues/102730
[TestCase (ApplePlatform.MacOSX)]
[TestCase (ApplePlatform.MacCatalyst)]
public void RaisesAppDomainUnhandledExceptionEvent (ApplePlatform platform)
{
Expand Down