Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using PresentationFramework.Aero, do I need to set "Copy Local" to true (and include it in my setup project)?

Tags:

.net

wpf

gac

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
like image 803
Helge Klein Avatar asked Nov 17 '11 22:11

Helge Klein


1 Answers

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.

like image 53
Helge Klein Avatar answered Oct 31 '22 22:10

Helge Klein