You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Faster Exceptions: unmanaged exception handling in C++/CLI #114727
Using System.Runtime.LegacyExceptionHandling can fix the problem, but the configuration will be removed in future. So I hope the problem can be fixed in "Faster Exceptions".
Reproduction Steps
See above
Expected behavior
C++/CLI should be able to handle unmanaged exception.
Actual behavior
Faster Exceptions transfers unmanaged exception to managed exception.
Regression?
No response
Known Workarounds
set System.Runtime.LegacyExceptionHandling to true
@panxn Can you also please share how you are compiling your C++/CLI? Specifically what /clr flag setting are you using? I'd like to better understand community usage in general.
I managed to reproduce this in a small project (/clr:netcore library invoked from C# executable). There's nothing fundamentally incompatible (as in, should be easy to fix), the C++/CLI code throws the exception from native code, it enters the managed code which wraps it, and then it uses a filter to identify the C++ exceptions (based on Marshal.GetExceptionPointers()).
NetConsoleApp.csproj is .NET Console App, it was created from Visual Studio 2022 17.12
Net8CppCliDll.vcxproj is C++/CLI DLL, also created from VS, project type is "CLR Empty Project (.NET)"
The dotnet console app calls function defined in c++/cli. Exceptions are thrown and caught in c++/cli.
Modify NetConsoleApp.csproj to use net8 or net9/10, or enable System.Runtime.LegacyExceptionHandling with net9/10 to watch the difference.
This is a typical usage:
std::map<int, int> m;
try {
m.at(1);
} catch (std::out_of_range) {
// should be caught in c++/cli
}
I can confirm that the issue was fix by my recent change. The test app that @panxn shared above prints "std::exception" with the current main branch while it prints "System::Exception" with older .NET 10. The change missed preview 3 by a couple of days, so it will be in preview 4.
Thanks @janvorli. Looks like we can close this. @panxn please consider using .NET 10 Preview 4 to validate these changes. Let's track any servicing of .NET 9 in the PR that fixes the issue.
Activity
AaronRobinsonMSFT commentedon Apr 20, 2025
@janvorli What is the way forward here? I didn't think we would be regressing C++/CLI by default.
AaronRobinsonMSFT commentedon Apr 20, 2025
@panxn Can you also please share how you are compiling your C++/CLI? Specifically what
/clrflag setting are you using? I'd like to better understand community usage in general.filipnavara commentedon Apr 20, 2025
I managed to reproduce this in a small project (
/clr:netcorelibrary invoked from C# executable). There's nothing fundamentally incompatible (as in, should be easy to fix), the C++/CLI code throws the exception from native code, it enters the managed code which wraps it, and then it uses a filter to identify the C++ exceptions (based onMarshal.GetExceptionPointers()).filipnavara commentedon Apr 20, 2025
Here are binaries of the repro, the build process is a bit convoluted: cppcli-exception.zip
It seems to pass on latest .NET 10 (main, not tested on Preview 3) but extra verification would be welcome.
panxn commentedon Apr 21, 2025
I made a code sample to reproduce it CppCliException.zip:
The dotnet console app calls function defined in c++/cli. Exceptions are thrown and caught in c++/cli.
Modify
NetConsoleApp.csprojto use net8 or net9/10, or enableSystem.Runtime.LegacyExceptionHandlingwith net9/10 to watch the difference.This is a typical usage:
janvorli commentedon Apr 23, 2025
Let me take a look. I have recently fixed a bug in the native exception handling (#113323), chances are this issue is related.
janvorli commentedon Apr 23, 2025
I can confirm that the issue was fix by my recent change. The test app that @panxn shared above prints "std::exception" with the current main branch while it prints "System::Exception" with older .NET 10. The change missed preview 3 by a couple of days, so it will be in preview 4.
AaronRobinsonMSFT commentedon Apr 23, 2025
Thanks @janvorli. Looks like we can close this. @panxn please consider using .NET 10 Preview 4 to validate these changes. Let's track any servicing of .NET 9 in the PR that fixes the issue.
panxn commentedon Apr 24, 2025
Thank you! I will use preview 4.