private bool IsValidImage(byte[] bytes)
{
try
{
using (MemoryStream ms = new MemoryStream(bytes))
Image.FromStream(ms, true, true);
}
catch (ArgumentException)
{
return false;
}
return true;
}
Can someone tell me what I'm doing wrong? This works fine when the actual byte array is an image. But when I pass in another type of file, like docx or xlsx then I get runtime error of "Parameter is not valid" on FromStream. The exception doesn't get caught in the catch block either. If the FromStream throws an ArgumentException, it should get caught in the catch block, right?