Windows XPマシンでは、次のコードは「操作が正常に完了しました」というメッセージとともにSystem.ComponentModel.Win32Exceptionをスローします。
System.Drawing.Icon icon = new System.Drawing.Icon("icon.ico");
プログラムのクラッシュを止めることができます
try
{
System.Drawing.Icon icon = new System.Drawing.Icon("icon.ico");
}
catch(System.ComponentModel.Win32Exception ex)
{
if (ex.NativeErrorCode != 0)
{
throw;
}
}
もちろん、アイコンは設定されていません。
フルスタックトレースは
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行目は私が投稿した元の行です。
これはWPFアプリであり、Windows7マシンではコードは正常に機能します。
編集:アイコンがWindows XPでまったく機能していなかったことが判明し、256色のバージョンを追加すると修正されたようです。