2011-02-04 44 views
9

WPF應用程序不會啓動我已經在.NET 4.0中編寫了一個WPF應用程序。由於System.IO.FileFormatException()

我已經安裝併成功運行於以下操作系統的應用程序:

  • 的Windows XP SP2
  • Vista的
  • 視窗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加載到目標計算機上。

+0

您是否100%確定目標機器具有您定位的.NET Framework的最新Service Pack? – abramlimpin 2011-02-04 04:36:25

+0

我沒有在這裏的機器,但除非我錯了.Net框架拋出了異常。錯誤日誌的第二行顯示'Framework版本:v4.0.30319',所以我認爲這是安裝的版本。 – 2011-02-04 04:59:19

回答

3

我不得不建議可能/一個窗口圖標文件是.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?

8

感謝對同一問題的提示。我發現我將Icon屬性設置爲Shell.xaml Window屬性中的ICO。我在VS中運行時刪除了無圖標窗口。然而,我去了項目屬性,並選擇了那裏的圖標(VS在我的資源文件夾中找到了圖標 - 酷!)。當應用程序構建包含ICO的EXE時,令人驚喜的是窗口上現在有相同的圖標。