I have a HttpModule that act as a file upload module and after upgrading the .NET framework to 4.5 it works differently. With framework 4.0 the ReadEntityBody method filled the array with 256k but after the upgrade it will only return 16k. Any one else having this problem?
public void ProcessRequest(HttpContext context)
{
IServiceProvider provider = (IServiceProvider)context;
HttpWorkerRequest worker = (HttpWorkerRequest)provider.GetService(
typeof(HttpWorkerRequest));
byte[] data = new byte[256 * 1024];
int readData = worker.ReadEntityBody(data, data.Length);
// ......
}
We have run into this as well and have had to adjust. In fact in production we have found that often less than 16 KB can be returned as well, likely because less is available at a time in that environment.
Personally, I look at this as a 4.5 bug because the behavior of ReadEntityBody is not documented to return less than requested, so this is a breaking change from 4.0 to 4.5.
On the other hand, Stream.Read does document this behavior explicitly:
An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached.
So if you look at it from another angle, ReadEntityBody
has the same API as Stream.Read
and should be expected to have the same semantics. In that sense, 4.5 (webengine4.dll) merely changed the implementation while still fulfilling the same contract.
IMO, at worst it's a breaking change while at best it's a documentation bug. Some may consider it neither. You can decide.
I haven't felt motivated to file a bug. If it had worked this way from day 1, I probably would have considered it logical. It's just a shame that it broke in the intended 100% backward-compatible framework update. C'est la vie..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With