2

Web アプリで次のエラー スタック トレースを取得することがあります。

   [ArgumentException: An item with the same key has already been added.]
   System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
   System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +10695474
   System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) +10
   NHibernate.Util.ThreadSafeDictionary`2.Add(TKey key, TValue value) +93
   NHibernate.Type.TypeFactory.GetType(NullableType defaultUnqualifiedType, Int32 length, GetNullableTypeWithLength ctorDelegate) +88
   NHibernate.Type.TypeFactory.<RegisterDefaultNetTypes>b__c(Int32 l) +82
   NHibernate.Type.TypeFactory.BuiltInType(String typeName, Int32 length) +46
   NHibernate.Mapping.SimpleValue.GetHeuristicType() +168
   NHibernate.Mapping.SimpleValue.get_Type() +49
   NHibernate.Mapping.SimpleValue.IsValid(IMapping mapping) +30
   NHibernate.Mapping.PersistentClass.Validate(IMapping mapping) +87
   NHibernate.Mapping.RootClass.Validate(IMapping mapping) +21
   NHibernate.Cfg.Configuration.ValidateEntities() +183
   NHibernate.Cfg.Configuration.Validate() +13
   NHibernate.Cfg.Configuration.BuildSessionFactory() +36
   Framework.Data.Code.BaseSessionFactoryProvider..ctor() +74
   Framework.Data.Code.SessionFactoryProvider..ctor() +29
   Framework.Data.Code.NestedSessionManager..cctor() +43

私の SessionFactoryProvider はスレッドセーフなシングルトーンです:

 public interface ISessionFactoryProvider
 {
        ISessionFactory GetSessionFactory();
 }
 public abstract class BaseSessionFactoryProvider : ISessionFactoryProvider
 {
        protected readonly ISessionFactory factory;
        public ISessionFactory GetSessionFactory()
        {
            return factory;
        }

        protected BaseSessionFactoryProvider()
        {
            factory = GetConfig().BuildSessionFactory();
        }
        public abstract Configuration GetConfig();
 }
 public class SessionFactoryProvider : BaseSessionFactoryProvider
 {
            public static ISessionFactory SessionFactory
            {
                get { return Instance.factory; }
            }
            public override Configuration GetConfig()
            {
                return new Configuration().Configure();
            }
            public static SessionFactoryProvider Instance
            {
                get
                {
                    return NestedSessionManager.sessionManager;
                }
            }
            class NestedSessionManager
            {
                internal static readonly SessionFactoryProvider sessionManager =
                    new SessionFactoryProvider();
            }
   }

また、私のアプリでは、ninject を介して SessionFactoryProvider を ISessionFactoryProvider にバインドします kernel.Bind<ISessionFactoryProvider>().To<SessionFactoryProvider>().InSingletonScope();

だから私の質問はなぜこのエラーが発生するのですか?

4

1 に答える 1