有时我会在我的网络应用程序中收到此错误堆栈跟踪:
[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();
所以我的问题是为什么我会收到这个错误?