Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error writing headers when returning FileInfo HttpResult

I'm on Mono 3.x, on Mac OSX and I'm trying to return a static file with ServiceStack. The code is (and should be, according to other answers) very straightforward:

public class AirPlayService : Service
{
    public object Get(Movie request)
    {
        var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Movies", request.Name);

        var file = new FileInfo(fileName);
        return new HttpResult(file, asAttachment:false); 
    }
}

The Movie object is a simple DTO.
When my Get() gets called I see the following error in my Terminal window:

ERROR: Error occured while Processing Request: [IOException] Write failure, Exception: Write failure INFO: Failed to write error to response: {0}, Exception: Cannot be changed after headers are sent. ERROR: Error in HttpListenerResponseWrapper: Write failure, Exception: Write failure

ServiceStack is version 3.9.35; Mono JIT compiler version 3.0.3 (master/39c48d5 Tue Jan 8 12:12:24 EST 2013); .NET 4.5.

What am I doing wrong?

like image 289
Richard Avatar asked Nov 13 '22 11:11

Richard


1 Answers

i had the same problem on my dad's computer, it worked for me by using :

public class AirPlayService : Service
{
    public object Get(Movie request)
    {
        var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ( "Movies", request.Name);

        var file = new FileInfo(fileName);
        return new HttpResult(file, asAttachment:false); 
like image 164
ValterZHD Avatar answered Nov 15 '22 05:11

ValterZHD