我猜您ExportCheck.dll
在您推荐的项目中没有被推荐(Copy Local True)?
对,如果是这样,您将不得不从 Uri 路径加载 DLL。
var asemblyPath = @"C:\MyDevCodeBase\AssetMVVMSample\Asset1MVVMPool\bin\Debug";
var assemblyName = "Asset1MVVMPool"
var myViewModel = "Asset1MVVMPool.List.ViewModels.Asset1ListViewModel, Asset1MVVMPool, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
var newAsmbly = Assembly.LoadFrom(assemblyPath + @"\" + assemblyName + ".dll");
if (!string.IsNullOrEmpty(myViewModel))
{
var type = newAsmbly.GetTypes().FirstOrDefault(
t => t.AssemblyQualifiedName == viewModelFullName);
var currentViewModel
= Activator.CreateInstance(type) as IBaseViewModel;
return currentViewModel;
}
编辑
对于使用 Copy Local True 的已引用程序集,请使用以下代码...
var myasmbly = Assembly.GetExecutingAssembly().GetReferencedAssemblies().Where(
asmbly => asmbly.Name == "Export.dll").FirstOrDefault();
if (!string.IsNullOrEmpty(myViewModel))
{
var type = myasmbly.GetTypes().FirstOrDefault(
t => t.AssemblyQualifiedName == viewModelFullName);
var currentViewModel
= Activator.CreateInstance(type) as IBaseViewModel;
return currentViewModel;
}