ASP.NET 3.5 web site. You are trying to set the Response.Filter property and you are getting an HttpException with the message "Response filter is not valid."
There is a bug in ASP.NET 3.5 where you cannot set the Response.Filter property unless you read it first. When the Response.Filter property is first read, it instantiates some internal fields in the HttpWriter class.
Just read the property first so that it initializes the internal properties accordingly.
Dim f = Response.Filter ' Assumes Option Infer On
Response.Filter = New FilterStream(Response.OutputStream) ' Where FilterStream is your stream
var f = Response.Filter;
Response.Filter = new FilterStream(Response.OutputStream);