如何从强名称程序集加载 ResourceDictionary?
How to load a ResourceDictionary from a strong names assembly?
我的项目引用了 2 个 dll。如果引用的 dll 名称不强,则资源加载正常并且我的用户控件可以正常工作。问题是我必须强命名引用的 DLL,现在我的用户控件给我一个 XamlParseException System.Windows.Markup.StaticResourceHolder,内部为 "Could not load file or assembly"。我猜无法找到或加载 app.xaml 中的静态资源,因此它认为程序集未加载。有解决办法吗?
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();
}
}
pack://application:,/MaterialDesignThemes.Wpf;component - "MaterialDesignThemes.Wpf" 是您的程序集名称吗?还是命名空间?
您可以尝试使用您的程序集 (dll) 名称作为参考吗?查看
Pack URI 了解更多详情..
您可以启用融合日志记录并从此日志文件中获得提示。
How to enable assembly bind failure logging (Fusion) in .NET
我的项目引用了 2 个 dll。如果引用的 dll 名称不强,则资源加载正常并且我的用户控件可以正常工作。问题是我必须强命名引用的 DLL,现在我的用户控件给我一个 XamlParseException System.Windows.Markup.StaticResourceHolder,内部为 "Could not load file or assembly"。我猜无法找到或加载 app.xaml 中的静态资源,因此它认为程序集未加载。有解决办法吗?
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();
}
}
pack://application:,/MaterialDesignThemes.Wpf;component - "MaterialDesignThemes.Wpf" 是您的程序集名称吗?还是命名空间?
您可以尝试使用您的程序集 (dll) 名称作为参考吗?查看 Pack URI 了解更多详情..
您可以启用融合日志记录并从此日志文件中获得提示。 How to enable assembly bind failure logging (Fusion) in .NET