6

I've been using MahApps.Metro from NuGet for a while without any issues. However, recently I had a few issues with NuGet packages needing to be reinstalled.

In the end, I uninstalled all of the NuGet packages I needed and reinstalled them. As far as I can tell, everything works correctly now except that when I try to start the application, it immediately throws the above exception:

System.Windows.Markup.XamlParseException: ''Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '34' and line position '18'.'

Inner Exception
IOException: Cannot locate resource 'styles/colors.xaml'.

And if I check those specified lines, it is this <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />.

My App.xaml looks like this:

<Application.Resources>
    <ResourceDictionary>
        <!-- Some other stuff is here -->
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            <!-- Bunch of other stuff here -->
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

I have tried various things from other similar questions:

  • Changing "Colors" to "Colours"
  • Changing "Colors" to "colors"
  • Changing "Colors to "colours"
  • Restore NuGet packages
  • Uninstalled/reinstalled package
  • Tried x86, x64 and AnyCPU target platforms
  • Endless number of clean/rebuild solution with closing VS2017 inbetween
  • Checked StartupUri is correct
  • Ensured Assembly name and Default namespace are different (and have always been)

I'm completely at a loss as to what try next...

ASh
  • 34,632
  • 9
  • 60
  • 82
WSC
  • 903
  • 10
  • 30

2 Answers2

10

Since you most likely used the latest NuGet package of MahApps.Metro v2.0 you got these errors. As you mentioned we need to follow official Migration to v2.0 guide. Following steps helped me resolve the issue that may help some other readers of this post who are encountering the similar issues:

  1. Remove the tag <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />

  2. Replace tags such as

    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Green.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />`
    

    with

    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Green.xaml" />`
    
  3. In the tag <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" /> remove the word Animated

If there are any other tags raising error, please refer to the above link. I used that link to solve above issues.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
nam
  • 21,967
  • 37
  • 158
  • 332
3

The one thing I hadn't tried was using an older version... And yep version 2.0.0 of MahApps.Metro changed how themes were done. Using version 1.6.5 fixes the issue or you need to follow the migration guide here: https://mahapps.com/docs/guides/migration-to-v2.0

WSC
  • 903
  • 10
  • 30