ASP.NET - The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))

Asked By sunny C on 02-Jul-12 12:49 PM
Hi There,


I am getting below exception when i clicked a linkbutton in Telerik Grid which will open a new window with PDF file document. It was working in development environment (windows 7 + IIS 6.1) but when I deploy this on Windows 2008 + IIS 7 i am getting below exception. I am using asp.net 4.0.


Exception: 


The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE)) 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 


Exception Details: System.Runtime.InteropServices.COMException: The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))
Source Error: 


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  


Stack Trace: 
[COMException (0x80070006): The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))]
[HttpException (0x80004005): An error occurred while communicating with the remote host. The error code is 0x80070006.]
   System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect) +3084029
   System.Web.Hosting.IIS7WorkerRequest.FlushCore(Boolean keepConnected, Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32[] bodyFragmentTypes) +8746160
   System.Web.Hosting.IIS7WorkerRequest.FlushCachedResponse(Boolean isFinal) +373
   System.Web.HttpResponse.UpdateNativeResponse(Boolean sendHeaders) +434
   System.Web.HttpRuntime.FinishRequestNotification(IIS7WorkerRequest wr, HttpContext context, RequestNotificationStatus& status) +121

My code below: 

Context.Response.Clear();
                Response.AppendHeader("Content-Disposition", "inline; filename=" + fileInfo);
                Context.Response.ContentType = "application/pdf";
                Context.Response.TransmitFile(fileInfo);

i tried adding response.flush(), response.close() but of no use.

Can you just let me know is there anything else that i can do? I didn't try the option of reinstalling ASP.NET 4.0 yet.

Thanks in advance,
Sunny
Robbe Morris replied to sunny C on 02-Jul-12 05:52 PM
Wrap a try/catch block around these lines:

Context.Response.Clear();
                Response.AppendHeader("Content-Disposition", "inline; filename=" + fileInfo);
                Context.Response.ContentType = "application/pdf";
                Context.Response.TransmitFile(fileInfo);