9

I have written a WPF application in .NET 4.0.

I have installed and successfully run the application on the following operating systems:

  • Windows XP SP2
  • Vista
  • Window 7 (32 bit)
  • Windows 7 (64 bit)

After installing the application on a machine with Windows XP SP3, the application failed to start. I checked the Event Viewer's application logs and found the following error:

Application: ApplicationName.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileFormatException
Stack:
   at System.Windows.Media.Imaging.BitmapFrameDecode.EnsureThumbnail()
   at System.Windows.Media.Imaging.BitmapFrameDecode.get_Thumbnail()
   at MS.Internal.AppModel.IconHelper.GetBestMatch(System.Collections.ObjectModel.ReadOnlyCollection`1<System.Windows.Media.Imaging.BitmapFrame>, System.Windows.Size)
   at MS.Internal.AppModel.IconHelper.CreateIconHandleFromImageSource(System.Windows.Media.ImageSource, System.Windows.Size)
   at MS.Internal.AppModel.IconHelper.GetIconHandlesFromImageSource(System.Windows.Media.ImageSource, IconHandle ByRef, IconHandle ByRef)
   at System.Windows.Window.UpdateIcon()
   at System.Windows.Window.SetupInitialState(Double, Double, Double, Double)
   at System.Windows.Window.CreateSourceWindow(Boolean)
   at System.Windows.Window.CreateSourceWindowDuringShow()
   at System.Windows.Window.SafeCreateWindowDuringShow()
   at System.Windows.Window.ShowHelper(System.Object)
   at System.Windows.Window.Show()
   at ApplicationName.App.LoadMainWindow()
   at ApplicationName.App.OnStartup(System.Windows.StartupEventArgs)
   at System.Windows.Application.<.ctor>b__1(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.runTryCode(System.Object)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at ApplicationName.App.Main()

So I am guessing that it has something to do one of the images I have in one of my windows, but not sure what ;)

Has anyone seen this exception before and have a solution?

Note: In case this is relevant, my installer loads WIC and the full .NET Framework 4.0 onto the target machine, where necessary.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Ryan Spears
  • 2,963
  • 2
  • 31
  • 39
  • Are you 100% sure the target machine has the latest service pack of the .NET Framework you're targeting? – abramlimpin Feb 04 '11 at 04:36
  • I don't have the machine here but unless I am mistaken the .Net Framework threw the exception. The second line of the error log showed 'Framework Version: v4.0.30319', so I assume that is the version installed. – Ryan Spears Feb 04 '11 at 04:59
  • If it has something to do with font issue/s, you might want to check this link: http://forums.silverlight.net/forums/p/176008/396460.aspx – abramlimpin Feb 04 '11 at 06:21
  • you might be able to locate the image that it is having the problem with by using the sysinternals [procmon](http://technet.microsoft.com/en-us/sysinternals/bb896645) tool to monitor which files it is accessing. – Sam Holder Feb 04 '11 at 09:16

2 Answers2

8

Thanks for the hints on same issue. I found that I had the Icon property set to an ICO within the Shell.xaml Window property. I removed that which gives the icon-less window when I run in VS. However I went to the project properties and selected the icon there (VS found the icon in my resources folder-cool!). When the application builds the EXE the contains the ICO, and a nice surprise is that the window now has the same icon on it.

Andrew
  • 81
  • 1
  • 2
3

I would have to suggest that possibly the/a window icon file is in .png format, converting the file to a .jpeg and retrying ought to be worth your while.

Note that intriguingly, debugging with Visual Studio on the seemingly defective machine actually doesn't have problems, in my experience.

My apologies that I don't have any references regarding this matter, but it was brought to light to me by self investigation as research turned up less than scarce results. I will try and see if there is any information out there now, as it was some time ago.

EDIT:

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9e723d51-0e26-4609-8fe1-5e0edcf7385b

How do I get an Icon from a png image?

Community
  • 1
  • 1
Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
  • I removed the icon from the Window as you suggested and I no longer got the exception. I will change the image from .ico to .jpeg and see how that goes. Thanks for the help. – Ryan Spears Feb 24 '11 at 23:06
  • Take a look into the bitiness of your *.ico image/s, it may be part of the problem along with the initial format (I'm no expert in the internal storage of icon files) - try saving your icon with different colour ranges. – Grant Thomas Feb 25 '11 at 00:36
  • http://connect.microsoft.com/VisualStudio/feedback/details/321285/wpf-application-fails-if-window-icon-is-a-vista-ico-file – JulianM Mar 21 '12 at 03:39
  • My icon was a PNG, converted it to an ICO using Icon Sushi, works fine now. – Chris Fulstow Feb 13 '13 at 15:53