Calling Server.TransferRequest inside HttpApplication.EndRequest event throws InvalidOperationException, Handle is not initialized - by Sam Rueby

Status : 

  Duplicate<br /><br />
		This item appears to be a duplicate of another existing Connect or internal item.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 735533 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 4/4/2012 6:55:37 PM
Access Restriction Public
Moderator Decision Sent to Engineering Team for consideration

Description

This issue arrived after installing Visual Studio 2011 Ultimate Beta and .NET 4.5 Beta.

Attempted to test a Web Forms application that was developed and running successfully using Visual Studio 2010 and .NET 4 was immediately no longer functional. Nothing was updated. It does not target the new framework; It still targets .NET 4. Basically, nothing changed in-between installing Visual Studio 2011 Beta and .NET 4.5 Beta.

I've tracked this issue down to a call to Server.TransferRequest inside the HttpApplication's EndRequest event handler. This is all that needs to happen to get an IIS error page showing that an InvalidOperationException was thrown. Here is the Event Log details:

Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 4/4/2012 9:36:23 PM 
Event time (UTC): 4/5/2012 1:36:23 AM 
Event ID: c8bdc839a98f468f937a04f1099e381d 
Event sequence: 11 
Event occurrence: 1 
Event detail code: 0 
 
Application information: 
    Application domain: /LM/W3SVC/1/ROOT/WebApplication1-21-129780633805243780 
    Trust level: Full 
    Application Virtual Path: /WebApplication1 
    Application Path: C:\Users\Sam\Desktop\WebApplication1\WebApplication1\WebApplication1\ 
    Machine name: RS64
 
Process information: 
    Process ID: 1388 
    Process name: w3wp.exe 
    Account name: NT AUTHORITY\NETWORK SERVICE 
 
Exception information: 
    Exception type: InvalidOperationException 
    Exception message: Handle is not initialized.
   at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
   at System.Web.Hosting.PipelineRuntime.GetManagedPrincipalHandler(IntPtr pRootedObjects)
   at System.Web.Hosting.UnsafeIISMethods.MgdGetPrincipal(IntPtr pHandler, IntPtr& pToken, IntPtr& ppAuthType, Int32& pcchAuthType, IntPtr& ppUserName, Int32& pcchUserName, IntPtr& pManagedPrincipal)
   at System.Web.Hosting.IIS7WorkerRequest.GetUserPrincipal()
   at System.Web.Hosting.IIS7WorkerRequest.SynchronizeVariables(HttpContext context)
   at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)

 
 
Request information: 
    Request URL: http://localhost/WebApplication1/Error.aspx 
    Request path: /WebApplication1/Error.aspx 
    User host address: ::1 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: NT AUTHORITY\NETWORK SERVICE 
 
Thread information: 
    Thread ID: 13 
    Thread account name: NT AUTHORITY\NETWORK SERVICE 
    Is impersonating: False 
    Stack trace:    at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
   at System.Web.Hosting.PipelineRuntime.GetManagedPrincipalHandler(IntPtr pRootedObjects)
   at System.Web.Hosting.UnsafeIISMethods.MgdGetPrincipal(IntPtr pHandler, IntPtr& pToken, IntPtr& ppAuthType, Int32& pcchAuthType, IntPtr& ppUserName, Int32& pcchUserName, IntPtr& pManagedPrincipal)
   at System.Web.Hosting.IIS7WorkerRequest.GetUserPrincipal()
   at System.Web.Hosting.IIS7WorkerRequest.SynchronizeVariables(HttpContext context)
   at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
 
 
Custom event details: 
Sign in to post a comment.
Posted by Microsoft on 10/22/2012 at 5:40 PM
This issue has been fixed in .NET4.5 RTM.
Posted by Microsoft on 4/6/2012 at 12:47 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Sam Rueby on 4/5/2012 at 6:55 AM
I posted an example solution.
Posted by MS-Moderator07 [Feedback Moderator] on 4/5/2012 at 1:49 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to efficiently investigate and reproduce this issue, we are requesting additional information outlined below.

Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

We look forward to hearing from you with this information.

Microsoft Visual Studio Connect Support Team
Posted by MS-Moderator01 on 4/4/2012 at 7:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)