Why do I get an InvalidCastException
when trying to do this?
throw (ArgumentNullException)(new Exception("errormessage", null));
This is a simplified version of the following function.
public static void Require<T>(bool assertion, string message, Exception innerException) where T: Exception
{
if (!assertion)
{
throw (T)(new Exception(message, innerException));
}
}
The complete error message is:
System.InvalidCastException : Unable to cast object of type 'System.Exception' to type 'System.ArgumentNullException'.