1
Vote

Getting error "An item with the same key has already been added".

description

I am getting error "An item with the same key has already been added" when initializing the NetSqlAzManRoleProvider using the code approach (instead of config)

Below is the code:
        var roleProvider = new NetSqlAzMan.Providers.NetSqlAzManRoleProvider();

        roleProvider.Initialize("AuthorizationRoleProvider", ConfigureAuthorizationRoleProvider(appConfig));


    private NameValueCollection ConfigureAuthorizationRoleProvider(ApplicationConfigurationManager appConfig)
    {
        var config = new NameValueCollection();

        config["connectionStringName"] = appConfig.AuthorizationDatabaseConnectionName;
        config["storeName"] = appConfig.AuthorizationStoreName;
        config["applicationName"] = appConfig.AuthorizationApplicationName;
        config["userLookupType"] = "LDAP";
        config["defaultDomain"] = "DOMAINNAME";
        config["UseWCFCacheService"] = "false";

        return config;
    }
Stack Trace:

System.TypeInitializationException was unhandled by user code
HResult=-2146233036
Message=The type initializer for 'Core.Infrastructure.IOC.IocContainer' threw an exception.
Source=Core.IOC
TypeName=Core.Infrastructure.IOC.IocContainer
StackTrace:
   at Core.Infrastructure.IOC.IocContainer.get_Instance()
   at Core.Infrastructure.IntegrationTest.Security.AuthorizationManagerIntegrationTest.TestAddUserToMultipleRolesForWindowsUser() in c:\codebase\New folder VS2012\Core\Core.Infrastructure.IntegrationTest\Security\AuthorizationManagerIntegrationTest.cs:line 57
InnerException: System.ArgumentException
   HResult=-2147024809
   Message=An item with the same key has already been added.
   Source=mscorlib
   StackTrace:
        at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
        at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
        at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
        at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
        at NetSqlAzMan.Cache.StorageCache.BuildStorageCache(String storeNameFilter, String applicationNameFilter)
        at NetSqlAzMan.Providers.NetSqlAzManRoleProvider.InvalidateCache(Boolean waitForCacheBuiltCompletition)
        at NetSqlAzMan.Providers.NetSqlAzManRoleProvider.Initialize(String name, NameValueCollection config)
        at Core.Infrastructure.RegisterModule.Authorization.AuthorizationModule.Load() in c:\codebase\New folder VS2012\Core\Core.Infrastructure.RegisterModule.Authorization\AuthorizationModule.cs:line 21
        at Ninject.Modules.NinjectModule.OnLoad(IKernel kernel) in c:\Projects\Ninject\ninject\src\Ninject\Modules\NinjectModule.cs:line 85
        at Ninject.KernelBase.Load(IEnumerable`1 m) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 217
        at Ninject.KernelBase.Load(IEnumerable`1 assemblies) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 245
        at Ninject.Modules.CompiledModuleLoaderPlugin.LoadModules(IEnumerable`1 filenames) in c:\Projects\Ninject\ninject\src\Ninject\Modules\CompiledModuleLoaderPlugin.cs:line 82
        at Ninject.Modules.ModuleLoader.LoadModules(IEnumerable`1 patterns) in c:\Projects\Ninject\ninject\src\Ninject\Modules\ModuleLoader.cs:line 60
        at Ninject.KernelBase.Load(IEnumerable`1 filePatterns) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 236
        at Ninject.ModuleLoadExtensions.Load(IKernel kernel, String[] filePatterns) in c:\Projects\Ninject\ninject\src\Ninject\Syntax\ModuleLoadExtensions.cs:line 54
        at Core.Infrastructure.IOC.IocContainer..cctor() in c:\codebase\New folder VS2012\Core\Core.Infrastructure.IOC\IocContainer.cs:line 39
   InnerException:

comments

aferende wrote Feb 5, 2013 at 4:39 PM

Have you given the same name to the Store and to the Application ?!

Try to rename one of them.