I have an action method in my MVC app which returns a FileResult
based on a file saved as a blob in the database. The root problem is that for some file types, requesting the file returns an empty file, even though I've verified that the database has the correct contents encoded in the Content
column.
However, the really odd part is how difficult it is to me to pin down exactly what's causing this. Here's a few gotchas that I can't make sense of:
Downloading text files, like *.txt
and *.csv
returns an empty file, while downloading e.g. a PDF works correctly
This only happens on our CI server, and I can't reproduce it on my local workstation. These are the only differences I can think of:
How do I trouble-shoot this? What could cause it?
OK, as expected from how the question is written, this problem was highly specific to our setup, so the actual fix for me is probably not that interesting. However, in order to (hopefully) be helpful to someone else stumbling over similar problems and finding their way here (welcome!), I'll post a summary of the troubleshooting campaign that eventually helped me find the root cause and fix it.
tl;dr: The problem in this case was custom HTTP compression - when turned off, everything worked.
Are you sure that your local settings reflect those of the production/staging environment? Not just that they're supposed to, but that they actually do - if you're having problems reproducing the error, then it's almost certainly due to something here.
Some things that could vary:
Debug
/Release
/OtherConf
setting in build scripts? In IDE?Web.config
: we have a local Web.config
file that is used by devs, but create the production version in our build script based on a template Web.config.erb
. Do all versions match?text/html
data (or whatever it is that is failing)? Do you use the same settings locally?Still haven't found anything? Well, there are other ways to look for differences than manually.
Try to side-step the CI build process, and publish your local (working) version of the app to the server. Hopefully, it can reveal some discrepancy that you missed.
If you still cannot find a setting that differs, and still cannot reproduce it locally, can you debug on the server? If you don't have VS installed on the server, maybe give Remote debugging a try. (I didn't manage to get it working before I found the problem, mainly because it was excruciatingly slow on our setup, but it's well worth a try...)