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

时间:2011-11-17 22:39:41

标签: .net wpf gac

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

<ResourceDictionary Source="/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml" />

<Application.Resources>我在调试模式下启动程序时遇到此异常(在发布模式下程序无声地崩溃):

  

类型的第一次机会异常   'System.Windows.Markup.XamlParseException'发生在   PresentationFramework.dll

     

其他信息:'设置属性   '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.

更新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

1 个答案:

答案 0 :(得分: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" />

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