如果我插入一个断点没有命中并给我一个错误,调试器根本不会命中Module

时间:2012-02-22 13:27:38

标签: silverlight mef prism-4

我遇到问题(重要的是要注意调试器没有命中 CivicaHousingRepairsModule ....如果我在第一行插入断点......没有任何内容被击中。)因为最近2天没有任何线索。 我使用Silverlight 4,PRISM 4.0和MEF创建了示例应用程序。以下是哪个contian两个模块。

//Module 1
namespace Civica.Housing.Security
{
    [ModuleExport(typeof(CivicaHousingSecurityModule),InitializationMode = InitializationMode.OnDemand)]
    public class CivicaHousingSecurityModule:IModule
    {
         private readonly IRegionManager _regionManager;
         [ImportingConstructor] //MEF magic to for resolving all the DI
         public CivicaHousingSecurityModule(IRegionManager regionManager, IAuthenticationService authenticationService)
         {
             regionManager.CheckForNull("regionManager");
             _regionManager = regionManager;
         }
         #region IModule Implementation
         public void Initialize()
         {
         } 
         #endregion
    }
}

//Module 2
namespace Civica.Housing.Repairs
{
    [ModuleExport(typeof(CivicaHousingRepairsModule), InitializationMode = InitializationMode.OnDemand)]
    public class CivicaHousingRepairsModule : IModule
    {
        private readonly IRegionManager _regionManager;
        #region Constructor
        [ImportingConstructor] 
        public CivicaHousingRepairsModule(IRegionManager regionManager, IAuthenticationService authenticationService)
        {
            regionManager.CheckForNull("regionManager");
            _regionManager = regionManager;
        }
        #endregion
        #region IModule Implementation
        public void Initialize()
        {
            _regionManager.RegisterViewWithRegion(RegionNames.ContentRegion, typeof(TestView));
        }
        #endregion
    }
}

以下是regestring模块的代码( ModuleCatalog.xaml )。

<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">
    <Modularity:ModuleInfo Ref="Civica.Housing.Security.xap" InitializationMode="OnDemand" 
ModuleName="CivicaHousingSecurityModule" />
    <Modularity:ModuleInfo Ref="Civica.Housing.Repairs.xap" InitializationMode="OnDemand" 
ModuleName="CivicaHousingRepairsModule" />
</Modularity:ModuleCatalog>

以下是 Bootstrapper

的代码
 public class CivicaHousingBootstrapper : MefBootstrapper
    {
        private const string ModuleCatalogUri = 

"/Civica.Housing.App;component/ModulesCatalog.xaml";
.
.
.
 protected override Microsoft.Practices.Prism.Modularity.IModuleCatalog CreateModuleCatalog()
        {
            var moduleCatalog=Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml

(new Uri(ModuleCatalogUri,


UriKind.Relative));
            return moduleCatalog;            
        }
.
.
.
}

问题:

当我从一个模块(安全)导航到另一个模块(修复)时,它会给我以下错误

Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 
2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; 
Tablet PC 2.0)
Timestamp: Wed, 22 Feb 2012 13:18:00 UTC
Message: Unhandled Error in Silverlight Application 
Code: 4004    
Category: ManagedRuntimeError   
Message: Microsoft.Practices.Prism.Modularity.ModuleInitializeException: An exception 
occurred while initializing module 'CivicaHousingRepairsModule'. 
    - The exception message was: The composition remains unchanged. The changes were rejected 
because of the following error(s): The composition produced multiple composition errors, with 3 
root causes. The root causes are provided below. Review the CompositionException.Errors property 
for more detailed information.
1) More than one export was found that matches the constraint '((exportDefinition.ContractName == 
"Civica.Housing.Services.IRepairsDataService") AndAlso (exportDefinition.Metadata.ContainsKey
("ExportTypeIdentity") AndAlso "Civica.Housing.Services.IRepairsDataService".Equals

(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.

Resulting in: Cannot set import 'Civica.Housing.Security.ViewModels.DashboardViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService")' 

on part 'Civica.Housing.Security.ViewModels.DashboardViewModel'.
Element: Civica.Housing.Security.ViewModels.DashboardViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService") 

-->  Civica.Housing.Security.ViewModels.DashboardViewModel -->  AssemblyCatalog 

(Assembly="Civica.Housing.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

2) More than one export was found that matches the constraint '((exportDefinition.ContractName == 

"Civica.Housing.Services.IRepairsDataService") AndAlso (exportDefinition.Metadata.ContainsKey

("ExportTypeIdentity") AndAlso "Civica.Housing.Services.IRepairsDataService".Equals

(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.

Resulting in: Cannot set import 'Civica.Housing.Security.ViewModels.ShortcutViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService")' 

on part 'Civica.Housing.Security.ViewModels.ShortcutViewModel'.
Element: Civica.Housing.Security.ViewModels.ShortcutViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService") 

-->  Civica.Housing.Security.ViewModels.ShortcutViewModel -->  AssemblyCatalog 

(Assembly="Civica.Housing.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

3) More than one export was found that matches the constraint '((exportDefinition.ContractName == 

"Civica.Housing.Services.IRepairsDataService") AndAlso (exportDefinition.Metadata.ContainsKey

("ExportTypeIdentity") AndAlso "Civica.Housing.Services.IRepairsDataService".Equals

(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.

Resulting in: Cannot set import 'Civica.Housing.Security.ViewModels.HeaderViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService")' 

on part 'Civica.Housing.Security.ViewModels.HeaderViewModel'.
Element: Civica.Housing.Security.ViewModels.HeaderViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService") 

-->  Civica.Housing.Security.ViewModels.HeaderViewModel -->  AssemblyCatalog 

(Assembly="Civica.Housing.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

    Check the InnerException property of the exception for more information. If the exception 

occurred 
    while creating an object in a DI container, you can exception.GetRootException() to help 

locate the 
    root cause of the problem.  ---> System.ComponentModel.Composition.ChangeRejectedException: 

The composition remains unchanged. The changes were rejected because of the following error(s): 

The composition produced multiple composition errors, with 3 root causes. The root causes are 

provided below. Review the CompositionException.Errors property for more detailed information.

1) More than one export was found that matches the constraint '((exportDefinition.ContractName == 

"Civica.Housing.Services.IRepairsDataService") AndAlso (exportDefinition.Metadata.ContainsKey

("ExportTypeIdentity") AndAlso "Civica.Housing.Services.IRepairsDataService".Equals

(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.

Resulting in: Cannot set import 'Civica.Housing.Security.ViewModels.DashboardViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService")' 

on part 'Civica.Housing.Security.ViewModels.DashboardViewModel'.
Element: Civica.Housing.Security.ViewModels.DashboardViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService") 

-->  Civica.Housing.Security.ViewModels.DashboardViewModel -->  AssemblyCatalog 

(Assembly="Civica.Housing.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

2) More than one export was found that matches the constraint '((exportDefinition.ContractName == 

"Civica.Housing.Services.IRepairsDataService") AndAlso (exportDefinition.Metadata.ContainsKey

("ExportTypeIdentity") AndAlso "Civica.Housing.Services.IRepairsDataService".Equals

(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.

Resulting in: Cannot set import 'Civica.Housing.Security.ViewModels.ShortcutViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService")' 

on part 'Civica.Housing.Security.ViewModels.ShortcutViewModel'.
Element: Civica.Housing.Security.ViewModels.ShortcutViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService") 

-->  Civica.Housing.Security.ViewModels.ShortcutViewModel -->  AssemblyCatalog 

(Assembly="Civica.Housing.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

3) More than one export was found that matches the constraint '((exportDefinition.ContractName == 

"Civica.Housing.Services.IRepairsDataService") AndAlso (exportDefinition.Metadata.ContainsKey

("ExportTypeIdentity") AndAlso "Civica.Housing.Services.IRepairsDataService".Equals

(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.

Resulting in: Cannot set import 'Civica.Housing.Security.ViewModels.HeaderViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService")' 

on part 'Civica.Housing.Security.ViewModels.HeaderViewModel'.
Element: Civica.Housing.Security.ViewModels.HeaderViewModel..ctor 

(Parameter="_iRepairsDataService", ContractName="Civica.Housing.Services.IRepairsDataService") 

-->  Civica.Housing.Security.ViewModels.HeaderViewModel -->  AssemblyCatalog 

(Assembly="Civica.Housing.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

   at System.ComponentModel.Composition.CompositionResult.ThrowOnErrors(AtomicComposition 

atomicComposition)
   at System.ComponentModel.Composition.Hosting.ExportProvider.OnExportsChanging

(ExportsChangeEventArgs e)
   at System.ComponentModel.Composition.Hosting.CatalogExportProvider.OnCatalogChanging(Object 

sender, ComposablePartCatalogChangeEventArgs e)
   at System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.OnChanging(Object 

sender, ComposablePartCatalogChangeEventArgs e)
   at System.ComponentModel.Composition.Hosting.AggregateCatalog.OnChanging

(ComposablePartCatalogChangeEventArgs e)
   at 

System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.RaiseChangingEvent

(Lazy`1 addedDefinitions, Lazy`1 removedDefinitions, AtomicComposition atomicComposition)
   at System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.Add

(ComposablePartCatalog item)
   at Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleInitializer.CreateModule

(ModuleInfo moduleInfo)
   at Microsoft.Practices.Prism.Modularity.ModuleInitializer.Initialize(ModuleInfo moduleInfo)
   --- End of inner exception stack trace ---
   at Microsoft.Practices.Prism.Modularity.ModuleInitializer.HandleModuleInitializationError

(ModuleInfo moduleInfo, String assemblyName, Exception exception)
   at Microsoft.Practices.Prism.Modularity.ModuleInitializer.Initialize(ModuleInfo moduleInfo)
   at Microsoft.Practices.Prism.Modularity.ModuleManager.InitializeModule(ModuleInfo moduleInfo)
   at Microsoft.Practices.Prism.Modularity.ModuleManager.LoadModulesThatAreReadyForLoad()
   at Microsoft.Practices.Prism.Modularity.ModuleManager.IModuleTypeLoader_LoadModuleCompleted

(Object sender, LoadModuleCompletedEventArgs e)
   at 

Microsoft.Practices.Prism.MefExtensions.Modularity.MefXapModuleTypeLoader.RaiseLoadModuleComplete

d(LoadModuleCompletedEventArgs e)
   at 

Microsoft.Practices.Prism.MefExtensions.Modularity.MefXapModuleTypeLoader.RaiseLoadModuleComplete

d(ModuleInfo moduleInfo, Exception error)
   at 

Microsoft.Practices.Prism.MefExtensions.Modularity.MefXapModuleTypeLoader.HandleDownloadCompleted

(DeploymentCatalog deploymentCatalog, AsyncCompletedEventArgs e)
   at 

Microsoft.Practices.Prism.MefExtensions.Modularity.MefXapModuleTypeLoader.DeploymentCatalog_Downl

oadCompleted(Object sender, AsyncCompletedEventArgs e)
   at System.ComponentModel.Composition.Hosting.DeploymentCatalog.OnDownloadCompleted

(AsyncCompletedEventArgs e)
   at System.ComponentModel.Composition.Hosting.DeploymentCatalog.HandleOpenReadCompleted(Object 

sender, OpenReadCompletedEventArgs e)
   at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
   at System.Net.WebClient.OpenReadOperationCompleted(Object arg)     

Line: 56
Char: 13
Code: 0
URI: http://localhost:61228/Civica.Housing.aspx

重要提示:调试器根本没有点击CivicaHousingRepairsModule如果我插入

第一行中的断点没有被击中。

我试过: 1.我已将所有PRISM dll设置为localcopy为假。

如果您遇到同样的问题并且有一个很好的解决方案,请告诉我。您的回答或建议将不胜感激。

2 个答案:

答案 0 :(得分:0)

我认为它的becoz ur xap文件不存在或处于损坏的格式。请从web项目中删除所有你的xap文件,然后按模块重建你的应用程序模块,然后尝试运行你的应用程序

答案 1 :(得分:0)

在您的模块项目中,您必须为所有Prism引用配置CopyLocal ='false',否则,在MainProject中,它应该是CopyLocal ='true'。 它对我有用。