使用PresentationFramework.Aero时,是否需要将"Copy Local"设置为true(并将其包含在我的安装项目中)?

Hel*_*ein 11 .net wpf gac

我的WPF项目使用.NET 4客户端配置文件.当我添加

<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />
Run Code Online (Sandbox Code Playgroud)

<Application.Resources>在调试模式下启动程序,当我得到这个异常(在释放模式程序崩溃默默)

PresentationFramework.dll中出现'System.Windows.Markup.XamlParseException'类型的第一次机会异常

附加信息:'Set property'System.Windows.ResourceDictionary.Source'引发了一个异常.行号'14'和行位置'14'.

当我将PresentationFramework.Aero的属性"Copy Local"设置为true时,一切正常,异常就消失了.

"Copy Local"会在我的输出目录中放置PresentationFramework.Aero的副本,因此我需要将它包含在我的安装项目中.为什么这有必要?根据MSDN PresentationFramework.aero包含在.NET framework 4.0客户端配置文件中,因此也包含在GAC中.我觉得在我的应用程序中部署框架文件感觉不舒服.

UDATE:

正如Hans Passant建议我验证目录PresentationFramework.Aero存在于C:\windows\microsoft.net\assembly\gac_msil.然后我使用fuslogvw.exe生成以下日志,在启动我的应用程序"SetACL Studio.exe"时创建,而ApplicationFramework.Aero.dll不在应用程序目录中.有趣的是,加载器甚至没有检查GAC.为什么?

*** Assembly Binder Log Entry  (18.11.2011 @ 17:13:27) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  D:\Daten\Helge\Programmierung\SetACL Studio\Source\Bin\Debug\SetACL Studio.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = HKT520\Helge
LOG: DisplayName = PresentationFramework.Aero, Culture=neutral
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: PresentationFramework.Aero, Culture=neutral | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///D:/Daten/Helge/Programmierung/SetACL Studio/Source/Bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = SetACL Studio.exe
Calling assembly : PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Daten\Helge\Programmierung\SetACL Studio\Source\Bin\Debug\SetACL Studio.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///D:/Daten/Helge/Programmierung/SetACL Studio/Source/Bin/Debug/PresentationFramework.Aero.DLL.
LOG: Attempting download of new URL file:///D:/Daten/Helge/Programmierung/SetACL Studio/Source/Bin/Debug/PresentationFramework.Aero/PresentationFramework.Aero.DLL.
LOG: Attempting download of new URL file:///D:/Daten/Helge/Programmierung/SetACL Studio/Source/Bin/Debug/PresentationFramework.Aero.EXE.
LOG: Attempting download of new URL file:///D:/Daten/Helge/Programmierung/SetACL Studio/Source/Bin/Debug/PresentationFramework.Aero/PresentationFramework.Aero.EXE.
LOG: All probing URLs attempted and failed.
Run Code Online (Sandbox Code Playgroud)

更新2:

这是gacutil的输出:

C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin>gacutil.exe /l presentationframework.aero
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:
  presentationframework.aero, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL

Number of items = 1
Run Code Online (Sandbox Code Playgroud)

Hel*_*ein 33

我刚刚在MSDN上找到以下内容:

您还可以通过为调用方法提供有关程序集的部分信息(例如仅指定程序集名称)来对程序集进行动态引用.在这种情况下,仅搜索应用程序目录以查找程序集,并且不会进行其他检查.

这解释了我看到的行为以及为什么GAC没有搜索PresentationFramework.aero.dll.我将动态引用更改为完整引用,并从PresentationFramework.aero中删除了"Copy Local".它现在无需在我的应用程序目录中使用PresentationFramework.aero.dll.

供参考,这是工作资源字典代码:

<ResourceDictionary Source="/PresentationFramework.Aero,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL;component/themes/Aero.NormalColor.xaml" />
Run Code Online (Sandbox Code Playgroud)

简而言之,删除主题的本地副本(如果已在解决方案中添加),请在Application.Resources(资源字典)下的App.xaml文件中添加完整引用,这应该可以.

  • +1用于链接MSDN文档和工作资源代码. (2认同)