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

标签 .net wpf gac

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

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

<Application.Resources>在 Debug模式下启动程序时出现此异常(在 Release模式下程序静默崩溃):

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: 'Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '14' and line position '14'.



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

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

日期:

正如 Hans Passant 建议的那样,我验证了目录 PresentationFramework.Aero 存在于 C:\windows\microsoft.net\assembly\gac_msil 中。 .然后我使用 fuslogvw.exe 生成以下日志,该日志是在启动我的应用程序“SetACL Studio.exe”时创建的,应用程序目录中不存在 PresentationFramework.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

最佳答案

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

You can also make a dynamic reference to an assembly by providing the calling method with only partial information about the assembly, such as specifying only the assembly name. In this case, only the application directory is searched for the assembly, and no other checking occurs.



这解释了我看到的行为以及为什么没有在 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 文件中添加完整引用,这应该可以。

关于.net - 使用 PresentationFramework.Aero 时,是否需要将 "Copy Local"设置为 true(并将其包含在我的设置项目中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8175410/

相关文章:

.net - 在.net应用程序中播放声音的更好的解决方案是什么:DirectX lib或System.Media.SoundPlayer的音频?

c# - 用于在 CLR 上实现语言的书籍和文献

.net - 我应该使用什么 gacutil.exe?

.net - .NET Word 2003 加载项可以安装在 GAC 之外吗?

dll - 如何在vista中将dll添加到gac

c# - 在 WCF 服务中传递接口(interface)?

c# - GridView 页码间距?

c# - 是否可以让我的 c# wpf 程序知道用户是否有触摸屏?

wpf - 单击某些其他控件时不会引发 TextBox LostFocus

wpf - 我怎样才能使这个自定义扩展器成为非硬编码的高度?