diff --git a/ILRuntime/Runtime/Intepreter/DelegateAdapter.cs b/ILRuntime/Runtime/Intepreter/DelegateAdapter.cs index 5764ef3e..14c45a64 100644 --- a/ILRuntime/Runtime/Intepreter/DelegateAdapter.cs +++ b/ILRuntime/Runtime/Intepreter/DelegateAdapter.cs @@ -1110,7 +1110,7 @@ public override bool CanAssignTo(IType type) } if (im.IsDelegateInvoke) { - if (im.ParameterCount == method_count && ret_type == method.ReturnType) + if (im.ParameterCount == method_count && method.ReturnType.CanAssignTo(ret_type)) { for (int i = 0; i < im.ParameterCount; i++) diff --git a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs index 3ac3daf8..1061f8f9 100644 --- a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs +++ b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs @@ -3628,7 +3628,14 @@ public object Run(ILMethod method, object instance, object[] p) } else { - throw new InvalidCastException(string.Format("Cannot Cast {0} to {1}", ((ILTypeInstance)obj).Type.FullName, type.FullName)); + string curType; + if (type.IsDelegate) + { + curType = $"{((DelegateAdapter)obj).Method.DeclearingType.FullName}.{((DelegateAdapter)obj).Method.Name}"; + } + else + curType = ((ILTypeInstance)obj).Type.FullName; + throw new InvalidCastException(string.Format("Cannot Cast {0} to {1}", curType, type.FullName)); } } else