2013-06-27 119 views
19

我最近完成了我使用Windows 8開發的第一個WPF應用程序。它在我的機器上運行良好。我的一位朋友也在他的Windows 8機器上的視覺工作室中運行它,並且工作正常。我在我的機器上點擊一次安裝程序,安裝正常並運行。爲什麼Windows 7無法加載AssemblyFramework.Aero2?

我在虛擬盒子上安裝了Windows 7,並嘗試使用點擊一次來安裝它。它提取了.NET 4.5和SQL Server Compact,安裝過程看起來完美無瑕。當Windows 7試圖運行該應用程序時,沒有發生任何有用的事情。我在virtualbox中安裝了Visual Studio,並能夠獲取此堆棧跟蹤。

我在Google上查找了PresentationFramework.Aero2,並遇到了3個SO問題和1個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: 

回答

28

我遇到了類似的問題。上下文:在Windows 8上使用Visual Studio 2012,Blend for 2012,.NET 4.5開發WPF應用程序。 APP.XAML爲主題引用了PresentationFramework.Aero2。使用ClickOnce分發應用程序。

在Windows 8上,沒有問題。在Windows XP/Vista/7上,應用程序會在上面記錄的「無法加載程序集」異常的情況下部分執行(在引用Aero2的第一個子頁面上)。

嘗試修復:標記Aero2在項目中複製本地(沒有幫助),試圖包含在ClickOnce安裝程序中(未出現在可用程序集列表中),複製到c:\ windows下目標Windows7計算機上的WPF文件夾中\ microsoft.net \ framework \ v4.xx \ wpf(沒有幫助)。

分辨率:

替換項目從PresentationFramework.Aero2到PresentationFramework.Aero引用,然後修改XAML引用相匹配。可以隨時推送到非Windows 8的機器並運行。開發工作正常。唯一的區別是進度條的默認外觀是光澤/ 3d。

+0

哦,這也稱爲向後兼容性?我不知道這個! –

+1

@PaulVilevac,你是什麼意思「替換引用...到PresentationFramework.Aero」?你究竟如何「替換」?您是否使用過.Aero,或者您的解決方案是否保留了非Windows8設備上的Aero2樣式? –

+9

對於其他人感到困惑的是,您只需從項目中移除'PresentationFramework.Aero2'引用並添加'PresentationFramework.Aero'引用。此外,您還需要在所有名稱空間導入中將** Aero2 **更改爲** Aero **;例如'的xmlns:主題= 「CLR-名稱空間:Microsoft.Windows.Themes;裝配= PresentationFramework.Aero」'。事情已經爲我解決了。 – dotNET

0

在開發人員機器上,有兩種版本的表示框架程序集。 Visual Studio引用「僅限元數據」版本。當您部署C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ WPF文件夾的程序集時,它應該可以工作(請參閱Problem with assembly PresentationFramework.Aero2