Response.Redirect Inside Try/Catch Block
<p>While trying to <code>convert strting into enum</code> in Asp.NET webApplication. </p>

<p>Code -</p>

<pre><code>enum MyEnum
{
    field1,
    field2,
    field3
}

string strField1 = "field1";
MyEnum parsedEnum = (MyEnum)Enum.Parse(typeof(MyEnum), strField1);
</code></pre>

<p>I encounter following error -</p>

<blockquote>
  <p>Unable to evaluate expression because the code is optimized or a
  native frame is on top of the call stack.</p>
</blockquote>

<p>What am I missing.</p>

<p>EDIT: Updated Code:</p>

<p>I have been using this enum to redirect user to other page, by validating CommandArgument of the button. I obtain this error while debugging the solution, other-wise the code works fine.</p>

<pre><code>&lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;asp:Button Text="Redirect" ID="btnRedirect" OnClick="btnRedirect_Click" CommandName="field1" runat="server" /&gt;
    &lt;/div&gt;
    &lt;/form&gt;



    protected void btnRedirect_Click(object sender, EventArgs e)
    {            
        var btn = sender as Button;
        var cmdName = btn.CommandName; //field1
        MyEnum parsedEnum = (MyEnum)Enum.Parse(typeof(MyEnum), cmdName);

        try
        {
            switch (parsedEnum)
            {
                case MyEnum.field1:
                    Response.Redirect("WebForm1.aspx");
                    break;
                case MyEnum.field2:
                    Response.Redirect("WebForm2.aspx");
                    break;
                case MyEnum.field3:
                    Response.Redirect("WebForm3.aspx");
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            var err = ex.Message;                
        }
    }
</code></pre>
