6
votes

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

1
Can you confirm, that the requested library is included in the output folder, when you run the application? - Herdo
Yes, the output folder of the Class Library project does contain the needed .dll (WpfCustomControlLibrary.dll). - Wbes
There are known issues with this, for a dirty solution, add the WpfCustomControlLibrary.dll to executable output folder, maybe someone will come up with detailed explanation, basically there is a problem with locating the resources for custom control. - Novitchi S
@Novitchi S So what you are saying is that this is a confirmed bug? Either way, thanks a lot, this actually solved the problem! What I did exactly was adding the reference of the CustomControlLibrary to the AddIn project. - Wbes

1 Answers

1
votes

Did you try to specify the assembly where your custom control is defined using the following syntax:

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