1

In my WPF application, I'm trying to load a Resource Dictionary from an external assembly.

It's underlined in the designer with a message "An error occured while locating ..." (my message is in french, so not sure about the exact english version).

Here is what I have in my App.xaml :

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MYNAMESPACE;component/Themes/MYFILE.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MYNAMESPACE;component/Styles/MYFILE.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

The two lines that are with MYNAMESPACE get underlined with the messages. I left the Mahapps ones because they work fine and don't get underlined. I redacted the names because they're related to my company.

I found some stuff here saying that the xaml build action should be "Resource" (here), but someone is saying this can cause problems. The xaml files in Mahapps are "Page" (mine too) and work just fine.

My assembly is a project of type "User Control Library".

Mickael V.
  • 1,109
  • 11
  • 21

1 Answers1

2

I remember struggling with this same issue. I can't remember what exactly solved my problem, but here is the way I set it up.

The Build Action of the resource dictionaries (xaml) is set to Page. So I'm quite certain that your assumption was correct.

The project containing the external resource dictionaries is part of the same solution I'm working in. So I reference to the dictionaries as followed:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/MY.NAMESPACE;component/MyExternalDictionary.xaml" />
            <ResourceDictionary Source="/MY.NAMESPACE;component/MYFILE.xaml" />
            <ResourceDictionary Source="MyInternalDictionary.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

This seems to work for me now, but I can't remember if this was all I did to solve it.
So if this still doesn't work it could also be caused by a missing reference. If one of your external resource dictionaries references something, this might have to be added to your current project as well.

Oceans
  • 3,445
  • 2
  • 17
  • 38
  • I wrote it like you, without the "pack..." and also switched between DEBUG and RELEASE and for some reason it fixed it. I had restarted my project before (without fixing it) so I have no idea what happened ! – Mickael V. Jun 01 '17 at 20:21