Bug 17801 - Missing Content-Type in header cause host crashes
Summary: Missing Content-Type in header cause host crashes
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 3.2.x
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-02-16 00:41 UTC by AlexZ
Modified: 2017-09-06 16:55 UTC (History)
2 users (show)

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


Description AlexZ 2014-02-16 00:41:41 UTC
Send any post without content-type to WCF host will cause its crashes.

Unhandled Exception:
System.ArgumentNullException: Argument cannot be null.
Parameter name: contentType
  at System.ServiceModel.Channels.WebMessageEncoder.IsContentTypeSupported (System.String contentType) [0x00011] in C:\cygwin\sources\mono\mcs\class\System.ServiceModel.Web\System.ServiceModel.Channels\WebMessageEncoder.cs:70
  at System.ServiceModel.Channels.Http.HttpReplyChannel.CreatePostMessage (System.ServiceModel.Channels.Http.HttpContextInfo ctxi) [0x0001d] in C:\cygwin\sources\mono\mcs\class\System.ServiceModel\System.ServiceModel.Channels.Http\HttpReplyChannel.cs:198
  at System.ServiceModel.Channels.Http.HttpReplyChannel.TryReceiveRequest (TimeSpan timeout, System.ServiceModel.Channels.RequestContext& context) [0x000aa] in C:\cygwin\sources\mono\mcs\class\System.ServiceModel\System.ServiceModel.Channels.Http\HttpReplyChannel.cs:172
  at System.ServiceModel.Channels.ReplyChannelBase.<BeginTryReceiveRequest>m__1B (TimeSpan tout, System.ServiceModel.Channels.RequestContext& ctx) [0x00036] in C:\cygwin\sources\mono\mcs\class\System.ServiceModel\System.ServiceModel.Channels\ReplyChannelBase.cs:126 

Version from 2.10.x to 3.2.6(the latest)
The reason is CreatePostMessage(without try-catch block) expecting a bool from IsContentTypeSupported, but IsContentTypeSupported throw a ArgumentNullException.

File: mono\mcs\class\System.ServiceModel.Web\System.ServiceModel.Channels\WebMessageEncoder.cs Line#70
public override bool IsContentTypeSupported (string contentType)
   if (contentType == null)
      //Bad code, commend it: throw new ArgumentNullException ("contentType");
   return false;  //just return false
   return true;
It's a simple patch, please include this in next version.
Comment 1 AlexZ 2014-02-16 00:43:25 UTC
Comment 2 Miguel de Icaza [MSFT] 2015-12-24 15:07:38 UTC
Can you provide a test case for this, and show what .NET would do in this case?
Comment 3 AlexZ 2015-12-25 16:13:26 UTC
Hi, that repro is in my first post. 
.NET will catch that exception but Mono forget to handle it.

Note You need to log in before you can comment on or make changes to this bug.