Dependent DLLs are not copied if referenced only from XAML

September 19, 2014

no comments

I got a nasty exception in my project:

A first chance exception of type ‘System.Windows.Markup.XamlParseException’ occurred in PresentationFramework.dll

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

To illusatrate, this how my solution looked like:

image

I have a control library that uses another control library (doesn’t matter if in the same solution or from 3rd party).
MyControlLibrary reference a control from the AThirdParty dll only in one of its user-controls xaml:

<Grid>
    <aThirdParty:ThirdPartyControl/>
</Grid>

MyWPFApplication used the user-control from MyControlLibrary inside its first window.

When the application loads the window, it throws the exception. looking inside the output directory will reveal that the AThirdParty.dll wasn’t copied.

It turns out that if the only reference to a dll is from something inside xaml, the dll wont get copied as a dependency.

How to fix

the easiest way to fix is simly giving a name the control that uses the third party control

<Grid>
    <aThirdParty:ThirdPartyControl x:Name="innerControl"/>
</Grid>
Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*