A mild Caveat while reading the InputStream in a Custom TFS Plugin if you’re using Git as Source Control

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:


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”
Git Push Error

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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s