2011-11-17 5 views
10

Dự án WPF của tôi sử dụng hồ sơ khách hàng .NET 4. Khi tôi thêmKhi sử dụng PresentationFramework.Aero, tôi có cần đặt "Sao chép Địa phương" thành true (và bao gồm nó trong dự án thiết lập của tôi) không?

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

để <Application.Resources> tôi nhận được ngoại lệ này khi bắt đầu chương trình trong chế độ gỡ lỗi (trong chế độ phát hành các chương trình âm thầm treo):

Một ngoại lệ cơ hội đầu tiên của loại 'System.Windows .Markup.XamlParseException 'xảy ra trong PresentationFramework.dll

Thông tin bổ sung:' Đặt thuộc tính 'System.Windows.ResourceDictionary.Source' đã ném một ngoại lệ. ' Dòng số '14' và vị trí dòng '14'.

Khi tôi đặt thuộc tính "Sao chép cục bộ" của PresentationFramework.Aero thành true, mọi thứ hoạt động và ngoại lệ sẽ biến mất.

"Sao chép địa phương" đặt một bản sao của PresentationFramework.Aero trong thư mục đầu ra của tôi và do đó tôi cần đưa nó vào dự án thiết lập của tôi. Tại sao điều đó lại cần thiết? Theo MSDN PresentationFramework.aero được bao gồm trong lược tả máy khách .NET framework 4.0 và do đó trong GAC. Tôi không cảm thấy thoải mái khi triển khai một tệp khung công tác với ứng dụng của tôi.

Udate:

Như Hans passant đề nghị tôi xác nhận rằng thư mục PresentationFramework.Aero tồn tại trong C:\windows\microsoft.net\assembly\gac_msil. Sau đó, tôi đã sử dụng fuslogvw.exe để tạo nhật ký sau, được tạo khi khởi động ứng dụng "SetACL Studio.exe" mà không có PresentationFramework.Aero.dll trong thư mục ứng dụng. Điều thú vị là, bộ nạp thậm chí không kiểm tra GAC ​​. Tại sao?

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

Cập nhật 2:

Đây là sản phẩm từ 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

Kiểm tra GAC. Điều hướng đến c: \ windows \ microsoft.net \ assembly \ gac_msil và kiểm tra lại xem thư mục PresentationFramework.Aero có ở đó không. Fuslogvw.exe để được trợ giúp khắc phục sự cố thêm. –

+0

@HansPassant: Cảm ơn, tôi đã xác minh rằng thư mục tồn tại - nó có và chứa DLL. Tôi đã thêm nhật ký fuslogvw vào câu hỏi của mình. –

+0

@ HansPassant: Nhận xét của bạn đã dẫn tôi đến con đường dẫn đến giải pháp. Cảm ơn bạn! –

Trả lời

31

Tôi chỉ tìm thấy sau đây trên MSDN:

Bạn cũng có thể tạo ra một năng động tham chiếu đến hội đồng bằng cách cung cấp số gọi ethod chỉ với một phần thông tin về lắp ráp, chẳng hạn như chỉ định tên lắp ráp. Trong trường hợp này, chỉ có thư mục ứng dụng được tìm kiếm để lắp ráp và không xảy ra việc kiểm tra nào khác.

Điều đó giải thích hành vi tôi đã thấy và lý do GAC không được tìm kiếm PresentationFramework.aero.dll. Tôi đã thay đổi tham chiếu động thành tham chiếu đầy đủ và xóa "Sao chép địa phương" từ PresentationFramework.aero. Nó bây giờ hoạt động mà không cần PresentationFramework.aero.dll trong thư mục ứng dụng của tôi.

Để tham khảo, đây là đoạn code từ điển tài nguyên làm việc:

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

Nói tóm lại, xóa các bản sao cục bộ của chủ đề của bạn (trong trường hợp bạn đã thêm vào trong giải pháp của bạn), thêm các tài liệu tham khảo đầy đủ trong App .xaml tệp dưới Application.Resources (Resource Dictionary) và điều này nên làm.

+2

+1 Để liên kết tài liệu MSDN và mã nguồn tài nguyên làm việc. – aolszowka