MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

FileNotFoundException: Could not load file or assembly 'MaterialDesignThemes.MahApps

Open Razique opened this issue 2 years ago • 1 comments

Bug explanation

Hi, I am trying to integrate one of the MahApps controls with a WFP application. The control is a simple range slider.

I have followed the steps described in the MahApps Metro Integration guide to deploy the library.

I have installed the following NuGet packages:

  • ControlzEX version 4.3.0
  • MahApps.Metro version 2.0.0
  • MaterialDesignThemes.MahApps version 0.2.5

After installing the packages, I have added a new Metro namespace as follows:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls"
        xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz"
        ...

I have then extended my resources dictionary as follows:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Indigo.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Green.xaml" />

    <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Green.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
</ResourceDictionary.MergedDictionaries>

Finally, I created a simple range slider as follows:

<metro:RangeSlider Width="200"
                   Margin="4"
                   metro:SliderHelper.ChangeValueBy="LargeChange"
                   metro:SliderHelper.EnableMouseWheel="MouseHover"
                   AutoToolTipPlacement="TopLeft"
                   LargeChange="10"
                   LowerValue="40"
                   Maximum="100"
                   Minimum="0"
                   Orientation="Horizontal"
                   SmallChange="1"
                   Style="{DynamicResource MahApps.Styles.RangeSlider.Win10}"
                   UpperValue="60">
    <metro:RangeSlider.AutoToolTipRangeValuesTemplate>
        <DataTemplate DataType="mah:RangeSliderAutoTooltipValues">
            <UniformGrid Columns="2" Rows="2">
                <TextBlock HorizontalAlignment="Right" Text="From:" />
                <TextBlock HorizontalAlignment="Right" Text="{Binding LowerValue, StringFormat='{}{0:N2}'}" />
                <TextBlock HorizontalAlignment="Right" Text="To:" />
                <TextBlock HorizontalAlignment="Right" Text="{Binding UpperValue, StringFormat='{}{0:N2}'}" />
            </UniformGrid>
        </DataTemplate>
    </metro:RangeSlider.AutoToolTipRangeValuesTemplate>
</metro:RangeSlider>

The project builds and I can run my application. The slider works as expected -- I can interact with it: Screenshot 2022-10-31 at 22 28 45

However, after a couple of minutes, or sometimes when running a different debugging session, the program throws the following exception:

System.Windows.Markup.XamlParseException: ''Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '134' and line position '45'.'

FileNotFoundException: Could not load file or assembly 'MaterialDesignThemes.MahApps, PublicKeyToken=df2a72020bd7962a' or one of its dependencies. The system cannot find the file specified.
Screenshot 2022-10-31 at 21 57 26

This exception seems to indicate that my application cannot locate the MaApps assembly, which is confusing given that the slider works sometimes and sometimes the application crashes while there are no changes in the library or configuration.

thanks for your help!

Version

4.6.1

Razique avatar Nov 01 '22 05:11 Razique

It seems like the library is trying to load a style which is not present in the used library. I'm thinking this could be a reference to an older version of Material Design In XAML referenced in the MaterialDesignThemes.MahApps assembly or one of it's dependencies. It could also by an unknown DynamicResource or StaticResource. It's hard to say if you can't provide a test repository so we can observe the bug.\

MichelMichels avatar Nov 10 '22 06:11 MichelMichels

Closed due to staleness

MichelMichels avatar Apr 01 '24 20:04 MichelMichels