我将 LinqToSql 用于 mvc Web 应用程序。如果很多人大致同时访问网络应用程序,我会看到一个An item with the same key has already been added.
错误。此错误的堆栈如下所示:
[ArgumentException: An item with the same key has already been added.]
System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +12673712
System.Data.Linq.DataContext.GetTable(MetaTable metaTable) +286
System.Data.Linq.DataContext.GetTable() +100
CableSense.Domain.Repository.Concrete.RoleRepository.GetRolesForUser(String userName) in c:\BuildAgent\work\271278ff356daf1\CableSense.Domain\Repository\Concrete\RoleRepository.cs:84
这只发生在我的 RoleRrovider 类中,它是 .net RoleProvider 的自定义实现。在那里,我的 ctor 从 Ninject 获得了一个存储库,如下所示:
public CustomRoleProvider()
{
_roleRepository = NinjectMVC3.Resolve<IRoleRepository>();
}
出错的方法:
public override string[] GetRolesForUser(string username)
{
return _roleRepository.GetRolesForUser(username);
}
在我的仓库中,只是一个返回数据的 linq 查询——仓库在内部实例化了一个上下文,没有什么是静态的或共享的。
任何想法为什么会发生这种情况?