当使用presentationFramework.Aero,做我需要设置"复制本地"真(并将其包括在我的安装项目)?我的、项目、并将其、presentationFramework

2023-09-04 22:35:25 作者:比棉花糖还甜

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

 < ResourceDictionary中源=/ presentationFramework.Aero;组件/主题/ Aero.NormalColor.xaml/>
 

< Application.Resources> 我在调试模式下启动程序时出现此异常(在释放模式程序默默地崩溃):

  

有一个第一次机会异常类型   System.Windows.Markup.XamlParseException发生在   presentationFramework.dll

     

更多信息:设置属性   System.Windows.ResourceDictionary.Source抛出异常。线   数字14和线位置'14'。

WPF 渲染原理

当我设置了presentationFramework.Aero到真正的财产复制本地,一切​​正常和异常消失了。

复制本地则以presentationFramework.Aero副本在我的输出目录,因此我需要把它列入我的安装项目。 为什么有此必要?根据 MSDN presentationFramework。航空包括在.NET Framework 4.0客户端配置文件,因此在GAC。我感觉不舒服部署我的应用程序的框架文件。

UDATE:

由于汉斯帕桑特建议我证实,该目录presentationFramework.Aero存在于 C:\ WINDOWS \ microsoft.net \组装\ GAC_MSIL 。然后,我开始我的应用程序SETACL Studio.exe没有presentationFramework.Aero.dll是present应用程序目录时使用fuslogvw.exe生成以下日志,创建的。有趣的是,装载机的甚至不检查GAC 。为什么呢?

  ***大会粘结剂日志条目(18.11.2011 @ 17时13分27秒)***

操作失败。
绑定结果:HR = 0x80070002。该系统找不到指定的文件。

C:从装配​​经理装\的Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ clr.dll
根据可执行ð运行:\名单Daten \黑尔格\ Programmierung \ SETACL工作室\来源\斌\调试\ SETACL Studio.exe
---详细的错误日志如下。

=== pre-绑定状态信息===
日志:用户= HKT520 \黑尔格
日志:显示名称= presentationFramework.Aero,文化=中性
 (部分)
警告:部分绑定信息是提供程序集:
警告:程序集名称:presentationFramework.Aero,文化=中性|域ID:1
警告:程序集显示名称的一部分提供时,会出现局部绑定。
警告:这可能导致粘合剂加载了不正确的装配。
警告:建议提供了一个完全指定的文字标识的组装,
警告:即由简单的名称,版本,区域性和公钥令牌。
警告:请参阅白皮书http://go.microsoft.com/fwlink/?LinkId=109270了解更多信息,共同解决这一问题。
日志:应用平台=文件:/// D:/名单Daten /黑尔格/ Programmierung / SETACL工作室/来源/斌/调试/
LOG:初始PrivatePath = NULL
日志:动基座= NULL
日志:缓存基地= NULL
LOG:AppName的= SETACL Studio.exe
调用汇编:presentationCore,版本= 4.0.0.0,文化=中性公钥= 31bf3856ad364e35。
===
日志:此绑定从default加载上下文。
日志:正在使用应用程序配置文件:D:\名单Daten \黑尔格\ Programmierung \ SETACL工作室\来源\斌\调试\ SETACL Studio.exe.Config
日志:使用主机配置文件:
日志:从C使用计算机配置文件:\ WINDOWS \ Microsoft.NET \ Framework64 \ v4.0.30319 \ CONFIG \ machine.config中。
日志:政策不被应用到引用在这个时候(私人,自定义,局部的,或基于位置的程序集绑定)。
日志:新的URL文件试图下载:/// D:/名单Daten /黑尔格/ Programmierung / SETACL工作室/来源/斌/调试/ presentationFramework.Aero.DLL。
日志:新的URL文件试图下载:/// D:/名单Daten /黑尔格/ Programmierung / SETACL工作室/来源/斌/调试/ presentationFramework.Aero / presentationFramework.Aero.DLL。
日志:新的URL文件试图下载:/// D:/名单Daten /黑尔格/ Programmierung / SETACL工作室/来源/斌/调试/ presentationFramework.Aero.EXE。
日志:新的URL文件试图下载:/// D:/名单Daten /黑尔格/ Programmierung / SETACL工作室/来源/斌/调试/ presentationFramework.Aero / presentationFramework.Aero.EXE。
日志:所有探测网址企图失败了。
 

更新2:

这是从GACUTIL输出:

  C:\ Program Files文件\微软的SDK \的Windows \ V7.1 \ BIN>的Gacutil.exe / L presentationframework.aero
微软(R).NET全局程序集缓存工具。版本3.5.30729.1
版权所有(c)Microsoft公司。版权所有。

全局程序集缓存包含以下组件:
  presentationframework.aero,版本= 3.0.0.0,文化=中性公钥= 31bf3856ad364e35,的ProcessorArchitecture = MSIL

项目数= 1
 

解决方案

我刚刚发现下面的 MSDN :

  

您还可以通过提供使动态引用程序集   调用方法与有关装配体中只有部分信息,例如   作为唯一指定的程序集名称。在这种情况下,只有   搜索应用程序目录的组装,并没有其他的   检查发生。

这说明了其行为,我看到的,为什么海关总署并没有搜索到了presentationFramework.aero.dll。我改变了动态参考,以一个完整的参考和presentationFramework.aero删除复制本地。现在的工作,而不需要在我的应用程序目录presentationFramework.aero.dll。

作为参考,在这里是工作的资源字典code:

 <的ResourceDictionary Source="/$p$psentationFramework.Aero,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL;component/themes/Aero.NormalColor.xaml" />
 

总之,删除你的主题的本地副本(在您添加在您的解决方案的情况下),加上充分借鉴下Application.Resources(资源词典)App.xaml文件,这应该做的。

My WPF project uses .NET 4 client profile. When I add

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

to <Application.Resources> I get this exception when starting the program in debug mode (in release mode the program silently crashes):

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'.

When I set the property "Copy Local" of PresentationFramework.Aero to true, everything works and the exception is gone.

"Copy Local" places a copy of PresentationFramework.Aero in my output directory and I therefore need to include it in my setup project. Why is that necessary? According to MSDN PresentationFramework.aero is included in the .NET framework 4.0 client profile and therefore in the GAC. I do not feel comfortable deploying a framework file with my application.

Udate:

As Hans Passant suggested I verified that the directory PresentationFramework.Aero exists in C:\windows\microsoft.net\assembly\gac_msil. Then I used fuslogvw.exe to generate the following log, created when starting my application "SetACL Studio.exe" without PresentationFramework.Aero.dll being present in the application directory. Interestingly, the loader does not even check the GAC. Why?

*** 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.

Update 2:

This is the output from 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

解决方案

I just found the following on 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.

That explains the behavior I was seeing and why the GAC was not searched for PresentationFramework.aero.dll. I changed the dynamic reference to a full reference and removed "Copy Local" from PresentationFramework.aero. It now works without needing PresentationFramework.aero.dll in my application directory.

For reference, here is the working resource dictionary code:

<ResourceDictionary Source="/PresentationFramework.Aero,Version=3.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL;component/themes/Aero.NormalColor.xaml" />

In short, delete the local copy of your themes(in case you have added in your solution), add the full reference in the App.xaml file under Application.Resources (Resource Dictionary) and this should do.

 
精彩推荐
图片推荐