Duplicate Key Error

Topics: Troubleshooting
Apr 14, 2011 at 7:31 PM

This post is nearly the same error (and I think same bug). It seems at some point I changed the case while creating a module (location/Location) and I can see in the Db where they are both in there.

The http://orchard.codeplex.com/workitem/17217 shows closed, but it's here in 1.1...Not sure if we need a new work item or not.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An item with the same key has already been added.

Source Error:

[No relevant source lines]

Source File: RecordTableNameConvention.cs Line: 13

Stack Trace:

[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) +9382923
   System.Linq.Enumerable.ToDictionary(IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) +252
   Orchard.Data.Conventions.RecordTableNameConvention..ctor(IEnumerable`1 descriptors) in RecordTableNameConvention.cs:13
   Orchard.Data.Providers.AbstractDataServicesProvider.CreatePersistenceModel(IEnumerable`1 recordDescriptors) in AbstractDataServicesProvider.cs:30
   Orchard.Data.Providers.AbstractDataServicesProvider.BuildConfiguration(SessionFactoryParameters parameters) in AbstractDataServicesProvider.cs:0
   Orchard.Data.<>c__DisplayClass3.<BuildConfiguration>b__2() in SessionFactoryHolder.cs:82
   Orchard.Data.SessionConfigurationCache.GetConfiguration(Func`1 builder) in SessionConfigurationCache.cs:51
   Orchard.Data.SessionFactoryHolder.BuildConfiguration() in SessionFactoryHolder.cs:81
   Orchard.Data.SessionFactoryHolder.GetConfiguration() in SessionFactoryHolder.cs:62
   Orchard.Data.SessionFactoryHolder.BuildSessionFactory() in SessionFactoryHolder.cs:74
   Orchard.Data.SessionFactoryHolder.GetSessionFactory() in SessionFactoryHolder.cs:52
   Orchard.Data.SessionLocator.For(Type entityType) in SessionLocator.cs:29
   Orchard.Data.Repository`1.get_Session() in Repository.cs:26
   Orchard.Data.Repository`1.get_Table() in Repository.cs:30
   Orchard.Data.Repository`1.Fetch(Expression`1 predicate) in Repository.cs:126
   Orchard.Data.Repository`1.Get(Expression`1 predicate) in Repository.cs:91
   Orchard.Data.Repository`1.Orchard.Data.IRepository<T>.Get(Expression`1 predicate) in Repository.cs:60
   Orchard.Core.Settings.Descriptor.ShellDescriptorManager.GetDescriptorRecord() in C:\websiteV3\src\Orchard.Web\Core\Settings\Descriptor\ShellDescriptorManager.cs:52
   Orchard.Core.Settings.Descriptor.ShellDescriptorManager.GetShellDescriptor() in C:\websiteV3\src\Orchard.Web\Core\Settings\Descriptor\ShellDescriptorManager.cs:25
   Orchard.Environment.ShellBuilders.ShellContextFactory.CreateShellContext(ShellSettings settings) in ShellContextFactory.cs:66
   Orchard.Environment.DefaultOrchardHost.CreateShellContext(ShellSettings settings) in DefaultOrchardHost.cs:133
   Orchard.Environment.DefaultOrchardHost.<CreateAndActivate>b__4(ShellSettings settings) in DefaultOrchardHost.cs:105
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +85
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +217
   System.Linq.Enumerable.ToArray(IEnumerable`1 source) +78
   Orchard.Environment.DefaultOrchardHost.BuildCurrent() in DefaultOrchardHost.cs:92
   Orchard.Environment.DefaultOrchardHost.BeginRequest() in DefaultOrchardHost.cs:166
   Orchard.Environment.DefaultOrchardHost.Orchard.Environment.IOrchardHost.BeginRequest() in DefaultOrchardHost.cs:70
   Orchard.WarmupStarter.Starter.OnBeginRequest(HttpContext context, Action`1 registrations) in Starter.cs:29
   Orchard.Web.MvcApplication.Application_BeginRequest() in C:\websiteV3\src\Orchard.Web\Global.asax.cs:24

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +72
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +335
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
   System.Web.Util.ArglessEventHandlerProxy.Callback(Object sender, EventArgs e) +57
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225

Server Error in '/' Application.

An item with the same key has already been added.

<!-- [ArgumentException]: An item with the same key has already been added. 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 Orchard.Data.Conventions.RecordTableNameConvention..ctor(IEnumerable`1 descriptors) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\Conventions\RecordTableNameConvention.cs:line 13 at Orchard.Data.Providers.AbstractDataServicesProvider.CreatePersistenceModel(IEnumerable`1 recordDescriptors) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\Providers\AbstractDataServicesProvider.cs:line 30 at Orchard.Data.Providers.AbstractDataServicesProvider.BuildConfiguration(SessionFactoryParameters parameters) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\Providers\AbstractDataServicesProvider.cs:line 0 at Orchard.Data.SessionFactoryHolder.<>c__DisplayClass3.<BuildConfiguration>b__2() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\SessionFactoryHolder.cs:line 82 at Orchard.Data.SessionConfigurationCache.GetConfiguration(Func`1 builder) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\SessionConfigurationCache.cs:line 51 at Orchard.Data.SessionFactoryHolder.BuildConfiguration() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\SessionFactoryHolder.cs:line 81 at Orchard.Data.SessionFactoryHolder.GetConfiguration() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\SessionFactoryHolder.cs:line 62 at Orchard.Data.SessionFactoryHolder.BuildSessionFactory() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\SessionFactoryHolder.cs:line 74 at Orchard.Data.SessionFactoryHolder.GetSessionFactory() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\SessionFactoryHolder.cs:line 52 at Orchard.Data.SessionLocator.For(Type entityType) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\SessionLocator.cs:line 29 at Orchard.Data.Repository`1.get_Session() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\Repository.cs:line 26 at Orchard.Data.Repository`1.get_Table() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\Repository.cs:line 30 at Orchard.Data.Repository`1.Fetch(Expression`1 predicate) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\Repository.cs:line 126 at Orchard.Data.Repository`1.Get(Expression`1 predicate) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\Repository.cs:line 91 at Orchard.Data.Repository`1.Orchard.Data.IRepository<T>.Get(Expression`1 predicate) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Data\Repository.cs:line 60 at Orchard.Core.Settings.Descriptor.ShellDescriptorManager.GetDescriptorRecord() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard.Web\Core\Settings\Descriptor\ShellDescriptorManager.cs:line 52 at Orchard.Core.Settings.Descriptor.ShellDescriptorManager.GetShellDescriptor() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard.Web\Core\Settings\Descriptor\ShellDescriptorManager.cs:line 25 at Orchard.Environment.ShellBuilders.ShellContextFactory.CreateShellContext(ShellSettings settings) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Environment\ShellBuilders\ShellContextFactory.cs:line 66 at Orchard.Environment.DefaultOrchardHost.CreateShellContext(ShellSettings settings) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Environment\DefaultOrchardHost.cs:line 133 at Orchard.Environment.DefaultOrchardHost.<CreateAndActivate>b__4(ShellSettings settings) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Environment\DefaultOrchardHost.cs:line 105 at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at Orchard.Environment.DefaultOrchardHost.BuildCurrent() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Environment\DefaultOrchardHost.cs:line 92 at Orchard.Environment.DefaultOrchardHost.BeginRequest() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Environment\DefaultOrchardHost.cs:line 166 at Orchard.Environment.DefaultOrchardHost.Orchard.Environment.IOrchardHost.BeginRequest() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard\Environment\DefaultOrchardHost.cs:line 70 at Orchard.WarmupStarter.Starter.OnBeginRequest(HttpContext context, Action`1 registrations) in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard.Startup\Starter.cs:line 29 at Orchard.Web.MvcApplication.Application_BeginRequest() in C:\Users\gsffbwc\Documents\Visual Studio 2010\Projects\EstrellaInsurance\websiteV3\src\Orchard.Web\Global.asax.cs:line 24 [TargetInvocationException]: Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Web.Util.ArglessEventHandlerProxy.Callback(Object sender, EventArgs e) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) -->
Coordinator
Apr 14, 2011 at 7:35 PM

If it still reproduces, please re-open the bug.