title: An attribute argument must be a constant expression, typeof expression, or array creation expression of an attribute parameter type
body: <p>I have these two line:</p>
  
  <pre><code>[AccessDeniedAuthorize(new string[] { "MIS", "Test" })]
  
  [AccessDeniedAuthorize(DAL.RoleHandler.GetRolesForTcode("testMenu"))]
  </code></pre>
  
  <p>But second line has this error:</p>
  
  <blockquote>
    <p>An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type</p>
  </blockquote>
  
  <p>But <code>GetRolesForTcode</code> returns <code>string[]</code> too, why the error?</p>
  
  <pre><code>public class AccessDeniedAuthorizeAttribute : AuthorizeAttribute
  {
      public override void OnAuthorization(AuthorizationContext filterContext)
      {
          base.OnAuthorization(filterContext);
  
          if (filterContext.Result is HttpUnauthorizedResult)
          {
              filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary { { "Controller", "AccessDenied" }, { "Action", "Index" } });
          }
      }
  
      public AccessDeniedAuthorizeAttribute(string[] roles)
      {
          this.Roles = string.Join(",", roles);
      }
  }
  
  public class RoleHandler
  {
      public static string[] GetRolesForTcode(string tCode)
      {
          using (var db = new Models.VMIEntities())
          {
              var roles = db.T_Auth_Role_Master
                  .Where(role =&gt; string.Compare(role.obj, "t_code", StringComparison.OrdinalIgnoreCase) == 0)
                  .Where(role =&gt; string.Compare(role.authobj_value, tCode, StringComparison.OrdinalIgnoreCase) == 0)
                  .Select(role =&gt; role.role);
              return roles.ToArray();
          }
      }
  }
  </code></pre>