Silverlight 应用程序中未处理的错误无法找到模块
我的解决方案包含 4 个 Silverlight 项目 - 一个主项目、两个模块项目和最后一个共享项目(用于通用接口等)。
主项目和模块项目没有相互引用(只是为了共享项目)。
您可以在下面找到我的模块的定义:
[ModuleExport("ServiceModule", typeof(ServiceModule), InitializationMode = InitializationMode.WhenAvailable)]
public class ServiceModule : IModule
[ModuleExport("ViewModule",
typeof(ViewModule),
DependsOnModuleNames = new string[] { "ServiceModule" },
InitializationMode = InitializationMode.WhenAvailable)]
public class ViewModule : IModule
我将模块添加到 ModuleCatalog 到主项目的派生 MefBootstrapper 类中(我使用模块的代码注册而不是 CreateFromXaml 方法):
protected override void ConfigureModuleCatalog()
{
ModuleCatalog.AddModule(
new ModuleInfo()
{
ModuleName = "ServiceModule",
ModuleType = "SilverlightEnabledService.ModuleDefinitions.ServiceModule, SilverlightEnabledService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ca4f032071a86aea",
Ref = "SilverlightEnabledService.xap",
InitializationMode = InitializationMode.WhenAvailable
}
);
ModuleCatalog.AddModule(
new ModuleInfo()
{
ModuleName = "ViewModule",
ModuleType = "RedOrBlackModule.ModuleDefinitions.ViewModule, RedOrBlackModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ca4f032071a86aea",
Ref = "RedOrBlackModule.xap",
InitializationMode = InitializationMode.WhenAvailable,
DependsOn = (new Collection<string>(new string[] { "ServiceModule" }))
}
);
}
从上面的代码可以看出,ModuleCtalog 模块名称与模块名称相同在 ModuleExportAttribute 中,但我得到以下异常:
未捕获的错误:Silverlight 应用程序中未处理的错误无法在导出的模块中找到类型为“SilverlightEnabledService.ModuleDefinitions.ServiceModule、SilverlightEnabledService、Version=1.0.0.0、Culture=neutral、PublicKeyToken=ca4f032071a86aea”的模块。确保模块目录中的模块名称与 ModuleExportAttribute 上为模块类型指定的名称相匹配。 в Microsoft.Practices.Prism.Modularity.ModuleInitializer.HandleModuleInitializationError(ModuleInfo moduleInfo, String assemblyName, Exception 异常)...
这似乎很简单的问题,但我还找不到解决方案。
My solution contains 4 Silverlight projects - one main, two module projects and last one share project (for common interfaces etc).
Main and module projects don't have references to each other (just to share project).
You can find definitions of my modules below:
[ModuleExport("ServiceModule", typeof(ServiceModule), InitializationMode = InitializationMode.WhenAvailable)]
public class ServiceModule : IModule
[ModuleExport("ViewModule",
typeof(ViewModule),
DependsOnModuleNames = new string[] { "ServiceModule" },
InitializationMode = InitializationMode.WhenAvailable)]
public class ViewModule : IModule
And I added modules to ModuleCatalog into derived MefBootstrapper class of main project (I used code registration of modules instead of CreateFromXaml method):
protected override void ConfigureModuleCatalog()
{
ModuleCatalog.AddModule(
new ModuleInfo()
{
ModuleName = "ServiceModule",
ModuleType = "SilverlightEnabledService.ModuleDefinitions.ServiceModule, SilverlightEnabledService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ca4f032071a86aea",
Ref = "SilverlightEnabledService.xap",
InitializationMode = InitializationMode.WhenAvailable
}
);
ModuleCatalog.AddModule(
new ModuleInfo()
{
ModuleName = "ViewModule",
ModuleType = "RedOrBlackModule.ModuleDefinitions.ViewModule, RedOrBlackModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ca4f032071a86aea",
Ref = "RedOrBlackModule.xap",
InitializationMode = InitializationMode.WhenAvailable,
DependsOn = (new Collection<string>(new string[] { "ServiceModule" }))
}
);
}
As see from code above, ModuleCtalog module name is the same as module name in ModuleExportAttribute, but I get exception below:
Uncaught Error: Unhandled Error in Silverlight Application Unable to locate the module with type 'SilverlightEnabledService.ModuleDefinitions.ServiceModule, SilverlightEnabledService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ca4f032071a86aea' among the exported modules. Make sure the module name in the module catalog matches that specified on ModuleExportAttribute for the module type. в Microsoft.Practices.Prism.Modularity.ModuleInitializer.HandleModuleInitializationError(ModuleInfo moduleInfo, String assemblyName, Exception exception)...
It seems very easy issue but I cannot find solution yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找不到该模块的原因有多种。请参阅此博客文章,了解它们的含义以及如何调试它们:如何调试和诊断 MEF 故障。
There are several reasons why the module might not be found. See this blog post for an overview of what they are and how to debug them: How to Debug and Diagnose MEF Failures.