我使用棱镜4.1与mef开发前台应用程序,我有问题,它。有时,在模块加载过程中,应用程序会异常失败。
无法加载文件或程序集"Sl.Common.Model,Version = 1.0.0.0,区域性=中性,PublicKeyToken = null“或其依赖项之一。找不到指定的文件。
模块有依赖关系(AuditModule和LoadersModule依赖于CommonModule)。
<Modularity:ModuleCatalog xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:Modularity="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism">
<!-- language: lang-xml -->
<Modularity:ModuleInfo Ref="Sl.Common.Model.xap" InitializationMode="WhenAvailable" ModuleName="CommonModule"/>
<Modularity:ModuleInfo Ref="Sl.Loaders.xap" ModuleName="LoadersModule">
<Modularity:ModuleInfo.DependsOn>
<sys:String>CommonModule</sys:String>
</Modularity:ModuleInfo.DependsOn>
</Modularity:ModuleInfo>
<Modularity:ModuleInfo Ref="Sl.Audit.xap" ModuleName="AuditModule">
<Modularity:ModuleInfo.DependsOn>
<sys:String>CommonModule</sys:String>
</Modularity:ModuleInfo.DependsOn>
</Modularity:ModuleInfo>
</Modularity:ModuleCatalog>应用程序有时会启动ok,但是当AuditModule或LoadersModule由于"CommonModule“而无法解决时,我遇到了一个问题,上面提到了异常。
public class Bootstrapper : MefBootstrapper
{
private const string ModuleCatalogUri = "/ModerationSlUserInteface;component/ModulesCatalog.xaml";
protected override void ConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(StackPanelRegionAdapter).Assembly));
}
protected override IModuleCatalog CreateModuleCatalog()
{
var catalog = Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(new Uri(ModuleCatalogUri, UriKind.Relative));
return catalog;
}
protected override DependencyObject CreateShell()
{
return this.Container.GetExportedValue<Shell>();
}
protected override void InitializeShell()
{
//base.InitializeShell();
Application.Current.RootVisual = (UIElement)this.Shell;
}
protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
{
RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings();
var stackPanelAdapterInstance = ServiceLocator.Current.GetInstance<StackPanelRegionAdapter>();
mappings.RegisterMapping(typeof(StackPanel), stackPanelAdapterInstance);
return mappings;
}
}代码可以从这里中提取
在Shell.xaml.cs中,当我点击if上的断点时(e.ModuleInfo.ModuleName == LoadersModuleName)
如果第一个模块是CommonModule,那么应用程序就启动ok。否则它就会例外地掉下来。
[Export]
public partial class Shell : UserControl, IPartImportsSatisfiedNotification
{
private const string LoadersModuleName = "LoadersModule";
private static Uri LoadersViewUri = new Uri("/LoadersView", UriKind.Relative);
public Shell()
{
this.InitializeComponent();
}
[Import(AllowRecomposition = false)]
public IModuleManager ModuleManager;
[Import(AllowRecomposition = false)]
public IRegionManager RegionManager;
public void OnImportsSatisfied()
{
this.ModuleManager.LoadModuleCompleted += (s, e) =>
{
if (e.ModuleInfo.ModuleName == LoadersModuleName)
{
this.RegionManager.RequestNavigate(RegionNames.MainRegion, LoadersViewUri);
}
};
}
}发布于 2012-09-27 14:46:58
我们发现,您还必须将模块中的任何引用添加到入口点项目。
因此,如果您在AuditModule中引用了AuditModule(例如),那么您也需要将对它的引用添加到MainProject中,即使MainProject中的任何代码都没有直接引用它。
https://stackoverflow.com/questions/12623582
复制相似问题