0

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();
    }
}
  • This should work fine. Can you please show how you reference the ResourceDictionary? – Klaus Gütter Nov 25 '18 at 15:26
  • edited OP... could it be the project is .Net 4.6.1? –  Nov 25 '18 at 15:31
  • Could you try to instantiate any type defined in the referenced assemblies in the app startup code? Does this work? – Klaus Gütter Nov 25 '18 at 15:40
  • edited OP added App.xaml.cs... if that is sufficient, then yes it works. –  Nov 25 '18 at 15:56
  • interesting... If I take out the user controls from the mainwindow.xaml the window loads fine and I see the referenced xaml resources. So it's seems only the controls are having the issue. –  Nov 25 '18 at 16:07
  • Are the user controls define in the same App assembly? If not, maybe they still reference the old DLLs (without strong name) – Klaus Gütter Nov 25 '18 at 16:17
  • >>Are the user controls define in the same App assembly?<< Yes. Found out that it's only the textbox element and setting a particular style on a togglebutton. I have the source but not sure what to look for. –  Nov 25 '18 at 18:14
  • 1
    Maybe you could enable fusion logging and get a hint from these log files? – Klaus Gütter Nov 25 '18 at 18:23
  • got it working... good thing for fusion log, revision off by 2 numbers, guess it liked the xaml until it ran into something it really needed, so it faked me out. Sorry for bothering ya and thanks for the help! –  Nov 25 '18 at 21:41
  • Glad it works; turned my comment to an answer so that it can be easier found by others. – Klaus Gütter Nov 26 '18 at 03:23

2 Answers2

0

pack://application:,,,/MaterialDesignThemes.Wpf;component - Is "MaterialDesignThemes.Wpf" the name of your assembly? or the namespace?

Can you try using your assembly (dll) name for reference? Check out Pack URI for more details..

Lingam
  • 609
  • 5
  • 16
0

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

Klaus Gütter
  • 11,151
  • 6
  • 31
  • 36