I'm currently working with code resembling sth like this:
[DllImport("<native-dlllibrary>.dll")]
internal unsafe static extern void SetCallback([...], <delegateType> callback);
// This method calls provided callback in case of error
// synchronously
DllImport("<native-dlllibrary>.dll")]
internal unsafe static extern void SomeOperation([...]);
[...]
private void ActualCallback([...])
=> throw new Exception();
[...]
{
SetCallback([...], callback);
try
{
SomeOperation([...]);
}
catch(Exception e)
{
[...] // process exception
}
}
The dll library is pure C/C++ (no C++/CLI), so the exception should ideally flow C# (callback) -> C/C++ (SomeOperation) -> C# (try catch block), however when it is thrown program pretty much freezes. Is it possible for that exception to reach the final C# try catch block (out of the box without workarounds)? I know that catching non-CLS compliant exceptions is possible (Can you catch a native exception in C# code?), but in this case I'm throwing a CLS compliant exception passing native boundary.