[System.Security.SecurityCritical]  // auto-generated
#pragma warning disable 618
        internal static Exception MakeSecurityException(AssemblyName asmName, Evidence asmEvidence, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed)
#pragma warning restore 618
        {
#if FEATURE_CAS_POLICY
            // See if we need to throw a HostProtectionException instead
            HostProtectionPermission hostProtectionPerm = permThatFailed as HostProtectionPermission;
            if (hostProtectionPerm != null)
            {
                return(new HostProtectionException(GetResString("HostProtection_HostProtection"), HostProtectionPermission.protectedResources, hostProtectionPerm.Resources));
            }

            // Produce relevant strings
            String     message = "";
            MethodInfo method  = null;
            try
            {
                if (granted == null && refused == null && demand == null)
                {
                    message = GetResString("Security_NoAPTCA");
                }
                else
                {
                    if (demand != null && demand is IPermission)
                    {
                        message = String.Format(CultureInfo.InvariantCulture, GetResString("Security_Generic"), demand.GetType().AssemblyQualifiedName);
                    }
                    else if (permThatFailed != null)
                    {
                        message = String.Format(CultureInfo.InvariantCulture, GetResString("Security_Generic"), permThatFailed.GetType().AssemblyQualifiedName);
                    }
                    else
                    {
                        message = GetResString("Security_GenericNoType");
                    }
                }

                method = SecurityRuntime.GetMethodInfo(rmh);
            }
            catch (Exception e)
            {
                // Environment.GetResourceString will throw if we are ReadyForAbort (thread abort).  (We shouldn't do a Contract.Assert in this case or it will lock up the thread.)
                if (e is System.Threading.ThreadAbortException)
                {
                    throw;
                }
            }

/*            catch(System.Threading.ThreadAbortException)
 *          {
 *              // Environment.GetResourceString will throw if we are ReadyForAbort (thread abort).  (We shouldn't do a BCLDebug.Assert in this case or it will lock up the thread.)
 *              throw;
 *          }
 *          catch
 *          {
 *          }
 */
            // make the exception object
            return(new SecurityException(message, asmName, granted, refused, method, action, demand, permThatFailed, asmEvidence));
#else
            return(new SecurityException(GetResString("Arg_SecurityException")));
#endif
        }