Bug 4542 - "Key duplication error" when duplicate charset in Content-Type
Summary: "Key duplication error" when duplicate charset in Content-Type
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 2.10.x
Hardware: Other Linux
: --- normal
Target Milestone: Untriaged
Assignee: Gonzalo Paniagua Javier
URL:
Depends on:
Blocks:
 
Reported: 2012-04-19 18:22 UTC by Greg Smolyn
Modified: 2012-04-20 17:31 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Solution demonstrating the bug (3.52 KB, application/x-gzip)
2012-04-19 18:22 UTC, Greg Smolyn
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Greg Smolyn 2012-04-19 18:22:54 UTC
Created attachment 1708 [details]
Solution demonstrating the bug

I am using HttpWebRequest/Response to grab some files off the internet.

In some instances, webResponse.ContentType has a duplicate charset (this is coming from misconfigured servers).

It looks like 

application/x-javascript;charset=UTF-8; charset=utf-8


So, if you have something like

var mime = new System.Net.Mime.ContentType(webResponse.ContentType);

You will get the following stacktrace:

Unhandled Exception: System.ArgumentException: Key duplication when adding: charset
  at System.Collections.Hashtable.PutImpl (System.Object key, System.Object value, Boolean overwrite) [0x00137] in /home/smolyn/src/ThirdParty/mono/2.10/mono-2.10.5/mcs/class/corlib/System.Collections/Hashtable.cs:779 
  at System.Collections.Hashtable.Add (System.Object key, System.Object value) [0x00000] in /home/smolyn/src/ThirdParty/mono/2.10/mono-2.10.5/mcs/class/corlib/System.Collections/Hashtable.cs:442 
  at System.Collections.Specialized.StringDictionary.Add (System.String key, System.String value) [0x00011] in /home/smolyn/src/ThirdParty/mono/2.10/mono-2.10.5/mcs/class/System/System.Collections.Specialized/StringDictionary.cs:116 
  at System.Net.Mime.ContentType.Parse (System.String pair) [0x00075] in /home/smolyn/src/ThirdParty/mono/2.10/mono-2.10.5/mcs/class/System/System.Net.Mime/ContentType.cs:84 
  at System.Net.Mime.ContentType..ctor (System.String contentType) [0x0005f] in /home/smolyn/src/ThirdParty/mono/2.10/mono-2.10.5/mcs/class/System/System.Net.Mime/ContentType.cs:67 
  at ContentTypeTest.MainClass.Main (System.String[] args) [0x00006] in /home/smolyn/ContentTypeTest/ContentTypeTest/Main.cs:13 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Key duplication when adding: charset
  at System.Collections.Hashtable.PutImpl (System.Object key, System.Object value, Boolean overwrite) [0x00137] in /home/smolyn/src/ThirdParty/mono/2.10/mono-2.10.5/mcs/class/corlib/System.Collections/Hashtable.cs:779 
  at System.Collections.Hashtable.Add (System.Object key, System.Object value) [0x00000] in /home/smolyn/src/ThirdParty/mono/2.10/mono-2.10.5/mcs/class/corlib/System.Collections/Hashtable.cs:442 
  at System.Collections.Specialized.StringDictionary.Add (System.String key, System.String value) [0x00011] in /home/smolyn/src/ThirdParty/mono/2.10/mono-2.10.5/mcs/class/System/System.Collections.Specialized/StringDictionary.cs:116 
  at System.Net.Mime.ContentType.Parse (System.String pair) [0x00075] in /home/smolyn/src/ThirdParty/mono/2.10/mono-2.10.5/mcs/class/System/System.Net.Mime/ContentType.cs:84 
  at System.Net.Mime.ContentType..ctor (System.String contentType) [0x0005f] in /home/smolyn/src/ThirdParty/mono/2.10/mono-2.10.5/mcs/class/System/System.Net.Mime/ContentType.cs:67 
  at ContentTypeTest.MainClass.Main (System.String[] args) [0x00006] in /home/smolyn/ContentTypeTest/ContentTypeTest/Main.cs:13
Comment 1 Gonzalo Paniagua Javier 2012-04-20 13:59:29 UTC
Fixed in master/7dd124f and mono-2-10/4b51c2d
Comment 2 Greg Smolyn 2012-04-20 17:31:54 UTC
Wow that was some quick turnaround... thanks! You're awesome!