FilePathResult with network path throws COMException (The handle is invalid)

3

I am using the FilePathResult like so:

return new FilePathResult(path, "text/xml");

My path is a path elsewhere on our network. This results in a server error. When I check the event log on the server I can see this error entry:

TransmitFile failed. File Name: \\our\path\to\the\file\filename.dfxp, HRESULT: 0x80070005

At the same time a warning is logged in the event viewer as well:

Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 5/30/2013 4:05:03 PM 
Event time (UTC): 5/30/2013 9:05:03 PM 
Event ID: d77e5b799b87455f9f4daa7367f1bad2 
Event sequence: 33 
Event occurrence: 1 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/3/ROOT-1-130144212630349792 
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: C:\inetpub\wwwroot\my.site.folder\ 
    Machine name: MyMachine

Process information: 
    Process ID: 3408 
    Process name: w3wp.exe 
    Account name: IIS APPPOOL\my.site.name

Exception information: 
    Exception type: COMException 
    Exception message: The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))



Request information: 
    Request URL: http://my.site.com/Download/fca4fd06-d942-4ee8-8fe3-7ec7aa26938f 
    Request path: /Download/fca4fd06-d942-4ee8-8fe3-7ec7aa26938f 
    User host address: 10.0.70.17 
    User: my@user.com
    Is authenticated: True 
    Authentication Type: Forms 
    Thread account name: OURDOMAIN\SA-ACCOUNT

Thread information: 
    Thread ID: 14 
    Thread account name: OURDOMAIN\SA-ACCOUNT
    Is impersonating: False 
    Stack trace:

My service account that the application is running under has read access to the folder location. I didn't find this problem mentioned elsewhere in the ASP.NET MVC world so I thought I would ask here.

asp.net-mvc
exception
networking
comexception

1 Answer

4

It may be too early to tell, however, it seems as though changing from a FilePathResult to a FileContentResult has fixed the problem.

var fileBytes = System.IO.File.ReadAllBytes(fileInfo.FullName);
return new FileContentResult(fileBytes, "text/xml")

I'm not sure what FilePathResult ends up doing internally, but, reading the file with ReadAllBytes seems to avoid the issue.

answered on Stack Overflow May 31, 2013 by Justin Helgerson

User contributions licensed under CC BY-SA 3.0