-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Cannot catch exceptions from reverse P/Invoke on Linux #7342
Comments
Seems to be related with #6820. |
@halter73 this is by design in CoreCLR and we are going to make it behave the same way on Windows too (see #7086). For some details, please see dotnet/coreclr#7652 (comment). |
Does that mean that one should wrap every callback in (pseudo-C#) try
{
some code that might throw
}
catch (System.Object o)
{
if (o is System.Exception) {
// log a stack trace maybe?
}
} |
@halter73 note that libuv is likely in an inconsistent state even on Windows – as a C library it is not designed to handle this scenario. |
@DemiMarie yes, the exceptions need to be caught at that boundary. What the code does when the exception is caught is specific to the application / library. It might be logging and then ignoring the exception, it might be logging and failing fast or converting the exception to some kind of status that's propagated to the managed code that called the native code that called the faulting managed code. |
The following app will print "Handled exception from reverse P/Invoke" on Windows and then exit. On Linux it will crash with an unhandled exception. I tested this using Microsoft.NETCore.App 1.1 on both platforms. I did not test this on macOS or with other versions of the dotnet runtime.
Windows output:
Linux output:
We expect to be able to catch and handle these exceptions in KestrelHttpServer.
The text was updated successfully, but these errors were encountered: