简体   繁体   中英

“Could not load file or assembly” Exception when using a Wpf Custom Control in C#

I'm trying to create and use a WPF Custom Control within a WPF Window. The Window is defined in a Class Library Project and used in an Office Word AddIn Project, while the Custom Control is defined in a Wpf Custom Control Library Project.

There aren't any errors before the project is started, the corresponding classes are also suggested by code completion.

The actual problem occurs in the Constructor of the Wpf Window, where the InitializeComponent() method throws an Exception with the following information:

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

Additional information: Could not load file or assembly 'WpfCustomControlLibrary, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."

This behaviour occurs regardless of the content of the mentioned classes, I have tried this with the most basic code possible. I also tried to create the Wpf Window right in the AddIn Project, using just the Wpf Custom Control Library Project (no separate Class Library). Although this scenario works just fine, I would very much appreciate to keep the separate Class Library for structural purposes.

Any help is highly appreciated, if further information is needed just let me know.

Kind regards

您是否尝试使用以下语法指定定义自定义控件的程序集:

 xmlns:export="clr-namespace:your.custom.control.namespace;assembly=your.assembly.name"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM