IconUtil.ToBitmap() throws ArgumentException on certain icons
Opened this issue · 0 comments
SamusAranX commented
In an application of mine, I need to enumerate other applications' icons.
The Windows Defender executable on Windows 10 (C:\Program Files\Windows Defender\MSASCuiL.exe
) makes IconUtil choke and throw an exception.
Check this out:
// Gets the biggest icon of an .exe file
public static Bitmap GetEXEIconBitmap(string path) {
IconExtractor ie = new IconExtractor(path);
if (ie.Count > 0) {
Icon bigIcon = IconUtil.Split(ie.GetIcon(0)).OrderByDescending(i => IconUtil.ToBitmap(i).PhysicalDimension.Width).First();
return IconUtil.ToBitmap(bigIcon);
} else {
Debug.WriteLine("ExtractAssociatedIcon");
return Icon.ExtractAssociatedIcon(path).ToBitmap();
}
}
That crazy long LINQ query sorts all icons by size and returns the largest one it can find.
When I do this with the abovementioned executable's path, IconUtil throws an ArgumentException:
At this point, I'm stumped. Even more so because it works maybe one in a hundred times, but crashes all the other times. Is Windows protecting Windows Defender by disallowing all access to it or does its executable really contain corrupt icon data?