If I set the Icon property to a Vista icon, I get a FileFormatException stating that the image format is unrecognized. If I try the same thing with an old Windows XP icon (without PNG compressed images) it works correctly. I simply cannot believe that WPF doesn't support Vista icons.
I get an even weirder problem. My icon displays OK the first time, but the second time I try to display it I get the same FileFormatException. I tried removing the 256x256 image from the icon and now it works OK regardless of how many times I display it.
When you save the icon file with a 256x256x32 size picture without PNG-compressing the picture, WPF seems to be able to cope with it.
For example in Axialis Icon Studio you can rightclick the icon and disable the PNG-compression. I reckon there are other tools to do the same thing out there somewhere.
- Proposed as answer by Cory Plotts Thursday, November 14, 2013 5:47 PM
Recently I installed MS Blend 3, and I'm facing the same issue using compresses vista format (256x256x32). The only workaround I found so far is no compressing the images.
Is this STILL the only way?
Project Manager at INOVATIVA Tecnologia www.inovativatec.com
I love bringing up a three-year old thread, but doing some research I came across this issue.
Oddly, a few coworkers have been getting this issue with an in-house produced Visual Studio Add-on. However, the issue didn't appear (meaning that the Add-on was working fine in their systems) until they installed .NET 4.0 and VS2010. I'm running Win7 and do not get the issue - however, the ones with the issues are running XP.
So something with installing VS2010 or .NET 4.0 caused this issue to rear its ugly head on XP. It worked on the same machines with .NET 3.5 and VS2008 installed.
I am using .NET 4 with VS 2010 pro on Window 7. My software displayed some .ico files. It is working good on window 7 but window vista are showing problems like not displayed icon on second time , delay atcs.
I just remove 256 by 256 image from ico file and it is working smoothly on vista also.
This exp might help somebody.
Very annoying bug to track down, my developer machine is currently XP (still targeting customers using XP)
The 256x256 png icons work fine in on XP, both running from debug/release and also from outside Visual Studio as an installed app.
It only crops up when using the application on any other machine. Not sure what dependency I've got installed in my dev PC to make the icon work.
I also encountered a similar problem on Windows 2008 Standard SP2.
The exception is:Timestamp: 2013/3/15 4:10:38
Message: HandlingInstanceID: 52a32845-c463-4d0d-b1c9-824dcab5ba3d
An exception of type 'System.IO.FileFormatException' occurred and was caught.
Type : System.IO.FileFormatException, WindowsBase, Version=220.127.116.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Message : 图像格式无法识别。
Source : PresentationCore
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void EnsureThumbnail()
Stack Trace : 在 System.Windows.Media.Imaging.BitmapFrameDecode.EnsureThumbnail()
在 MS.Internal.AppModel.IconHelper.GetBestMatch(ReadOnlyCollection`1 frames, Size size)
在 MS.Internal.AppModel.IconHelper.CreateIconHandleFromImageSource(ImageSource image, Size size)
在 MS.Internal.AppModel.IconHelper.GetIconHandlesFromImageSource(ImageSource image, IconHandle& largeIconHandle, IconHandle& smallIconHandle)
在 System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
在 System.Windows.Window.CreateSourceWindow(Boolean duringShow)
在 System.Windows.Window.ShowHelper(Object booleanBox)
在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
If I remove 256X256 image, this problem can be sovled.
I know this is very old now but I've had a bit of fun with this problem this morning. It turned out that the error was occurring only on XP machines where the colour settings were set to 16 bit, and when I changed it to 32-bit the problem magically disappeared.
This goes for XP (including Embedded) SP3.