Exception handling not working well on non-Windows platforms in R2R
The problem is when the exception is thrown from the DynamicHelperWorker API, used in R2R helper calls.
Minimal repro (crossgen binary before running it on Ubuntu):
public interface IUnimplemented { void UnimplementedMethod(); }
public class Castable : System.Runtime.CompilerServices.ICastable { public bool IsInstanceOfInterface(RuntimeTypeHandle interfaceType, out Exception castError) { castError = null; Console.WriteLine(String.Format("IsInstanceOfInterface has been called for type {0}", Type.GetTypeFromHandle(interfaceType))); return false; }
public RuntimeTypeHandle GetImplType(RuntimeTypeHandle interfaceType)
{
Console.WriteLine(String.Format("GetImplType has been called for type {0}", Type.GetTypeFromHandle(interfaceType)));
return this.GetType().TypeHandle;
}
}
public class Test { public static int Main(string[] args) { object implProxy = new Castable();
try
{
var foo = (IUnimplemented)implProxy;
Console.WriteLine("ERROR: CHKCAST didn't throw!!");
}
catch (InvalidCastException)
{
Console.WriteLine("PASSED");
return 100;
}
return -1;
}
}
Fixed by dotnet/coreclr#5446
@janvorli I am reopening this issue to track getting the fix into the release branch.
@gkhanna79 ok, makes sense.
Fixed by https://github.com/dotnet/coreclr/pull/5461