This is related to the implementation of a custom plugin using ITeamFoundationRequestFilter.
You can go to the first part of my post series by clicking the link below:
https://conradoclarkdeveloper.com/2015/03/02/iteamfoundationrequestfilter-part1-tfs
This post is a fix to a possible problem while reading requests if you’re using Git.
The problem with InputStream
In my first posts about implementing ITeamFoundationRequestFilter, I’m using HttpContext.Current.Request.InputStream to read the contents of the request. It happens so that, depending on the implementation, this may break Git functionality. If you access the InputStream before trying to push content to git, the following error is shown:
“This method or property is not supported after HttpRequest.Form, Files, InputStream, or BinaryRead has been invoked”
The method being called is the one in the line below:
Stream bufferlessInputStream = context.Request.GetBufferlessInputStream(true);
Which is being called by the class ReceivePackHandler (Microsoft.TeamFoundation.Git.Server), responsible for parsing and handling content pushed to Git.
On my examples this doesn’t happen because I’m checking the url for a specific service that I have to intercept. But it may help someone that’s struggling with this issue.
All in all, remember to only access the InputStream if you’re absolutely sure that you need to intercept the request to avoid undesirable side-effects.