+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Duplicate Key Exception on Image Handler

Duplicate Key Exception on Image Handler

4 posts, 0 answered
  1. Augusto Radtke
    Augusto Radtke avatar
    24 posts
    Registered:
    16 Apr 2010
    13 Aug 2010
    Link to this post
    Hello,

    Sometimes I got this strange behavior on my site. During the process of loading the various images of a page the image handler gets an exception and doesn´t load the image. After I hit the reload button and try again it works fine.

    The exception is the following:

    System.ArgumentException: Já foi adicionado um item com a mesma chave.
       em System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       em System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       em System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
       em Telerik.Cms.Engine.Data.Providers.DefaultProvider.get_AvailableStreamingProviders()
       em Telerik.Libraries.Data.DefaultProvider.get_AvailableStreamingProviders()
       em Telerik.Cms.Engine.Streaming.StreamHelper.IsStreamingCapable(IContent content, Boolean respectSettings, IStreamingContentProvider& streamingProvider)
       em Telerik.Cms.Engine.Streaming.StreamHelper.IsStreamingCapable(IContent content, Boolean respectSettings)
       em Telerik.Cms.Engine.ContentHttpHandler.GetContentData(HttpContext context, String extension, Object item, ResponseSettings& responseSettings)
       em Telerik.Cms.Web.CmsHttpHandlerBase.ProcessRequest(HttpContext context)
       em System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       em System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    The "Já foi adicionado um item com a mesma chave" means in Portuguese "There is already an item with the same key."

    Any hint?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Aug 2010
    Link to this post
    Hello Augusto Radtke,

    Could you provide some steps that we  could try to reproduce the issue? Which data provider you use - Files or Nolics?

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Augusto Radtke
    Augusto Radtke avatar
    24 posts
    Registered:
    16 Apr 2010
    16 Aug 2010
    Link to this post
    Hello Ivan,

    I´m using the files data provider. I can´t really reproduce it by regular procedure. Sometimes it happens, sometimes it doesn´t, normally it happens when the site isn´t visited for some time.

    I also forget to say that we have our own content handler for the images. Actually we derive from ContentHttpHandler and just override the ResizeImage() method to support a start crop position, the code is the following:

    protected override byte[] ResizeImage(byte[] imageData, string mimeType, System.Web.HttpRequest request)
            {
                Image image = Image.FromStream(new MemoryStream(imageData));
     
                int width = int.Parse(request.QueryString["width"]);
                int height = int.Parse(request.QueryString["height"]);
     
                 
                int x = request.QueryString["x"] != null ? Convert.ToInt32(request.QueryString["x"]) : 0;
                int y = request.QueryString["y"] != null ? Convert.ToInt32(request.QueryString["y"]) : 0;;
     
                MemoryStream stream = new MemoryStream();
                bool decreaseOnly = false;
                if ("true".Equals(request.QueryString["decreaseOnly"], StringComparison.OrdinalIgnoreCase)) {
                    decreaseOnly = true;
                }
                bool keepProportions = true;
                if ("false".Equals(request.QueryString["proportional"], StringComparison.OrdinalIgnoreCase)) {
                    keepProportions = false;
                }
     
                Telerik.Cms.Engine.ImagesHelper.SaveImageToStream(ImagesExtender.GenerateThumbnail(width, height, image, keepProportions, decreaseOnly, x, y), stream, mimeType);
     
                return stream.GetBuffer();
            }

    There is nothing really magic about that and we really don´t use dictionaries to possible explode with duplicate keys.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Aug 2010
    Link to this post
    Hi Augusto Radtke,

    1. Make sure that you have removed/replaced all references to the default ContentHttpHandler in your web.config file

    2. Try excluding the custom ContentHttpHandler from your project for a while and see whether the problem will appear. If you use an older version of Sitefinity try using the latest SP - Sitefinity 3.7 SP3, because there are some fixes between SP1, SP2 and SP3 releases.



    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered