On a Windows XP-based computer, the following code throws a System.ComponentModel.Win32Exception message with the message "Operation completed successfully"
System.Drawing.Icon icon = new System.Drawing.Icon("icon.ico");
I can stop the program crashing with
try
{
System.Drawing.Icon icon = new System.Drawing.Icon("icon.ico");
}
catch(System.ComponentModel.Win32Exception ex)
{
if (ex.NativeErrorCode != 0)
{
throw;
}
}
but of course the icon is not set.
Full stack trace
at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
at System.Drawing.Icon..ctor(String fileName, Int32 width, Int32 height)
at System.Drawing.Icon..ctor(String fileName)
at hermes.Window1..ctor() in D:\\projects\\hermesclient\\hermesWPF\\hermes\\Window1.xaml.cs:line 50"
This line 50 is the source line I posted.
This is a WPF application, and on a computer running Windows 7, the code works fine.
EDIT: The icon turned out to not work at all in Windows XP, adding that 256 color versions fixed it.
source
share