After successful application deployment in pre-production environment and when I ran the application start page, I got below exception. We shouted “Not Again”… setting up of CS2009 application is not a simple task and automating the installation is a nightmare (as usual, we doubted our installation tool for not installing the application correctly). The exception is wired and we are not able to figure out why the error has occurred?

An exception of type ‘System.ArgumentException’ occurred and was caught.
————————————————————————
06/12/2010 05:22:20
Type : System.ArgumentException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : An item with the same key has already been added.
Source : mscorlib
Help link :
ParamName :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void ThrowArgumentException(System.ExceptionResource)
Stack Trace :    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Microsoft.Commerce.Application.Common.Configuration.ServiceConfiguration.CreateDictionary(String channelName)
   at Microsoft.Commerce.Application.Common.Configuration.ServiceConfiguration.GetSiteName(String channel)
   at Microsoft.Commerce.Broker.OperationService.InitializeOperationContext(CommerceRequest request)
   at Microsoft.Commerce.Broker.OperationService.ProcessRequest(CommerceRequest request)

CS2009 exceptions are not user friendly. You need more troubleshooting skills to see what is the problem and where exactly to tweak to make the application work. Since our site is running on variations (to support multiple languages), I had make sure that our site channel configuration is pointed to correct values.

To troubleshoot these kind of errors, I suggest every CS2009 developer to download Reflector tool. This tool will help us see how the assembly code has written and what values it is expecting and on which condition it is throwing certain exception. After troubleshooting further, I came to know that the old site is not deleted which is currently pointing to same commerce server site and running in same application pool. After stopping the old site, my site started working. Seems CS2009 is adding the site name to a dictionary and it is throwing “An item with the same key has already been added.“exception as the site name was already entered by the first site into the dictionary.

Same error hits back again:

After few days,  I started getting same error on production. Hurry, time to sleepless nights :) . I have verified whether channel configuration is correct and no duplicates. Finally, I peeped into product code using reflector. I could see and feels that when the channel name (CommerceRequest. RequestContext().Channel())comes as empty/null even though the channel name exists in config section/list.

Silly thing is that in one method they are checking for not null in one method

clip_image001

try to add the default value (Default_GUID) in another method.

clip_image001[4]

 

Think of the situation where you didn’t mentioned channel name or somehow commerce server didn’t get channel name.

  • On first request, since we are getting emplty value, we are calling CreateDictionary method to add default channel name to the list(everything is fine till this point).
  • For the next time if we gets empty config value null, we are once again trying to check the value for null and without checking whether default channel (Default_guid) already exist in list , we are trying to add it default_GUID value, which is triggering the value.

The remedy I followed (which worked) is hardcoded channel name in the code.

context.Channel = "Default";
context.UserLocale = SPContext.Current.Web.Locale.ToString();

context.UserUILocale = SPContext.Current.Web.Locale.ToString();

context.RequestId = Guid.NewGuid().ToString("B");

Related Articles


If you like this post, please click on our sponsor advertisement.


Leave a Reply

Follow me on Google+
Couldn't get data from google+
Sign up for Newsletter