Search code examples
c#wpfxamlresourcedictionary

How to load a ResourceDictionary from a strong names assembly?


I have project that references 2 dlls. if the referenced dlls are not strong named the resources load fine and my user controls work. The problem is I had to strong name the referenced DLLs and now my user controls give me a XamlParseException System.Windows.Markup.StaticResourceHolder with an inner of "Could not load file or assembly". I'm guessing the static resource in the app.xaml could not be found or loaded so it thinks the assembly is not loaded. Is there a way around this?

App.Xaml...

 <Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Grey.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Red.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

App.xaml.cs...

 public partial class App
{
    protected override void OnStartup(StartupEventArgs e)
    {
        // referenced to MaterialDesignThemes.Wpf
        MaterialDesignThemes.Wpf.DialogHost d = new MaterialDesignThemes.Wpf.DialogHost();
        var b = d.IsOpen;

        base.OnStartup(e);
        var app = new MainWindow();
        var context = new MainWindowVM();
        app.DataContext = context;
        app.Show();
    }
}

Solution

  • You could enable fusion logging and get a hint from this log file. How to enable assembly bind failure logging (Fusion) in .NET