HttpRequestBase.GetBufferedInputStream not found w

2019-06-21 19:31发布

问题:

  1. Created a MVC5 WebAPI2 project using Visual Studio
  2. Created a basic JSON POST
  3. Post arguments cause HttpRequestBase.GetBufferedInputStream not found failure

Works on:

  1. Windows with visual studio

Fails on:

  1. OSX Xamarin
  2. Gentoo Xamarin

Test application: Mono MVC5 Web API2 Test Case

Test procedure:

  1. run the MVC application in xamarin
  2. On load the page will do a ajax post to the server.
  3. a) server will return a 500 error on failure

    b) console.log post arg on success

    Error: {
        "Message": "An error has occurred.",
        "ExceptionMessage": "Method 'HttpRequestBase.GetBufferedInputStream' not found.",
        "ExceptionType": "System.MissingMethodException",
        "StackTrace": " at System.Web.Http.WebHost.HttpControllerHandler+LazyStreamContent.get_StreamContent () [0x00008] in :0
    
                        at System.Web.Http.WebHost.HttpControllerHandler+LazyStreamContent.CreateContentReadStreamAsync () [0x00000] in :0
    
                        at System.Net.Http.HttpContent+c__async2.MoveNext () [0x00095] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/System.Net.Http/System.Net.Http/HttpContent.cs:159
    
                        --- End of stack trace from previous location where exception was thrown ---
    
                        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
    
                        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201
    
                        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
    
                        at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
    
                        at System.Runtime.CompilerServices.TaskAwaiter`1[System.IO.Stream].GetResult () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372
    
                        at System.Net.Http.HttpContentExtensions+d__0`1[System.Object].MoveNext () [0x00080] in :0
    
                        --- End of stack trace from previous location where exception was thrown ---
    
                        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
    
                        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201
    
                        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
    
                        at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
    
                        at System.Runtime.CompilerServices.TaskAwaiter`1[System.Object].GetResult () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372
    
                        at System.Web.Http.ModelBinding.FormatterParameterBinding+d__0.MoveNext () [0x000a5] in :0
    
                        --- End of stack trace from previous location where exception was thrown ---
    
                        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
    
                        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201
    
                        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
    
                        at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
    
                        at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:124
    
                        at System.Web.Http.Controllers.HttpActionBinding+d__0.MoveNext () [0x000a0] in :0
    
                        --- End of stack trace from previous location where exception was thrown ---
    
                        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
    
                        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201
    
                        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
    
                        at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
    
                        at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:124
    
                        at System.Web.Http.Controllers.ActionFilterResult+d__2.MoveNext () [0x0008f] in :0
    
                        --- End of stack trace from previous location where exception was thrown ---
    
                        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
    
                        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201
    
                        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
    
                        at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
    
                        at System.Runtime.CompilerServices.TaskAwaiter`1[System.Net.Http.HttpResponseMessage].GetResult () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372
    
                        at System.Web.Http.Dispatcher.HttpControllerDispatcher+d__1.MoveNext () [0x0018d] in :0 "
    }
    

回答1:

I too had this issue after promising a client I could write an ASP.NET 5 WepAPI application and deploy it in their Ubuntu 14.04 server. Yay.

Basically, you need to upgrade to a bleeding edge version to get this feature supported correctly. On Ubuntu, you can use the official nightlies repository. Note however that, on Ubuntu, you may need to list all installed packages using dpkg and do a grep for mono and make sure that you fully purge previous installations (manual and package-manager installed alike). You'll have this issue especially if you've installed from source.

Again, in the context of Ubuntu, you can use whereis mono to track down everywhere that it might be. This must be done because otherwise you're going to have conflicts, as you'll have multiple versions of mono competing in your ENV.

For OSX and other platforms, you can find official information and links to nightlies here.

Again, for Ubuntu, here's how to add the binary nightlies to your sources:

echo "deb http://download.mono-project.com/repo/debian nightly main" | sudo tee /etc/apt/sources.list.d/mono-nightly.list
sudo apt-get update


回答2:

This API was added just recently into Mono (first version to have it is 4.3.2.467). Then please upgrade your Mono version to be able to use this feature.

(Or use ASP.NET Core, which renders WebAPI infrastructure obsolete, and also runs in Linux out of the box without the need of Mono, AFAIU.)

NB: Yes, 4.3.x is too bleeding edge at the time of this writing, then you might need to upgrade Mono yourself outside the boundaries of your distribution or accessing unstable channels. Or build Mono yourself, but under no circumstance follow blindly unofficial guides about how to compile Mono yourself, or install some random packages (unless you know what you're doing). You should always refer to packages signed-off by the official sources, such as the nightlies ones, or use official guides on how to install versions of mono in parallel (otherwise you may run into troubles about conflicting distro packages, or wrong prefix being used for installation that doesn't work out of the box, etc).



回答3:

Context to reproduce is described in the first post.

The main problem is that "HttpRequestBase.GetBufferedInputStream" is not available in Mono version (4.2).

Async operations are not fully implemented in mono mcs, as written on their blog. The workaround I did for my project is to use HttpContect.Current.Request.InputStream to get posted data and create an extension class inspired by aspnetwebstack repository to serialize.

Then compilation directive for mono/windows

Source and example is available here.

It work on my server mono v4.2.x (Debian 8), tested on Windows and Osx.



回答4:

I had this same error on Ubuntu 16.04. I fixed it by upgrading my Mono installation. The mono project's download page has instructions for how to do that for different OSes.

To upgrade, I ran these commands:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/mono-official.list
sudo apt-get update
sudo apt-get upgrade

[FromBody] works fine after that.