Bug 317309 (MONO73046) - [GMCS]: Doesn't support new enums (defined in 2.0) in (security) attributes
Summary: [GMCS]: Doesn't support new enums (defined in 2.0) in (security) attributes
Status: RESOLVED FIXED
Alias: MONO73046
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.1
Hardware: Other All
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Martin Baulig
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-26 01:03 UTC by Sebastien Pouliot
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
attribute.diff (1.70 KB, patch)
2005-03-20 19:54 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:08:56 UTC


---- Reported by sebastien@ximian.com 2005-02-25 18:03:14 MST ----

Description of Problem:
mcs/gmcs don't support new SecurityAction defined in 2.0

Steps to reproduce the problem:
1. Try compiling this with gmcs

using System;
using System.Security;
using System.Security.Permissions;
 
class Program {
 
        [SecurityPermission (SecurityAction.DemandChoice, ControlPrincipal
= true)]
        [SecurityPermission (SecurityAction.DemandChoice, ControlThread =
true)]
        public int Execute ()
        {
                Console.WriteLine ("*0* Success (at least one condition was
met)");
                return 0;
        }
 
        static int Test ()
        {
                return new Program ().Execute ();
        }
 
        static int Main (string[] args)
        {
                try {
                        return Test ();
                }
                catch (SecurityException se) {
                        Console.WriteLine ("*1* Unexpected
SecurityException\n{0}", se);
                        return 1;
                }
        }
}

Actual Results:
Error

Expected Results:
Success

How often does this happen? 
Always

Additional Information:

Adding this to gmcs did the trick for me.

I had to use the integer value of the new SecurityAction enum's elements
otherwise the compilation didn't work (? mcs use 1.0 to compile gmcs ?).

Index: attribute.cs
===================================================================
--- attribute.cs        (revision 41194)
+++ attribute.cs        (working copy)
@@ -760,6 +760,11 @@
  
                        if (!for_assembly) {
                                if (action < SecurityAction.Demand ||
action > SecurityAction.InheritanceDemand) {
+#if NET_2_0
+                                       // LinkDemandChoice,
InheritanceDemandChoice and DemandChoice are new (and valid) in 2.0
+                                       if ((int)action >= 16 &&
(int)action <= 18)
+                                               return true;
+#endif
                                        Error_AttributeEmitError
("SecurityAction is out of range");
                                        return false;
                                }



---- Additional Comments From rharinath@novell.com 2005-02-28 03:32:12 MST ----

Well, in net_2_0_bootstrap, we ensure that mcs is run with
supportedRuntime="v2.0.40607".

That's the only change.  We just us mcs as is.  However, since it uses
the 2.0 runtime, these types should be available to it when compiling
gmcs.

I think the '#ifdef NET_2_0' is inappropriate for code in 'gmcs'.  
That code almost uses mscorlib from the 2.0 profile, and so we can use
many .Net2.0 APIs directly.  However, we have to ensure such APIs are
available under NET_2_0_BOOTSTRAP in mscorlib.




---- Additional Comments From sebastien@ximian.com 2005-03-15 16:09:42 MST ----

The problem is more general than I originally thought. Trying to use
new enums value from IsolatedStorageScope in security attributes
results in errors.

System.IO.IsolatedStorage/IsolatedStorageFile.cs(160) error CS0647:
Error emitting 'IsolatedStorageFilePermission' attribute because
'System.ArgumentException was thrown during attribute processing:
Invalid enum 69
Parameter name: IsolatedStorageContainment'
System.IO.IsolatedStorage/IsolatedStorageFile.cs(170) error CS0647:
Error emitting 'IsolatedStorageFilePermission' attribute because
'System.ArgumentException was thrown during attribute processing:
Invalid enum 64
Parameter name: IsolatedStorageContainment'
System.IO.IsolatedStorage/IsolatedStorageFile.cs(180) error CS0647:
Error emitting 'IsolatedStorageFilePermission' attribute because
'System.ArgumentException was thrown during attribute processing:
Invalid enum 48
Parameter name: IsolatedStorageContainment'
System.IO.IsolatedStorage/IsolatedStorageFile.cs(191) error CS0647:
Error emitting 'IsolatedStorageFilePermission' attribute because
'System.ArgumentException was thrown during attribute processing:
Invalid enum 37
Parameter name: IsolatedStorageContainment'


So forget my previous hack as it was only hidding the more complex
problem. 

I'm c.c. Marek as he had been doing the security attribute stuff in mcs.



---- Additional Comments From sebastien@ximian.com 2005-03-17 16:42:14 MST ----

my bad :(
I should have used BOOTSTRAP_NET_2_0 in a few places.
The BOOTSTRAP_NET_2_0 were added in SVN.



---- Additional Comments From sebastien@ximian.com 2005-03-20 12:17:07 MST ----

oops the second problem (IsolatedStorage) was fixed by adding
BOOTSTRAP_NET_2_0. But this hasn't fixed the original problem :(



---- Additional Comments From sebastien@ximian.com 2005-03-20 12:54:52 MST ----

Created an attachment (id=167492)
attribute.diff




---- Additional Comments From sebastien@ximian.com 2005-03-20 12:58:38 MST ----

The attached patch, by Martin and slighly modified by me, fix this
problem (and make the code clearer). However it doesn't work for some
actions that aren't part of the SecurityAction enum (i.e. the NonCas
actions). 

IMHO typecasting their int value as a SecurityAction would be the
"cleanest" way to add them but https://bugzilla.novell.com/show_bug.cgi?id=MONO67711 is blocking this.



---- Additional Comments From martin@ximian.com 2005-04-30 04:50:15 MST ----

Is there anything else to do besides committing that patch ?



---- Additional Comments From martin@ximian.com 2005-04-30 05:46:03 MST ----

Ok, committed the patch.



---- Additional Comments From atsushi@ximian.com 2005-08-23 07:05:52 MST ----

This is not fixed (incorrect dependency).



---- Additional Comments From martin@ximian.com 2005-08-23 09:16:27 MST ----

Ok, now I'm totally confused - what's the problem here ?



---- Additional Comments From atsushi@ximian.com 2005-08-23 09:37:39 MST ----

Current gmcs output is:

$ gmcs 73046.cs
73046.cs(7) warning CS0618:
`System.Security.Permissions.SecurityAction.DemandChoice' is obsolete:
`to be removed before 2.0 RTM'
73046.cs(7) error CS0647: Error during emitting
`System.Security.Permissions.SecurityPermissionAttribute' attribute.
The reason is `SecurityAction is out of range X'
73046.cs(8) warning CS0618:
`System.Security.Permissions.SecurityAction.DemandChoice' is obsolete:
`to be removed before 2.0 RTM'
73046.cs(8) error CS0647: Error during emitting
`System.Security.Permissions.SecurityPermissionAttribute' attribute.
The reason is `SecurityAction is out of range X'
Compilation failed: 2 error(s), 2 warnings

I don't know what was the original errors.



---- Additional Comments From sebastien@ximian.com 2005-09-26 13:32:31 MST ----

Not 100% sure the original problem is fixed (the fact that the enum
couldn't, more than 6 months ago, be used in gmcs) but the new
security actions have been removed from 2.0 RC.

This bug depended on bug(s) 67711.
Imported an attachment (id=167492)