U4-6990 - Error when using Umbraco task scheduler

Created by David Verberckmoes 19 Aug 2015, 14:44:25 Updated by Andreas Kaltenhuber 24 Sep 2015, 09:12:47

Calling a page from the taskScheduler returns an exception: System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type

The cause is that the Method for the HttpRequestMessage should be HttpMethod.Post instead of HttpMethod.Get, see MSDN: https://msdn.microsoft.com/en-us/library/d4cek6cc%28v=vs.110%29.aspx


Sebastiaan Janssen 19 Aug 2015, 14:47:50

Really? Because we're using it just fine. The thing is.. you need to implement the URL you're calling to accept the GET verb, instead of the POST verb. So if you can call the URL you're using in the task scheduler from your browser then it will also work in the task scheduler. Does that help?

Pawel Bres 20 Aug 2015, 11:58:58

@sebastiaan I have same issue with ashx handler which I can call via browser with no problems. Any idea ?

Sebastiaan Janssen 20 Aug 2015, 12:08:18

I would recommend you copy this GetTaskByHttpAync code, pass in your ashx URL and try to see what the problem is:


Pawel Bres 20 Aug 2015, 12:44:43

@sebastiaan I did and it works ok when I put it like this:

var request = new HttpRequestMessage() { RequestUri = new Uri(url), Method = HttpMethod.Get, //Content = new StringContent(string.Empty) };

or when I switch method to Post

Sebastiaan Janssen 20 Aug 2015, 13:26:19

I wonder why your ashx doesn't accept an empty content request. Can you have a look in fiddler or in your network tab in your browser debug tools to see what content gets sent when you disable that line?

Pawel Bres 20 Aug 2015, 13:50:44

@sebastiaan when I call it with Post method and with Content = new StringContent(string.Empty) I get: Entity: Content-Length: 0 Content-Type: text/plain; charset=utf-8

when I call it with Get method and with Content = new StringContent(string.Empty) I get an exception "Cannot send a content-body with this verb-type"

when I call it with Get and without any Content there is no Entity in request at all. So it seams that there is difference between no content and empty content.

Also in scenario where exception is thrown there is no request in fiddler at all and my ashx in not called, so I guess it's not problem related to ashx handler.

Stephan 24 Aug 2015, 15:16:07

The problem seems to be that our code uses the GET Method yet sets the Content of the request... to an empty string, but nevertheless. We should not set Content. MSDN says that the ProtocolViolationException can be thrown if method is GET and content-length is greater ''or equal to'' zero.

That was not causing errors in the past, though. Could it be a change in the .NET framework? @pbres : what framework version are you running? 4.6?

Pawel Bres 24 Aug 2015, 21:47:51

@zpqrtbnk I think it's exactly as you said. I'm using 4.5.

Stephan 25 Aug 2015, 06:36:44

Mmm... I was hoping for a change in 4.6... because we've been running on 4.5 for ages without issues. Unless 4.5.2 introduces something? Let me check...

Pawel Bres 25 Aug 2015, 07:06:48

Maybe there was some change in System.Net.Http ?

Stephan 25 Aug 2015, 09:51:54

The following code ''does'' fail on 4.6 (ie where Environment.Version is 4.0.30319.42000):

using (var wc = new HttpClient()) { var request = new HttpRequestMessage() { RequestUri = new Uri("http://www.example.com/"), Method = HttpMethod.Get, Content = new StringContent(string.Empty) };

var result = wc.SendAsync(request).Result; Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }

It works only if the Content = ... line is commented out.

4.x framework updates being in-place updates, I am not sure how I can test on 4.5 now that I have 4.6 installed. Anybody having a non-4.6 machine available where they could run the test and report?

Anyways... we can make things much simpler:

using (var wc = new HttpClient()) { var result = wc.GetAsync("http://www.example.com/").Result; Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }

That's what we should use in ScheduledTasks I guess.

Stephan 25 Aug 2015, 10:01:14

Pushed eec11c8e5f37ccd4e39c7cab0adb890968883145 that should fix the issue whatever the framework version. Any chance you can test?

Sebastiaan Janssen 25 Aug 2015, 10:09:57

For an easy way to test, wait until this build finishes in a few minutes and then you can download the build from the artifacts: https://ci.appveyor.com/project/SebastiaanJanssen/umbraco-cms-hs8dx/build/1160/artifacts

Pawel Bres 25 Aug 2015, 11:38:19

sounds great! I will test it, I have v4.0.30319 on my machine

Stephan 25 Aug 2015, 12:06:57

AFAIK 4.0.30319 is 4.x and the last number tells 4.5 from 4.6... 42000 is for 4.6.

Pawel Bres 25 Aug 2015, 12:24:19

You are right, I have exactly 4.5.2 (4.0.30319.34209)

Stephan 26 Aug 2015, 12:50:48

Tested OK.

Andreas Kaltenhuber 21 Sep 2015, 11:39:13

Just upgraded an umbraco 7.2.8 installation to the latest 7.3.0 RC and i still get the same error:

2015-09-21 13:29:06,801 [74] ERROR Umbraco.Web.Scheduling.ScheduledTasks - An error occurred calling web task for url: http://localhost:56577/umbraco/api/sync/test System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type. at System.Net.HttpWebRequest.CheckProtocol(Boolean onRequestStream) at System.Net.HttpWebRequest.BeginGetRequestStream(AsyncCallback callback, Object state) az System.Net.Http.HttpClientHandler.StartGettingRequestStream(RequestState state) az System.Net.Http.HttpClientHandler.PrepareAndStartContentUpload(RequestState state) --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Umbraco.Web.Scheduling.ScheduledTasks.d__9.MoveNext()

Pawel Bres 21 Sep 2015, 12:42:04

@Andreas.Kaltenhuber I think it will be released in final build. I have rebuilded 7.2.8 and if you would like I can send it to you

Andreas Kaltenhuber 24 Sep 2015, 09:12:47

You're right, totally forgot about that!! Just complied from the source and it works.

Priority: Normal

Type: Bug

State: Fixed

Assignee: Stephan

Difficulty: Easy


Backwards Compatible: True

Fix Submitted:

Affected versions: 7.3.0, 7.2.8

Due in version: 7.3.0


Story Points: