Bug 22764 - HTTP POST ContentType is null instead of one sent by client in case of MultipartFormDataContent
Summary: HTTP POST ContentType is null instead of one sent by client in case of Multip...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.8.0
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-09-08 21:49 UTC by rndXamUser
Modified: 2014-12-01 07:08 UTC (History)
3 users (show)

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


Attachments
Self Testing Project to test bug (5.08 MB, application/zip)
2014-09-09 23:34 UTC, rndXamUser
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 rndXamUser 2014-09-08 21:49:29 UTC
System.Net.Http.MediaTypeHeaderValue DataContent.Headers.ContentType is null in Web API Controller Action

I discovered this bug as I was having following issue.

http://stackoverflow.com/questions/25734727/multipart-web-api-action-in-owin-self-host-inconsistency


Headers.ContentType in Web API Action are receiving the request is null instead of actual Content Type set by the client.

This only seems to be occur after I get the request in my web api action. I debugged both at same point in action and VS 2013 has it set to one sent by user but Mono (Mono JIT compiler version 3.10.1) has set it to null. However, the default MultipartFormDataContent initializes it right in both VS2013 and Mono as I tested using 


            var testingMultipartFormDataContent = new MultipartFormDataContent();

in both VS2013 and Mono it is set.
This means somewhere it is being reset somewhere as it goes inside the following if inside the web api controller action.

      if (Request.Content.Headers.ContentType == null)
            {
                Console.WriteLine("header is null");
            }

Hopefully, y'all will fix this bug. :)
Comment 2 Marek Safar 2014-09-09 03:53:48 UTC
It's quite hard to guess where the bug is. Could you attach self contained repro for the issue
Comment 3 rndXamUser 2014-09-09 07:51:19 UTC
I've emailed you the whole program, if that's what you meant.
Comment 4 Marek Safar 2014-09-09 17:42:10 UTC
Fixed in master
Comment 5 rndXamUser 2014-09-09 23:34:10 UTC
Created attachment 7976 [details]
Self Testing Project to test bug

Just navigate to http://localhost:1234/api/upload to test.
Comment 6 rndXamUser 2014-09-09 23:34:24 UTC
I"m not sure whether to call it fixed or not. I just latest from git.

$ git rev-parse HEAD
5e9eba8ffbb5b1bf9444a9308a0e74cca7f29e32

https://github.com/mono/mono/commit/5e9eba8ffbb5b1bf9444a9308a0e74cca7f29e32

and installed it.
Mono JIT compiler version 3.10.1 (master/5e9eba8 Tue Sep  9 20:19:57 EDT 2014)

I'm getting similar error. I've also made a self contained project which acts as expected in Windows but not in Mono.
Comment 7 rndXamUser 2014-09-09 23:35:08 UTC
I'm not sure if it's the exact same bug, or should I reopen this or not. I reopened this just in case.
Comment 8 rndXamUser 2014-09-09 23:37:06 UTC
This is the error I get now.
{
Message: "An error has occurred.",
ExceptionMessage: "Error writing MIME multipart body part to output stream.",
ExceptionType: "System.IO.IOException",
StackTrace: " at System.Net.Http.HttpContentMultipartExtensions+<MultipartReadAsync>d__8.MoveNext () [0x00000] in <filename unknown>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 at System.Net.Http.HttpContentMultipartExtensions+<ReadAsMultipartAsync>d__0`1[BugTestSelfContained.Controllers.NamedMultipartFormDataStreamProvider].MoveNext () [0x00000] in <filename unknown>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <filename unknown>:0 at BugTestSelfContained.Controller.UploadController+<Post>c__async0.MoveNext () [0x00000] in <filename unknown>:0 ",
InnerException: {
Message: "An error has occurred.",
ExceptionMessage: "The stream provider of type 'NamedMultipartFormDataStreamProvider' threw an exception.",
ExceptionType: "System.InvalidOperationException",
StackTrace: " at System.Net.Http.MimeBodyPart.GetOutputStream () [0x00000] in <filename unknown>:0 at System.Net.Http.MimeBodyPart+<WriteSegment>d__0.MoveNext () [0x00000] in <filename unknown>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <filename unknown>:0 at System.Net.Http.HttpContentMultipartExtensions+<MultipartReadAsync>d__8.MoveNext () [0x00000] in <filename unknown>:0 ",
InnerException: {
Message: "An error has occurred.",
ExceptionMessage: "The given key was not present in the dictionary.",
ExceptionType: "System.Collections.Generic.KeyNotFoundException",
StackTrace: " at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (System.Collections.Generic.TKey key) [0x00000] in <filename unknown>:0 at System.Net.Http.Headers.HttpHeaders.GetValue[ContentDispositionHeaderValue] (System.String name) [0x00000] in <filename unknown>:0 at System.Net.Http.Headers.HttpContentHeaders.get_ContentDisposition () [0x00000] in <filename unknown>:0 at System.Net.Http.MultipartFormDataStreamProviderHelper.IsFileContent (System.Net.Http.HttpContent parent, System.Net.Http.Headers.HttpContentHeaders headers) [0x00000] in <filename unknown>:0 at System.Net.Http.MultipartFormDataStreamProvider.GetStream (System.Net.Http.HttpContent parent, System.Net.Http.Headers.HttpContentHeaders headers) [0x00000] in <filename unknown>:0 at System.Net.Http.MimeBodyPart.GetOutputStream () [0x00000] in <filename unknown>:0 "
}
}
}
Comment 9 Marek Safar 2014-09-10 03:49:17 UTC
It's different issue but I've fixed it in master as well.
Comment 10 rndXamUser 2014-09-10 10:44:51 UTC
Thank you based Marek. This fixes everything. :)
Comment 11 Mohit Kheterpal 2014-12-01 07:08:09 UTC
As per comment 10, this issue is now fix. 

Hence closing this issue.