0

I have 2 projects under the same solution in VS2010. P1 references P2 as a project.

P1 contains a UserControl from P2 and this UserControl references many dictionaries and converters from P2 itself. Separately, these 2 projects runs well without issues.

The problem is when P1 calls the UserControl from P2, an exception pops out stating that it cannot find the resource key which is needed for the UserControl.

Can someone point me in the right direction?

EDIT:

This is the referencing (I had stripped all non-relevant data):

Referencing

This is P1's App.xaml:

<Application x:Class="P1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml" >

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Dictionaries/TabControlDictionary.xaml"/>
            <ResourceDictionary Source="/Dictionaries/ButtonDictionary.xaml"/>                
            and so on....
</Close Everything>

This is P2's App.xaml:

<Application x:Class="P2.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml" >

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Dictionaries/ListBox1Dictionary.xaml"/>
            <ResourceDictionary Source="/Dictionaries/ListBox2Dictionary.xaml"/>                          
            and so on....
</Close Everything>

And this is where P1 creates the UserControl:

<Window xmlns:p2="clr-namespace:P2;assembly=P2"
        and other stuff >
    <Grid>
        <p2:myUserControl />
    </Close Everything>

Which threw an exception during runtime saying it can't find resource keys. I should also point out that P1 and P2 are in completely different folder and drives on the HDD.

Darren Ng
  • 373
  • 1
  • 5
  • 20
  • Post the relevant xaml. It's hard to determine where your error is – Mark Aug 21 '14 at 12:43
  • Hi @Mark I have added more information.Thanks for helping! – Darren Ng Aug 21 '14 at 16:32
  • 1
    I'm kinda new to WPF as well, but I have a feeling that if you create something in the App.xaml of a project, it exists only if you launch this application. Hence the error: you launch P1 but not P2, because P2 is just referenced. BUT I may be completely mistaken. EDIT: [this may be related](http://stackoverflow.com/questions/338056/resourcedictionary-in-a-separate-assembly) – Kilazur Aug 21 '14 at 16:37
  • 1
    I think you have a problem with the pack uris could you please edit them to `pack://application:,,,/P2;component/Dictionaries/ListBox1Dictionary.xaml` P2 according to your assembly name – Mark Aug 22 '14 at 06:17

0 Answers0