-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Unable to catch in managed code any user exception thrown from native Linux code #10794
Comments
We do not support exception handling interop on Unix. There is no good way to do it. The Mono project has a great write up on it here: http://www.mono-project.com/docs/advanced/pinvoke/#runtime-exception-propagation . The same reasoning applies to .NET Core. |
Wow. Good reading indeed! In the end of the referenced section in that article, the author recommends as follows:
@jkotas, do you recommend the same approach for .NET Core wrapping native C++ as well? Thanks for the quick response and the reference! |
Yes. |
OK. Thank you for your time :) I'm closing this issue. |
@yaireclipse This would be entirely possible if the following proposal was adopted: https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/BnNRLtFXJMA/gZcutJGsBQAJ |
@AaronRobinsonMSFT, thanks for the interesting reference. Sounds like a good direction for C programming in general. Also might enable automatic translation of exceptions in non-Windows native code to managed code, and maybe even unifying Windows and non-Windows behavior. |
Basically, I have a solution that contains one project of managed C# .NET Core and another native linux C++ project. The managed code project uses the native one. In the native code I throw various C++ exceptions (such as
runtime_error
). In the managed code, I call the native code within atry
-catch
block, expecting to catch the offending exception(s) in the managed code.I've tried:
catch (Exception)
;catch (System.Runtime.CompilerServices.RuntimeWrappedException)
;catch {..}
;[SecurityCritical]
+[HandleProcessCorruptedStateExceptions]
, although I thought these exceptions are probably not considered corrupted-state exception, and even if they did, in Strip corrupted state exceptions handling #7272 @jkotas states that corrupted-state exceptions are not converted to managed exceptions;legacyCorruptedStateExceptionsPolicy
totrue
(again - although I thought I'm not dealing with corrupted-state exceptions).All, to no avail.
I've set-up this Minimal, Complete and Verifiable example that demonstrates what I currently fail to achieve, and the different attempts to solve it.
Tested with .NET Core 2.0, on Ubuntu 16.04.2 LTS (via Bash on Ubuntu on Windows) and CentOS Linux release 7.5.1804 (via Docker for Windows).
This was actually asked in the past on Stackoverflow by @levhaikin, a colleage of mine, with no answers, so we turn to you :) :
Thanks,
Yair
The text was updated successfully, but these errors were encountered: