As I started my new WPF application, I got greeted with FileFormatException - "The image format is unrecognized". I was confused since application was so new that I haven't added any images to it. After checking and double-checking I found which image exception was referring to - my application icon.
It seemed like normal icon to me. As I compared it to icons that I already used successfully with WPF there was only one difference. This icon had 256x256 size. As soon as I deleted it, my program started working again (ok, it was empty application so making it work was not that big of task).
Side effect of this solution was that I lost my big images. That felt dirty to me so I ended up with two icons in my application. First one was with all images (including 256x256) and I used it as application icon (Properties, Application, Icon). Second one was without 256x256 images and I just set it's Build Action to "Resource". Whenever I needed WPF window icon, I just pointed to second one.
I must confess that I am quite annoyed by this. WPF was all about making Windows look and feel better. Using brand new .NET 4 and restricting icons to sizes before Vista just does not seem right. And I better not start about how useful XAML exceptions are...
P.S. If you do not have icon editor available, I would recommend IcoFx. It is good and it is free.
thanks for help, i’ve had the same issue but seriously, who needs 256×256 icons? (Yes, i had 256×256 icon in my ico file because i’ve used batch build command from IcoFX program)
Thank you, great tip!
Thanks. This helped solve my problem.
-Peter
There is a better solution to your problem. Simply don’t compress the image. See http://stackoverflow.com/questions/12385143/wpf-application-shows-image-format-is-unrecognized/19984844#19984844 for more info.
And, yes, that screenshot is from IcoFX … I use that tool too.
Hope this makes you happy! I couldn’t believe that I had to rip out the 256×256 image in order to support Windows XP. Well, it turns out that you don’t have to!
That is nice solution. Thanks.
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.