System.Drawing.Icon构造投掷"操作已成功&QUOT完成;例外操作、Drawing、System、QUOT

2023-09-03 16:55:55 作者:灰飞烟灭

在Windows XP计算机,以下code是扔System.ComponentModel.Win32Exception的消息已成功完成的操作

On a Windows XP machine, the following code is throwing a System.ComponentModel.Win32Exception with the message "The 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.

完整的堆栈跟踪

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"

这行50是原线我张贴。

That line 50 is the original line I posted.

这是一个WPF应用程序,并在Windows 7计算机上code正常工作。

This is a WPF app, and on a Windows 7 machine the code works fine.

编辑:原来的图标不工作在Windows XP中所有,加入256色版本似乎已经固定它

Turned out the icon wasn't working in Windows XP at all, adding 256 colour versions seems to have fixed it.

推荐答案

原来的图标不工作在Windows XP中所有,加入256色版本,似乎已经解决了。

Turned out the icon wasn't working in Windows XP at all, adding 256 colour versions seems to have fixed it.