由于System.IO.FileFormatException(),WPF应用程序无法启动

时间:2011-02-04 03:44:18

标签: .net wpf

我在.NET 4.0中编写了一个WPF应用程序。

我已在以下操作系统上安装并成功运行该应用程序:

  • Windows XP SP2
  • Vista的
  • Window 7(32位)
  • Windows 7(64位)

在装有Windows XP SP3的计算机上安装应用程序后,应用程序无法启动。我检查了事件查看器的应用程序日志,发现以下错误:

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()

所以我猜它有一些东西要做我在我的一个窗口中的图像,但不确定是什么;)

之前有没有人见过这个例外并有解决方案?

注意:如果这是相关的,我的安装程序会在必要时将WIC和完整的.NET Framework 4.0加载到目标计算机上。

2 个答案:

答案 0 :(得分:8)

感谢有关同一问题的提示。我发现我在Shell.xaml Window属性中将Icon属性设置为ICO。当我在VS中运行时,我删除了提供无图标窗口的那个。但是我去了项目属性并在那里选择了图标(VS在我的资源文件夹中找到了图标 - 很酷!)。当应用程序构建EXE时,它包含ICO,令人惊喜的是窗口现在具有相同的图标。

答案 1 :(得分:3)

我必须建议/ a窗口图标文件可能是.png格式,将文件转换为.jpeg,重试应该是值得的。

请注意,根据我的经验,在看似有缺陷的机器上使用Visual Studio进行调试实际上没有问题。

我很抱歉我没有任何关于此事的参考,但是通过自我调查向我揭示了这一点,因为研究结果不是很少。我会尝试看看现在是否有任何信息,就像前一段时间一样。

编辑:

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?