Bug 20764 - WebMessageFormatter crashes with void return type OperationContract
Summary: WebMessageFormatter crashes with void return type OperationContract
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 3.4.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-06-20 13:42 UTC by RGeoffrion
Modified: 2017-09-06 16:55 UTC (History)
3 users (show)

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


Attachments
patch file (636 bytes, application/octet-stream)
2014-06-20 13:42 UTC, RGeoffrion
Details
patch file (637 bytes, patch)
2014-06-20 14:32 UTC, RGeoffrion
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 RGeoffrion 2014-06-20 13:42:03 UTC
Created attachment 7133 [details]
patch file

Exception Object reference not set to an instance of an object   at System.ServiceModel.Dispatcher.WebMessageFormatter+WrappedBodyWriter.WriteObject (System.Runtime.Serialization.XmlObjectSerializer serializer, System.Xml.XmlDictionaryWriter writer, System.Object value) [0x00000] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs:481 
  at System.ServiceModel.Dispatcher.WebMessageFormatter+WrappedBodyWriter.WriteJsonBodyContents (System.Xml.XmlDictionaryWriter writer) [0x00026] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs:459 
  at System.ServiceModel.Dispatcher.WebMessageFormatter+WrappedBodyWriter.OnWriteBodyContents (System.Xml.XmlDictionaryWriter writer) [0x0002d] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs:440 
  at System.ServiceModel.Channels.BodyWriter.WriteBodyContents (System.Xml.XmlDictionaryWriter writer) [0x00000] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Channels/BodyWriter.cs:57 
  at System.ServiceModel.Channels.SimpleMessage.OnWriteBodyContents (System.Xml.XmlDictionaryWriter writer) [0x00000] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Channels/MessageImpl.cs:331 
  at System.ServiceModel.Channels.Message.WriteBodyContents (System.Xml.XmlDictionaryWriter writer) [0x00022] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:183 
  at System.ServiceModel.Channels.Message.WriteBody (System.Xml.XmlDictionaryWriter writer) [0x0001c] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:168 
  at System.ServiceModel.Channels.Message.OnWriteMessage (System.Xml.XmlDictionaryWriter writer) [0x00065] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:293 
  at System.ServiceModel.Channels.Message.WriteMessage (System.Xml.XmlDictionaryWriter writer) [0x00026] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:195 
  at System.ServiceModel.Channels.Message.WriteMessage (System.Xml.XmlWriter writer) [0x00000] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:200 
  at System.ServiceModel.Channels.WebMessageEncoder.WriteMessage (System.ServiceModel.Channels.Message message, System.IO.Stream stream) [0x000ee] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs:187 
  at System.ServiceModel.Channels.Http.HttpRequestContext.InternalReply (System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00034] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpRequestContext.cs:139 
  at System.ServiceModel.Channels.Http.HttpRequestContext.Reply (System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Channels.Http/HttpRequestContext.cs:101 
  at System.ServiceModel.Dispatcher.MessageProcessingContext.Reply (Boolean useTimeout) [0x00026] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/MessageProcessingContext.cs:96 
  at System.ServiceModel.Dispatcher.OperationInvokerHandler.Reply (System.ServiceModel.Dispatcher.MessageProcessingContext mrc, Boolean useTimeout) [0x0001d] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/OperationInvokerHandler.cs:69 
  at System.ServiceModel.Dispatcher.OperationInvokerHandler.ProcessRequest (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00044] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/OperationInvokerHandler.cs:29 
  at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseRequestProcessorHandler.cs:15 
  at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00017] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseRequestProcessorHandler.cs:16 
  at System.ServiceModel.Dispatcher.HandlersChain.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x0000b] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseRequestProcessor.cs:72 
  at System.ServiceModel.Dispatcher.BaseRequestProcessor.ProcessRequest (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00018] in /usr/src/packages/BUILD/mono-3.4.0/mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseRequestProcessor.cs:26 

on

[OperationContract]
		[WebInvoke(UriTemplate = "attribute/{id}",
		           Method = "POST",
		           RequestFormat = WebMessageFormat.Json,
		           ResponseFormat = WebMessageFormat.Json)]
		void UpdateAttribute(Attribute attribute, string id);


fixed by updating file, see attached patch file
Comment 1 RGeoffrion 2014-06-20 14:32:05 UTC
Created attachment 7135 [details]
patch file
Comment 2 Miguel de Icaza [MSFT] 2015-02-23 22:30:28 UTC
In response to Atsushi's request, I tried creating a test case that would reproduce the issue, but I am failing to come up with a sample, I get crashes elsewhere -- likely, because I do not know how to configure WCF.

This is what I wrote:

		[Test]
		public void Connect () {
			var host = new WebServiceHost (typeof (MyService), new Uri ("http://localhost:30158/"));
			try {
				
				host.Open ();
				var cf = new ChannelFactory<IDemoService>(new WebHttpBinding(), "http://localhost:30158");
				cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
				var channel = cf.CreateChannel();
				channel.UpdateAttribute(null, "foo");
				Console.WriteLine();
			} finally {
				host.Close ();
			}
		}

		[ServiceContract]
		interface IDemoService {
			[OperationContract]
			[WebInvoke(UriTemplate = "{id}",
				   Method = "POST",
				   RequestFormat = WebMessageFormat.Json,
				   ResponseFormat = WebMessageFormat.Json)]
			void UpdateAttribute(Attribute attr, string id);
		}

		public class DemoService : IDemoService {
			public void UpdateAttribute(Attribute attr, string id)
			{
				Console.WriteLine ("got it");
			}
		}

But when I run this, I get the following:

1) MonoTests.System.ServiceModel.Web.WebServiceHostTest.Connect : System.ArgumentException : Non-empty namespace URI is not allowed in this XmlDictionaryWriter
at System.Runtime.Serialization.Json.JsonWriter.WriteStartElement (System.String prefix, System.String localName, System.String ns) [0x001b5] in /cvs/mono/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonWriter.cs:217
at System.Xml.XmlSimpleDictionaryWriter.WriteStartElement (System.String prefix, System.String localName, System.String ns) [0x00015] in /cvs/mono/mcs/class/System.Runtime.Serialization/System.Xml/XmlSimpleDictionaryWriter.cs:175
at System.Xml.XmlDictionaryWriter.WriteStartElement (System.String prefix, System.Xml.XmlDictionaryString localName, System.Xml.XmlDictionaryString namespaceUri) [0x00016] in /cvs/mono/mcs/class/System.Runtime.Serialization/System.Xml/XmlDictionaryWriter.cs:310
at System.ServiceModel.Channels.Message.WriteXsiNil (System.Xml.XmlDictionaryWriter writer) [0x00006] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:147
at System.ServiceModel.Channels.Message.WriteBodyContents (System.Xml.XmlDictionaryWriter writer) [0x00048] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:175
at System.ServiceModel.Channels.Message.WriteBody (System.Xml.XmlDictionaryWriter writer) [0x0001c] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:156
at System.ServiceModel.Channels.Message.OnWriteMessage (System.Xml.XmlDictionaryWriter writer) [0x00065] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:282
at System.ServiceModel.Channels.Message.WriteMessage (System.Xml.XmlDictionaryWriter writer) [0x00026] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:184
at System.ServiceModel.Channels.Message.WriteMessage (System.Xml.XmlWriter writer) [0x00000] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel.Channels/Message.cs:189
at System.ServiceModel.Channels.WebMessageEncoder.WriteMessage (System.ServiceModel.Channels.Message message, System.IO.Stream stream) [0x000ee] in /cvs/mono-master/mcs/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs:187
at System.ServiceModel.Channels.HttpRequestChannel.BeginProcessRequest (System.ServiceModel.Channels.HttpChannelRequestAsyncResult result) [0x0059d] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpRequestChannel.cs:203
at System.ServiceModel.Channels.HttpRequestChannel.BeginRequest (System.ServiceModel.Channels.Message message, TimeSpan timeout, System.AsyncCallback callback, System.Object state) [0x00012] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpRequestChannel.cs:338
at System.ServiceModel.Channels.HttpRequestChannel.Request (System.ServiceModel.Channels.Message message, TimeSpan timeout) [0x00000] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpRequestChannel.cs:72
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x0000b] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:584
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Description.OperationDescription od, Boolean isAsync, System.Object[]& parameters, System.ServiceModel.OperationContext context) [0x00069] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:536
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (System.Reflection.MethodBase method, System.String operationName, Boolean isAsync, System.Object[]& parameters, System.ServiceModel.OperationContext context) [0x0003a] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:501
at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (System.Reflection.MethodBase method, System.String operationName, Boolean isAsync, System.Object[]& parameters, System.ServiceModel.OperationContext context) [0x0000d] in /cvs/mono-master/mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs:482

I could use some help writing the repro test case.
Comment 3 Alexander Grep 2015-03-05 07:40:19 UTC
Would this be an acceptable test?

[Test]
public void Connect () {
            var host = new WebServiceHost (typeof (DemoService), new Uri
                ("http://localhost:30158/"));
            try {
                host.Open ();
                var wc = new WebClient();
                wc.DownloadString("http://localhost:30158/testData");
                Console.WriteLine();
            } finally {
                host.Close();
            }
        }

[ServiceContract]
    interface IDemoService {
        [OperationContract]
        [WebInvoke(UriTemplate = "/{testData}",
            Method = "GET",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json)]
        void UpdateAttribute(string testData);
    }

    public class DemoService : IDemoService {
        public void UpdateAttribute(string testData)
        {
            Console.WriteLine ("got it: "+testData);
        }
    }
Comment 4 Miguel de Icaza [MSFT] 2015-03-05 11:35:40 UTC
Thanks for the test!    Applied the fix to mono/master and the 4.0.0 branch.