Caliburn微型版本4.0.212。项目版本.NET6
在Caliburn.Micro3.0和.Net Framework 4.7.2中,它可以正常工作
当我尝试打开位于另一个项目中的简单viewModel时,出现错误:“The component does not have a resource identified by the URI”我使用的是Caliburn Micro示例:https://github.com/Caliburn-Micro/Caliburn.Micro/tree/master/samples/tutorals/WPF/Wpf.Tutorial
为了重现错误,我在解决方案中创建了另一个项目:“CommonView”我将AboutViewModel从主项目移到了这个项目,如下图所示:
Solution Explorer View的
在 Bootstrap 中,我需要修改SelectAssemblies方法以添加来自这个新项目的文件
protected override IEnumerable<Assembly> SelectAssemblies()
{
var assemblies = new List<Assembly>();
assemblies.AddRange(base.SelectAssemblies());
string[] fileEntries = Directory.GetFiles(Directory.GetCurrentDirectory());
foreach (string fileName in fileEntries)
{
if (!fileName.Contains(".conf") && fileName.Contains("CommonView.dll"))
{
assemblies.Add(Assembly.LoadFile(fileName));
}
}
return assemblies;
}
字符串
现在,当我从按钮调用About类时,Caliburn试图获取示例,但没有找到,所以我得到了错误。
protected override object GetInstance(Type service, string key)
{
var instance = _container.GetInstance(service, key);
//instance is null
return instance;
}
型
但是,如果我在调用CategoryViewModel时进行调试,它将正确返回示例
我看到这篇文章,Juan卡洛斯覆盖了InitializeComponent(),但我认为它应该有一个更容易的aproachment:The component does not have a resource identified by the uri的
先谢谢你了。谨致问候
1条答案
按热度按时间nzk0hqpo1#
问题出在程序集的加载上,程序集应该是这样的:assemblies.Add(Assemblies.LoadFrom(fileName));
https://learn.microsoft.com/en-us/archive/blogs/suzcook/loadfile-vs-loadfrom
长寿繁荣