Bug 1340 - NullReferenceException when calling WCF service with HTTP method other than GET or POST
Summary: NullReferenceException when calling WCF service with HTTP method other than G...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies ()
Version: 2.10.x
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-10-07 10:18 UTC by Krzysztof Szczuka
Modified: 2012-09-19 00:29 UTC (History)
5 users (show)

Tags:
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:
Status:
RESOLVED FIXED

Description Krzysztof Szczuka 2011-10-07 10:18:39 UTC
I have plain WCF service with WebHttpBinding. The service accepts requests with GET and POST methods.

Now, when using MS .NET runtime the HEAD request on the service methods returns proper response of 405 Method Not Allowed. Using Mono runtime with HEAD request just kills the service. I've looked at the source code and it seems that there is a bug here:

mono\mcs\class\System.ServiceModel\System.ServiceModel.Channels.Http\HttpReplyChannel.cs
...
...
if (ctxi.Request.HttpMethod == "POST") {
  msg = CreatePostMessage (ctxi);
  if (msg == null)
    return false;
} else if (ctxi.Request.HttpMethod == "GET")
    msg = Message.CreateMessage (MessageVersion.None, null);

if (msg.Headers.To == null)
     ^-- here msg can be null
...
...

Stack trace:
Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object
  at System.ServiceModel.Channels.Http.HttpReplyChannel.TryReceiveRequest (TimeS
pan timeout, System.ServiceModel.Channels.RequestContext& context) [0x00000] in
<filename unknown>:0
  at System.ServiceModel.Channels.ReplyChannelBase.<BeginTryReceiveRequest>m__1B
 (TimeSpan tout, System.ServiceModel.Channels.RequestContext& ctx) [0x00000] in
<filename unknown>:0 

Regards
Krzysztof Szczuka
Comment 1 shahbour 2012-06-29 11:15:01 UTC
Hello

I face same issue , i patched my framework with the below to fix it

if (ctxi.Request.HttpMethod == "POST") {
  msg = CreatePostMessage (ctxi);
} else if (ctxi.Request.HttpMethod == "GET")
    msg = Message.CreateMessage (MessageVersion.None, null);
if (msg == null)
    return false;
if (msg.Headers.To == null)
     ^-- here msg can be null

I move the check if msg == null to be after both GET and POST .
Comment 2 Martin Baulig 2012-09-19 00:29:47 UTC
Fixed; master commit 85147e7