MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.15k stars 3.43k forks source link

Had Mahapps installed, went to install this and set it up but get "Could not load file or assembly 'MahApps.Metro' now." #1107

Closed MostHated closed 5 years ago

MostHated commented 5 years ago

Hey there, I had Mahapps installed and went to install this and set it up but get "Could not load file or assembly 'MahApps.Metro' now."

System.Windows.Markup.XamlParseException: Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'MahApps.Metro, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Here is what my resources have in it, I also have Caliburn.Micro, not sure if that makes a difference?

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary>
                <local:AppBootstrapper x:Key="bootstrapper" />
            </ResourceDictionary>
            <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/Themes/Light.Blue.xaml" />

            <!-- Material Design -->
            <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.DeepPurple.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />                

            <!-- Material Design: MahApps Compatibility -->
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Flyout.xaml" />

        </ResourceDictionary.MergedDictionaries>

        <SolidColorBrush x:Key="HighlightBrush" Color="{DynamicResource Primary700}"/>
        <SolidColorBrush x:Key="AccentBaseColorBrush" Color="{DynamicResource Primary600}" />
        <SolidColorBrush x:Key="AccentColorBrush" Color="{DynamicResource Primary500}"/>
        <SolidColorBrush x:Key="AccentColorBrush2" Color="{DynamicResource Primary400}"/>
        <SolidColorBrush x:Key="AccentColorBrush3" Color="{DynamicResource Primary300}"/>
        <SolidColorBrush x:Key="AccentColorBrush4" Color="{DynamicResource Primary200}"/>
        <SolidColorBrush x:Key="WindowTitleColorBrush" Color="{DynamicResource Primary700}"/>
        <SolidColorBrush x:Key="AccentSelectedColorBrush" Color="{DynamicResource Primary500Foreground}"/>
        <LinearGradientBrush x:Key="ProgressBrush" EndPoint="0.001,0.5" StartPoint="1.002,0.5">
            <GradientStop Color="{DynamicResource Primary700}" Offset="0"/>
            <GradientStop Color="{DynamicResource Primary300}" Offset="1"/>
        </LinearGradientBrush>
        <SolidColorBrush x:Key="CheckmarkFill" Color="{DynamicResource Primary500}"/>
        <SolidColorBrush x:Key="RightArrowFill" Color="{DynamicResource Primary500}"/>
        <SolidColorBrush x:Key="IdealForegroundColorBrush" Color="{DynamicResource Primary500Foreground}"/>
        <SolidColorBrush x:Key="IdealForegroundDisabledBrush" Color="{DynamicResource Primary500}" Opacity="0.4"/>
        <SolidColorBrush x:Key="MahApps.Metro.Brushes.ToggleSwitchButton.OnSwitchBrush.Win10" Color="{DynamicResource Primary500}" />
        <SolidColorBrush x:Key="MahApps.Metro.Brushes.ToggleSwitchButton.OnSwitchMouseOverBrush.Win10" Color="{DynamicResource Primary400}" />
        <SolidColorBrush x:Key="MahApps.Metro.Brushes.ToggleSwitchButton.ThumbIndicatorCheckedBrush.Win10" Color="{DynamicResource Primary500Foreground}" />

    </ResourceDictionary>

Thanks, -MH

jespersh commented 5 years ago
  1. Check the dll is actually there
  2. Learn to use fuslogvw https://docs.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer
MostHated commented 5 years ago

I appreciate the info. Here is what showed up in that application : https://i.imgur.com/6fo0RKZ.png

Here is an error from Rider and also the /bin/Debug folder in which has the DLL's in them. https://i.imgur.com/IhCfiVJ.png

Here are my packages, each one has the appropriate DLL's in them. https://i.imgur.com/RvR5wNg.png

jespersh commented 5 years ago

I appreciate the info. Here is what showed up in that application : i.imgur.com/6fo0RKZ.png

There appears to be multiple runs in that logsession which confuses me. Click View Log on the lines that a module that failed to load (those lines without Version in the description). It will bring up the additional info that tells you why it failed.

MostHated commented 5 years ago

I am supposed to have the actual Mahapps.Metro nuget as well as the MaterialDesign.Metro one, am I not? Could it be some sort of version mismatch? I think the newest version of Mahapps came out just a few days ago, around the time I installed it. Also, would it make a difference if I originally had only Mahapps installed and was using it, then came across MaterialDesign and installed it and tried to integrate it after the fact? The version of Mahapps I have in here was working fine on it's own, so I would imagine that the actual dll is probably ok, it was not until I added MaterialDesign that I now get this trouble.

Here is what it ways for Mahapps.Metro:

=== Pre-bind state information ===
LOG: DisplayName = MahApps.Metro, PublicKeyToken=null
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: MahApps.Metro, PublicKeyToken=null | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/Home/Desktop/uBackup/uBackup/uBackup/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = uBackup.exe
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Home\Desktop\uBackup\uBackup\uBackup\bin\Debug\uBackup.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Home/Desktop/uBackup/uBackup/uBackup/bin/Debug/MahApps.Metro.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\Home\Desktop\uBackup\uBackup\uBackup\bin\Debug\MahApps.Metro.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: MahApps.Metro, Version=2.0.0.0, Culture=neutral, PublicKeyToken=51482d6f650b2b3f
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Then this is MaterialDesign.Mahapps.Metro which it, as well as Design.Colors, and Design.WPF do not have version numbers, I am guessing though that it might be because they are not the "main" module? If that is the case then this below is not necessary, as it looks like it's showing success unlike the one above.

    === Pre-bind state information ===
LOG: DisplayName = MaterialDesignThemes.MahApps, Culture=neutral
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: MaterialDesignThemes.MahApps, Culture=neutral | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/Home/Desktop/uBackup/uBackup/uBackup/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = uBackup.exe
Calling assembly : PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Home\Desktop\uBackup\uBackup\uBackup\bin\Debug\uBackup.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Home/Desktop/uBackup/uBackup/uBackup/bin/Debug/MaterialDesignThemes.MahApps.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\Home\Desktop\uBackup\uBackup\uBackup\bin\Debug\MaterialDesignThemes.MahApps.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: MaterialDesignThemes.MahApps, Version=0.0.10.0, Culture=neutral, PublicKeyToken=null
LOG: A partially-specified assembly bind succeeded from the application directory. Need to re-apply policy.
LOG: Using application configuration file: C:\Users\Home\Desktop\uBackup\uBackup\uBackup\bin\Debug\uBackup.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Binding succeeds. Returns assembly from C:\Users\Home\Desktop\uBackup\uBackup\uBackup\bin\Debug\MaterialDesignThemes.MahApps.dll.
LOG: Assembly is loaded in default load context.
jespersh commented 5 years ago

I suspect you need to downgrade MahApps.Metro to 1.6.5 unless you create a binding redirect on the version, which I thought nuget would have done for you.

Note: 2.0.0.0 referenced is an alpha build. Beware of upgrading packages beyond support

MostHated commented 5 years ago

I appreciate it. I downgraded Mahapps as well as the ControlzEx as it threw an error as well after I did that. Now it seems to be working ok.