开发平台:Win7 + Vs2010 (WFP .Net4)
安装平台:WinXpSp3
长话短说,昨天在进行一个WPF程序的安装时,发生一个很麻烦的错误,具体表现为:打开这个软件就直接报错,报错界面如下:
到事件查看器里面,看到2条错误,分别是:


事件类型: 错误 事件来源: .NET Runtime 事件种类: 无 事件 ID: 1026 日期: 2012/05/31 事件: 8:08:03 用户: N/A 计算机: LWS-12 描述: 应用程序: RepairPartsScreen.exe Framework 版本: v4.0.30319 说明: 由于未经处理的异常,进程终止。 异常信息: System.Windows.Markup.XamlParseException 堆栈: 在 System.Windows.Markup.XamlReader.RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri) 在 System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri) 在 System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri) 在 System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean) 在 System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext) 在 System.Windows.Application.LoadComponent(System.Uri, Boolean) 在 System.Windows.Application.DoStartup() 在 System.Windows.Application.<.ctor>b__1(System.Object) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) 在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) 在 System.Windows.Threading.DispatcherOperation.InvokeImpl() 在 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) 在 System.Threading.ExecutionContext.runTryCode(System.Object) 在 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object) 在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 在 System.Windows.Threading.DispatcherOperation.Invoke() 在 System.Windows.Threading.Dispatcher.ProcessQueue() 在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) 在 MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) 在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) 在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) 在 System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) 在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) 在 MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) 在 System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 在 System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) 在 System.Windows.Threading.Dispatcher.Run() 在 System.Windows.Application.RunDispatcher(System.Object) 在 System.Windows.Application.RunInternal(System.Windows.Window) 在 System.Windows.Application.Run(System.Windows.Window) 在 RepairPartsScreen.App.Main() 有关更多信息,请参阅在 http://go.microsoft.com/fwlink/events.asp 的帮助和支持中心。


事件类型: 错误 事件来源: .NET Runtime 4.0 Error Reporting 事件种类: 无 事件 ID: 5000 日期: 2012/05/31 事件: 8:07:59 用户: N/A 计算机: LWS-12 描述: EventType clr20r3, P1 repairpartsscreen.exe, P2 1.0.0.0, P3 4fc5e671, P4 presentationframework, P5 4.0.0.0, P6 4ba1f8db, P7 78ff, P8 0, P9 system.windows.markup.xamlparse, P10 NIL. 有关更多信息,请参阅在 http://go.microsoft.com/fwlink/events.asp 的帮助和支持中心。 数据: 0000: 63 00 6c 00 72 00 32 00 c.l.r.2. 0008: 30 00 72 00 33 00 2c 00 0.r.3.,. 0010: 20 00 72 00 65 00 70 00 .r.e.p. 0018: 61 00 69 00 72 00 70 00 a.i.r.p. 0020: 61 00 72 00 74 00 73 00 a.r.t.s. 0028: 73 00 63 00 72 00 65 00 s.c.r.e. 0030: 65 00 6e 00 2e 00 65 00 e.n...e. 0038: 78 00 65 00 2c 00 20 00 x.e.,. . 0040: 31 00 2e 00 30 00 2e 00 1...0... 0048: 30 00 2e 00 30 00 2c 00 0...0.,. 0050: 20 00 34 00 66 00 63 00 .4.f.c. 0058: 35 00 65 00 36 00 37 00 5.e.6.7. 0060: 31 00 2c 00 20 00 70 00 1.,. .p. 0068: 72 00 65 00 73 00 65 00 r.e.s.e. 0070: 6e 00 74 00 61 00 74 00 n.t.a.t. 0078: 69 00 6f 00 6e 00 66 00 i.o.n.f. 0080: 72 00 61 00 6d 00 65 00 r.a.m.e. 0088: 77 00 6f 00 72 00 6b 00 w.o.r.k. 0090: 2c 00 20 00 34 00 2e 00 ,. .4... 0098: 30 00 2e 00 30 00 2e 00 0...0... 00a0: 30 00 2c 00 20 00 34 00 0.,. .4. 00a8: 62 00 61 00 31 00 66 00 b.a.1.f. 00b0: 38 00 64 00 62 00 2c 00 8.d.b.,. 00b8: 20 00 37 00 38 00 66 00 .7.8.f. 00c0: 66 00 2c 00 20 00 30 00 f.,. .0. 00c8: 2c 00 20 00 73 00 79 00 ,. .s.y. 00d0: 73 00 74 00 65 00 6d 00 s.t.e.m. 00d8: 2e 00 77 00 69 00 6e 00 ..w.i.n. 00e0: 64 00 6f 00 77 00 73 00 d.o.w.s. 00e8: 2e 00 6d 00 61 00 72 00 ..m.a.r. 00f0: 6b 00 75 00 70 00 2e 00 k.u.p... 00f8: 78 00 61 00 6d 00 6c 00 x.a.m.l. 0100: 70 00 61 00 72 00 73 00 p.a.r.s. 0108: 65 00 20 00 4e 00 49 00 e. .N.I. 0110: 4c 00 0d 00 0a 00 L.....
上面的报错信息除了 System.Windows.Markup.XamlParseException 外,基本无用
但可以判断为软件在窗口的Loaded前就挂了,因为没有任何异常被抛出。
找了一上午,终于发现有人有类似的问题:http://social.msdn.microsoft.com/Forums/zh-CN/wpf/thread/cfa1a133-3424-4fc6-b523-7a4cea5f8f3b
也就是说,因为我用了WinXP不支持的256×256大小的ico,造成窗口在初始化时,在读取资源时失败。
对应方法是把ico的大小改为96×96就行了,换句话说,256×256的ICO还是不要用了


I've had this error message appear when running certain WPF applications running XP sp3. The fix in my case was to check the icon (.ico) files being used by any of your windows in your application. It turned out that having a 256 * 256 32bit png image in the icon file used by the application window was causing the problem. Deleting that image, leaving the other icon types solved the problem.