Bug 31305 - HttpRequestHeaders.Host throws System.InvalidCastException
Summary: HttpRequestHeaders.Host throws System.InvalidCastException
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-06-22 18:01 UTC by sornakumar
Modified: 2016-04-16 09:33 UTC (History)
4 users (show)

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

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:

Description sornakumar 2015-06-22 18:01:48 UTC
When I try to access Headers.Host (https://github.com/mono/mono/blob/master/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpRequestHeaders.cs#L163) I get an invalid cast exception :
System.InvalidCastException : Cannot cast from source type to destination type.
Stack Trace:
  at (wrapper castclass) object:__castclass_with_cache (object,intptr,intptr)
  at System.Net.Http.Headers.HttpHeaders.GetValue[String] (System.String name) [0x00000] in <filename unknown>:0 
  at System.Net.Http.Headers.HttpRequestHeaders.get_Host () [0x00000] in <filename unknown>:0
Comment 1 Chris Hamons 2015-06-23 12:41:38 UTC
MonoMac is for the open source binding to build Mac GUI applications. This appears to be a class library bug.

Please consider filing similar bugs against that product in the future. I will move this one over.
Comment 2 Marek Safar 2015-06-26 02:24:01 UTC
How can I reproduce the issue?
Comment 3 johanhelsing 2015-10-07 04:01:31 UTC
I had this issue as well on Linux with Mono 4.0.4.

I did some searching, and this is what I found.

StackOverflow question:

Workaround (this worked for me as well):
Comment 4 Marek Safar 2015-10-08 09:18:17 UTC
Please test with Mono 4.2 it has a fix included for quire similar issue
Comment 5 Marek Safar 2016-04-16 09:33:50 UTC
Closing, please reopen if you can still reproduce it with Mono 4.4