locked
System.Reflection.MethodInfo.GetCurrentMethod.Name now throwing "Cannot Evaluate Security Function" error in Try...Catch RRS feed

  • Question

  • For the last five months I've been working on an ASP.NET 4.5 project using VS2013 Ultimate and Visual Basic. I've been developing on my location machine, using local ISS and a networked SQL 2012 server. 

    I've been using the following in this dev environment to catch mistakes since I'm new at ASP.NET:

    Catch ex As Exception
                Trace.Warn(ex.ToString())
                If ShowAlerts Then System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert(""" + currentMethod + ": " + isNull(ex.Message) + """)</SCRIPT>")
            End Try

    However, in the last couple weeks it has started to throw the following error: "Cannot evaluate a Security Function" 

    This happens every time methodinfo is called inside that try...catch. However, if I declare a string and assign it inside the function, but above the catch:

    DimcurrentMethod As String

    Try

           currentMethod = System.Reflection.MethodInfo.GetCurrentMethod.Name

           {insert code here}

    Catchex As Exception

                Trace.Warn(ex.ToString())

                IfShowAlerts ThenSystem.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert("""+ currentMethod + ": "+ isNull(ex.Message) + """)</SCRIPT>")

            End Try


    I no longer get an error. But I don't want to be calling methodinfo unless I need to (it is very expensive, after all), and I really dislike the idea of creating custom error messages for every single method so I know what method triggered the alert message.

    Similarly, an associate of mine linked me that he had a similar problem start in the last week of January 2015, with MethodInfo  sing the watch functionality of VS. He posted it at

    https://social.msdn.microsoft.com/forums/vstudio/en-US/008a06ed-92bf-40b4-8bc7-a6286a394ec8/error-cannot-evaluate-a-security-function

    I've found similar posts as far back as 2008 saying that you need to change permissions. That has not seemed to help. And it does not explain why I have suddenly had the error start only a few weeks ago after 4 months of not having the error.

    Does anyone know what I could try to resolve this? 

    Thanks!

    --Cralis


    • Edited by Cralis7 Tuesday, February 24, 2015 5:56 PM fixed typo
    Tuesday, February 24, 2015 5:50 PM

Answers

  • Check if the alternative works:

        Dim currentMethod As String = New StackFrame().GetMethod().Name

    • Proposed as answer by Barry Wang Wednesday, February 25, 2015 9:06 AM
    • Unproposed as answer by Barry Wang Wednesday, February 25, 2015 9:07 AM
    • Marked as answer by Fred Bao Friday, March 6, 2015 10:03 AM
    Wednesday, February 25, 2015 7:41 AM

All replies

  • Check if the alternative works:

        Dim currentMethod As String = New StackFrame().GetMethod().Name

    • Proposed as answer by Barry Wang Wednesday, February 25, 2015 9:06 AM
    • Unproposed as answer by Barry Wang Wednesday, February 25, 2015 9:07 AM
    • Marked as answer by Fred Bao Friday, March 6, 2015 10:03 AM
    Wednesday, February 25, 2015 7:41 AM
  • That worked! Thank you. I don't know if there are any implications (yet), but it does in-fact work inthe Try...Catch, inside the catch clause. 

    Now, why does System.Reflection.MethodInfo suddenly fail where it has not failed for the last 4 years?


    • Edited by Cralis7 Friday, February 27, 2015 11:53 PM
    Friday, February 27, 2015 11:51 PM