29

我最近完成了我使用 Windows 8 开发的第一个 WPF 应用程序。它在我的机器上运行良好。我的一个朋友也在他的 Windows 8 机器上的 Visual Studio 中运行它,并且成功了。我在我的机器上使用 click 一次安装程序,它可以正常安装并运行。

我在虚拟盒子上安装了 Windows 7,并尝试使用单击安装它。它获取 .NET 4.5 和 SQL Server Compact,安装过程似乎完美无缺。当 Windows 7 尝试运行该应用程序时,没有发生任何有用的事情。我在 virtualbox 中安装了 Visual Studio,并且能够获得这个堆栈跟踪。

我在 Google 上查找了 PresentationFramework.Aero2,遇到了 3 个 SO 问题和一个 MSDN 问题。MSDN 问题给了我一个暗示,我认为它可能是什么。如果我去 C:\Windows\Microsoft.NET\Framework\4.0\WPF 没有 PresentationFramework.Aero2.dll 文件,而在 Windows 8 上有...所以我将它复制并粘贴到 Windows 7 等效的地方希望实现某事,但一无所获。

这是堆栈跟踪:

System.Windows.Markup.XamlParseException was unhandled
  HResult=-2146233087
  Message='Add value to collection of type 'System.Collections.ObjectModel.ObservableCollection(System.Windows.Controls.DataGridColumn)' threw an exception.' Line number '35' and line position '71'.
  Source=PresentationFramework
  LineNumber=35
  LinePosition=71
  StackTrace:
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
       at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
       at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
       at System.Windows.Application.DoStartup()
       at System.Windows.Application.<.ctor>b__1(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at PremierAutoDataExtractor.App.Main()
  InnerException: System.IO.FileNotFoundException
       HResult=-2147024894
       Message=Could not load file or assembly 'PresentationFramework.Aero2, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
       Source=mscorlib
       FileName=PresentationFramework.Aero2, PublicKeyToken=31bf3856ad364e35
       FusionLog=WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

       StackTrace:
            at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
            at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
            at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
            at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
            at System.Windows.Baml2006.Baml2006SchemaContext.ResolveAssembly(BamlAssembly bamlAssembly)
            at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlTypeToType(BamlType bamlType)
            at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(BamlType bamlType, Int16 typeId)
            at System.Windows.Baml2006.Baml2006SchemaContext.GetXamlType(Int16 typeId)
            at System.Windows.Baml2006.Baml2006Reader.Process_ElementStart()
            at System.Windows.Baml2006.Baml2006Reader.Process_OneBamlRecord()
            at System.Windows.Baml2006.Baml2006Reader.ReadObject(KeyRecord record)
            at System.Windows.ResourceDictionary.CreateObject(KeyRecord key)
            at System.Windows.ResourceDictionary.OnGettingValue(Object key, Object& value, Boolean& canCache)
            at System.Windows.ResourceDictionary.OnGettingValuePrivate(Object key, Object& value, Boolean& canCache)
            at System.Windows.ResourceDictionary.GetValueWithoutLock(Object key, Boolean& canCache)
            at System.Windows.ResourceDictionary.GetValue(Object key, Boolean& canCache)
            at System.Windows.DeferredResourceReference.GetValue(BaseValueSourceInternal valueSource)
            at System.Windows.DeferredAppResourceReference.GetValue(BaseValueSourceInternal valueSource)
            at System.Windows.DependencyObject.GetEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, RequestFlags requests)
            at System.Windows.DependencyObject.GetValueEntry(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, RequestFlags requests)
            at System.Windows.DependencyObject.GetValue(DependencyProperty dp)
            at System.Windows.Controls.DataGridHelper.GetCoercedTransferPropertyValue(DependencyObject baseObject, Object baseValue, DependencyProperty baseProperty, DependencyObject parentObject, DependencyProperty parentProperty, DependencyObject grandParentObject, DependencyProperty grandParentProperty)
            at System.Windows.Controls.DataGridColumn.OnCoerceHeaderStyle(DependencyObject d, Object baseValue)
            at System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, Boolean skipBaseValueChecks)
            at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
            at System.Windows.DependencyObject.CoerceValue(DependencyProperty dp)
            at System.Windows.Controls.DataGridHelper.TransferProperty(DependencyObject d, DependencyProperty p)
            at System.Windows.Controls.DataGridColumn.SyncProperties()
            at System.Windows.Controls.DataGrid.UpdateColumnSizeConstraints(IList list)
            at System.Windows.Controls.DataGrid.OnColumnsChanged(Object sender, NotifyCollectionChangedEventArgs e)
            at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
            at System.Windows.Controls.DataGridColumnCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
            at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
            at System.Windows.Controls.DataGridColumnCollection.InsertItem(Int32 index, DataGridColumn item)
            at System.Collections.ObjectModel.Collection`1.Add(T item)
            at System.Collections.ObjectModel.Collection`1.System.Collections.IList.Add(Object value)
            at System.Xaml.Schema.XamlTypeInvoker.AddToCollection(Object instance, Object item)
            at MS.Internal.Xaml.Runtime.ClrObjectRuntime.Add(Object collection, XamlType collectionType, Object value, XamlType valueXamlType)
       InnerException: 
4

2 回答 2

42

我遇到了类似的问题。背景:使用 Visual Studio 2012、Blend for 2012、.NET 4.5 在 Windows 8 上开发 WPF 应用程序。APP.XAML 为主题引用了 PresentationFramework.Aero2。使用 ClickOnce 分发应用程序。

在 Windows 8 上,没有问题。在 Windows XP/Vista/7 上,应用程序会在执行的部分过程中崩溃(在引用 Aero2 的第一个子页面上),并记录上述“无法加载程序集”异常。

尝试修复:标记 Aero2 以在项目中复制本地(没有帮助),尝试包含在 ClickOnce 安装程序中(未出现在可用程序集列表中),复制到目标 Windows7 机器上 c:\windows\microsoft.net 下的 WPF 文件夹\framework\v4.xx\wpf (没有帮助)。

解析度:

将项目中的引用从 PresentationFramework.Aero2 替换为 PresentationFramework.Aero,然后修改 XAML 引用以匹配。可以轻松推送到非 Windows 8 机器并让它运行。开发工作正常。唯一发现的区别是进度条的默认外观是光泽/3d。

于 2013-07-05T17:58:29.703 回答
1

在开发人员机器上,有两个版本的表示框架程序集。Visual Studio 引用“仅元数据”版本。当您部署 C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF 文件夹的程序集时,它应该可以工作(请参阅程序集 PresentationFramework.Aero2 的问题

于 2018-02-26T08:57:50.193 回答