legacyUnhandledExceptionPolicy enabled="true" doesn't prevent ASP.NET application restarting.

Last post 03-27-2007 9:26 AM by MNF. 1 replies.

Sort Posts:

  • legacyUnhandledExceptionPolicy enabled="true" doesn't prevent ASP.NET application restarting.

    03-08-2007, 6:59 PM
    • Member
      259 point Member
    • MNF
    • Member since 07-24-2005, 8:15 PM
    • Posts 72
    We have an ASP.NET application in production(running IIS6 on Windows 2003 server) that sometimes has ".NET Runtime 2.0 Error Reporting" due to exceptions in background threads. We wanted to ignore the errors(while we will fix the cause) and specified

      <runtime>

         <legacyUnhandledExceptionPolicy enabled="true" />

      </runtime>

    in application web.config. Unfortunately it didn't help- ASP.NET application still keep restarting, which causes "session expired" behavior.

    I am able to reproduce this on a sample page.
    On load the page saves time to Session, then started background thread, that should will exception in 5 sec.

    There is also a button to read the Session value, and user can click the button.
    During the first 5 sec clicking the button retrieves Session Value correctly, after 5 sec the click causes some delay.
    If teh user keep clicking the button, it still continue to work (probably for a minute), then it reports that

    Object reference not set to an instance of an object. - which means that session information is lost.
    As I understand, after the unhandled exception is thrown, IIS starts a new working application domaiin,but keep old for a minute, than replace with the new, killing session state.

    By the was, if legacyUnhandledExceptionPolicy set to "false", click after 5 sec causes a long delay and then the same error, indicating that
    session state is lost, is shown.


    Can we do something to ignore exceptions in background threads, as legacyUnhandledExceptionPolicy enabled="true" suppose to do?

    The sample page, that I was using for testing is the following:

    <%@ Page Language="C#" AutoEventWireup="true"  %>

    <%@ Import namespace="System.Threading"  %>

    <%@ Import namespace="System.Diagnostics"  %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat=server >

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

                Session["TestKey"] = DateTime.Now.ToLongTimeString();

                Thread myThread = new Thread(new ThreadStart(DoWork));

                myThread.Start();

                lblTime.Text = "Page Loaded at " + Session["TestKey"].ToString();

            }

        }

        public void DoWork()

        {

           System.Diagnostics.Trace.WriteLine("Working thread...");

           Thread.Sleep(5000);//5 sec

           throw new ApplicationException("ThrowException =true");

        }

     

        protected void btnGetSession_Click(object sender, EventArgs e)

        {

            lblFromSession.Text = "From Session Page Loaded at " + Session["TestKey"].ToString();

        }

     

        </script>

     

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

        <title>Untitled Page</title>

    </head>

    <body>

        <form id="form1" runat="server">

        <div>

          Throw     Exception test&nbsp;

            <asp:Label ID="lblTime" runat="server" Text="Label"></asp:Label>

            <br />

            <asp:Label ID="lblFromSession" runat="server" Text=""></asp:Label>

            <br />

            <asp:Button ID="btnGetSession" runat="server" OnClick="btnGetSession_Click" Text="Get Session" /></div>

        </form>

    </body>

    </html>

     

  • Re: legacyUnhandledExceptionPolicy enabled="true" doesn't prevent ASP.NET application restarting.

    03-27-2007, 9:26 AM
    • Member
      259 point Member
    • MNF
    • Member since 07-24-2005, 8:15 PM
    • Posts 72

    Microsoft replied  at MS feedback site:

    Some of these configuration settings are not very well documented. The setting that you would like to change is only valid in the aspnet.config file. The file is passed to CorBindToRuntimeHost when ASP.NET loads the CLR. If you make a change similar to the one below and restart the worker process, everything should work as expected.

    C:\>type %WINDIR%\Microsoft.NET\Framework\v2.0.50727\aspnet.config
    <?xml version="1.0" encoding="UTF-8" ?>
    <configuration>
        <runtime>
            <legacyUnhandledExceptionPolicy enabled="true" />
            <legacyImpersonationPolicy enabled="true"/>
            <alwaysFlowImpersonationPolicy enabled="false"/>
            <SymbolReadingPolicy enabled="1" />
        </runtime>
    </configuration>

Page 1 of 1 (2 items)