突然之间,毫无征兆、莫名其妙地IOC就蹦出了个“已存在具有相同键的条目”的错误。
错误信息
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentException: 已存在具有相同键的条目。
源错误:
行 24: {
行 25: get {
行 26: return new WindsorContainer("Appconfigs.xml"); }
行 27: }
行 28:
源文件: d:\DHis\CoreWebUI\App_Code\ContainerInit.cs 行: 26
堆栈跟踪:
[ArgumentException: 已存在具有相同键的条目。]
System.Collections.Specialized.ListDictionary.Add(Object key, Object value) +2247376
System.Collections.Specialized.HybridDictionary.Add(Object key, Object value) +132
Castle.MicroKernel.Handlers.AbstractHandler.AddDependency(DependencyModel dependency) +423
Castle.MicroKernel.Handlers.AbstractHandler.EnsureDependenciesCanBeSatisfied() +592
Castle.MicroKernel.Handlers.AbstractHandler.Init(IKernel kernel) +143
Castle.MicroKernel.Handlers.DefaultHandlerFactory.Create(ComponentModel model) +134
Castle.MicroKernel.DefaultKernel.AddComponent(String key, Type serviceType, Type classType, LifestyleType lifestyle, Boolean overwriteLifestyle) +449
Castle.MicroKernel.DefaultKernel.AddComponent(String key, Type serviceType, Type classType, LifestyleType lifestyle) +44
Castle.MicroKernel.DefaultKernel.AddComponent(String key, Type serviceType, Type classType) +40
Castle.Windsor.WindsorContainer.AddComponent(String key, Type serviceType, Type classType) +42
Castle.Windsor.Installer.DefaultComponentInstaller.SetUpComponents(IConfiguration[] configurations, IWindsorContainer container) +419
Castle.Windsor.Installer.DefaultComponentInstaller.SetUp(IWindsorContainer container, IConfigurationStore store) +72
Castle.Windsor.WindsorContainer.RunInstaller() +75
Castle.Windsor.WindsorContainer..ctor(IConfigurationInterpreter interpreter) +150
Castle.Windsor.WindsorContainer..ctor(String xmlFile) +51
ContainerInit.get_Container() in d:\DHis\CoreWebUI\App_Code\ContainerInit.cs:26
ASP.global_asax.Session_Start(Object sender, EventArgs e) in d:\DHis\CoreWebUI\Global.asax:35
System.Web.SessionState.SessionStateModule.RaiseOnStart(EventArgs e) +2163166
System.Web.SessionState.SessionStateModule.CompleteAcquireState() +154
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +542
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +90
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 可是配置文件里面明明没有重复的Id呀。经过1小时的排查,发现只要配置文件中的这个
<component
id="Manager.HospPatientDrsAdvice"
service="Dawn.HIS.Core.ManagerInterface.Hospitalized.IHospPatientDrsAdviceManager, Dawn.HIS.Core.ManagerInterface"
type="Dawn.HIS.Core.BusinessManager.Hospitalized.HospPatientDrsAdviceManager, Dawn.HIS.Core.BusinessManager" />
标记注释掉就没问题了。可是这个标记还有用呀,然后发现只要把这个标记移到另一个我新添加的标记
<component
id="Manager.PatientStateAdv"
service="Dawn.HIS.Core.ManagerInterface.Hospitalized.IPatientStateAdvManager, Dawn.HIS.Core.ManagerInterface"
type="Dawn.HIS.Core.BusinessManager.Hospitalized.PatientStateAdvManager, Dawn.HIS.Core.BusinessManager" />
的下面就没问题了。真是奇怪,难道标记的顺序也很重要?
确实,HospPatientDrsAdviceManager类使用了IPatientStateAdvManager,难道如果必须按照引用顺序来排列标记的顺序?