I have looked at the other questions related to this problem but I do not see answer that helps me (or perhaps more to the point that I understand).
This code:
public static Bitmap GetLibraryObjectImage(Guid guid) {
try {
string tempPath = GetLibraryObjectImagePath(guid);
if (tempPath != string.Empty) {
var bytes = File.ReadAllBytes(tempPath);
var ms = new MemoryStream(bytes);
return (Bitmap)Image.FromStream(ms);
}
}
catch {
return (Bitmap)Image.FromFile(Application.StartupPath + @"\na.bmp");
}
return (Bitmap)Image.FromFile(Application.StartupPath + @"\na.bmp");
}
is intended to deal with any situation in which the image file is not found or is invalid in some other way. I have not identified any specific exception type in the hope that it will catch anything.
For one of my users it threw this exception:
Invalid Parameter.
At System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) At System.Drawing.Image.FromStream(Stream stream)
At ScruffyDuck.AirportDesignEditor.Helpers.U.GetLibraryObjectImage(Guid guid)
I have seen this before in other situations in try-catch blocks where handling images. I thought that the above try-catch would get everything including unmanaged exceptions but perhaps I am wrong.
I have no idea regarding the circumstances causing the exception but I really don't want my app to crash and burn even if I am trying to manage the problems. It was caught by my global exception handler but of course by then it is a bit late.
Many thanks for any insight into avoiding this