Attribute Expression Must be a Constant - Problem

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Attribute Expression Must be a Constant - Problem


    I decorated my assembly with the stuff below, but the compiler
    complains "An attribute argument must be a constant expression, typeof
    expression or array creation expression".

    I want my assembly to obey CAS and only read and write to its own
    application directory as well as %temp%. Any suggestions?

    Thanks.


    [assembly:
    FileIOPermissionAttribute( SecurityAction.RequestMinimum,
    Read=System.IO.Directory.GetCurrentDirectory() ) ,
    FileIOPermissionAttribute( SecurityAction.RequestMinimum,
    PathDiscovery=System.IO.Directory.GetCurrentDirect ory() ) ,
    FileIOPermissionAttribute( SecurityAction.RequestMinimum,
    Write=System.IO.Directory.GetCurrentDirectory() ) ,
    FileIOPermissionAttribute( SecurityAction.RequestMinimum,
    Read=System.Environment.GetEnvironmentVariable("TE MP")) ,
    FileIOPermissionAttribute( SecurityAction.RequestMinimum,
    PathDiscovery=System.Environment.GetEnvironmentVar iable("TEMP") ) ,
    FileIOPermissionAttribute( SecurityAction.RequestMinimum,
    Write=System.Environment.GetEnvironmentVariable("T EMP") )
    ]
    localhost Guest

  2. Similar Questions and Discussions

    1. regular expression problem ? and * characters
      Im writing a perl script now and this is part of the sricpt chomp = ($pattern = ARGV); for each(@thisarray) { if($_ =~ m/$pattern/i) {...
    2. Regular Expression Problem
      I am trying to parse a relatively simple SQL query with a regular expression. All is going well except for one issue I don't seem to be able to...
    3. Problem with regular expression
      I'm trying to use a regular expression to remove from the output of a call to ToString with an XML object, the text between "<?" and "?>" txtvar...
    4. php regular expression problem
      Hi, I've got just a small problem, it's probably not very complex but I'm not very experienced with regular expression stuff. I just need to...
    5. sed expression problem ?
      I am starting to use sed but am having a problem with one expression in ... cat /mnt/archive/fluxbox/keys | sed 's/:ExecCommand//g ;s/^Mod4 \(.\)...
  3. #2

    Default RE: Attribute Expression Must be a Constant - Problem

    Hello,

    Thanks for posting in the group.

    Based on the description, now you are adding attributes like
    FileIOPermissionAttribute( SecurityAction.RequestMinimum,
    Read=System.IO.Directory.GetCurrentDirectory() ) into assemblyinfo.cs
    file. When you build the project, the compiler gives error message "An
    attribute argument must be a constant expression, typeof expression or
    array creation expression". Please feel free to post here if I have
    misunderstood the problem.

    I am afraid it is impossible to use a runtime expression in Attribute
    arguments.

    The instance of an attribute class is constructed by the compiler when the
    compile detects an attribute applied to a target, and at this time the
    assembly hasn't been completed yet. And then the compiler initializes any
    public fields and properties have been specified. After that, the instance
    of the attribute is serialized to the target's metadata table entry.

    Please Note: all these are done by the compiler and there is not a way to
    get any runtime variable. Even if you use typeof keyword, you can only get
    those Types can be retrieved at compile time. To obtain the run-time type
    of an expression, you can use the .NET Framework method GetType.

    In order to achieve what you want, we need to do it programmatically, not
    declaratively. Please refer to the following article on how to do it:
    "Security in .NET: Enforce Code Access Rights with the Common Language
    Runtime "
    [url]http://msdn.microsoft.com/msdnmag/issues/01/02/CAS/default.aspx[/url]

    Hope that helps.

    Best regards,
    Yanhong Huang
    Microsoft Community Support

    Get Secure! ¨C [url]www.microsoft.com/security[/url]
    This posting is provided "AS IS" with no warranties, and confers no rights.

    Yan-Hong Huang[MSFT] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139