Author: gert
Date: 2005-05-13 09:01:50 -0400 (Fri, 13 May 2005)
New Revision: 44496

Modified:
   trunk/mcs/class/corlib/System/Activator.cs
   trunk/mcs/class/corlib/System/ChangeLog
   trunk/mcs/class/corlib/Test/System/ActivatorTest.cs
   trunk/mcs/class/corlib/Test/System/ChangeLog
Log:
* Activator.cs: Match exceptions thrown by MS.NET for CreateInstance 
                 overloads if type is abstract. Fixes bug #74861.
* ActivatorTest.cs: Tests for bug #74861.



Modified: trunk/mcs/class/corlib/System/Activator.cs
===================================================================
--- trunk/mcs/class/corlib/System/Activator.cs  2005-05-13 12:44:43 UTC (rev 
44495)
+++ trunk/mcs/class/corlib/System/Activator.cs  2005-05-13 13:01:50 UTC (rev 
44496)
@@ -152,10 +152,6 @@
                        if (type == null)
                                throw new ArgumentNullException ("type");
 
-                       if (type.IsAbstract)
-                               throw new MemberAccessException (Locale.GetText 
("Cannot create an abstract class. Class name: ") +
-                                                               type.FullName);
-
                        int length = 0;
                        if (args != null)
                                length = args.Length;
@@ -174,6 +170,15 @@
                                                                type.FullName);
                        }
 
+                       if (type.IsAbstract)
+#if NET_2_0
+                               throw new MissingMethodException 
(Locale.GetText ("Cannot create an abstract class. Class name: ") +
+                                                               type.FullName);
+#else
+                               throw new MemberAccessException (Locale.GetText 
("Cannot create an abstract class. Class name: ") +
+                                                               type.FullName);
+#endif
+
                        if (activationAttributes != null && 
activationAttributes.Length > 0 && type.IsMarshalByRef) {
                                object newOb = 
ActivationServices.CreateProxyFromAttributes (type, activationAttributes);
                                if (newOb != null)
@@ -195,10 +200,6 @@
                        if (type == null)
                                throw new ArgumentNullException ("type");
                
-                       if (type.IsAbstract)
-                               throw new MemberAccessException (Locale.GetText 
("Cannot create an abstract class. Class name: ") +
-                                                               type.FullName);
-                               
                        // It seems to apply the same rules documented for 
InvokeMember: "If the type of lookup
                        // is omitted, BindingFlags.Public | 
BindingFlags.Instance will apply".
                        if ((bindingAttr & _accessFlags) == 0)
@@ -224,6 +225,15 @@
                                                                type.FullName);
                        }
 
+                       if (type.IsAbstract)
+#if NET_2_0
+                               throw new MissingMethodException 
(Locale.GetText ("Cannot create an abstract class. Class name: ") +
+                                       type.FullName);
+#else
+                               throw new MemberAccessException (Locale.GetText 
("Cannot create an abstract class. Class name: ") +
+                                       type.FullName);
+#endif
+
                        if (activationAttributes != null && 
activationAttributes.Length > 0 && type.IsMarshalByRef) {
                                object newOb = 
ActivationServices.CreateProxyFromAttributes (type, activationAttributes);
                                if (newOb != null)
@@ -239,8 +249,13 @@
                                throw new ArgumentNullException ("type");
                
                        if (type.IsAbstract)
+#if NET_2_0
+                               throw new MissingMethodException 
(Locale.GetText ("Cannot create an abstract class. Class name: ") +
+                                                                type.FullName);
+#else
                                throw new MemberAccessException (Locale.GetText 
("Cannot create an abstract class. Class name: ") +
                                                                type.FullName);
+#endif
 
                        BindingFlags flags = BindingFlags.Public | 
BindingFlags.Instance;
                        if (nonPublic)

Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog     2005-05-13 12:44:43 UTC (rev 
44495)
+++ trunk/mcs/class/corlib/System/ChangeLog     2005-05-13 13:01:50 UTC (rev 
44496)
@@ -1,5 +1,10 @@
-2005-05-09 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+2005-05-13  Gert Driesen <[EMAIL PROTECTED]>
 
+       * Activator.cs: Match exceptions thrown by MS.NET for
+       CreateInstance overloads if type is abstract. Fixes bug #74861.
+
+2005-05-09  Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
        * OperatingSystem.cs: PlatformID.Unix.
 
 2005-05-09  Sebastien Pouliot  <[EMAIL PROTECTED]>

Modified: trunk/mcs/class/corlib/Test/System/ActivatorTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/ActivatorTest.cs 2005-05-13 12:44:43 UTC 
(rev 44495)
+++ trunk/mcs/class/corlib/Test/System/ActivatorTest.cs 2005-05-13 13:01:50 UTC 
(rev 44496)
@@ -91,6 +91,48 @@
        // all the overriden functions using activationAttribute
       }
 
+    [Test]
+#if NET_2_0
+    [ExpectedException(typeof(MissingMethodException))]
+#else
+    [ExpectedException(typeof(MemberAccessException))]
+#endif
+    public void CreateInstanceAbstract1() {
+          Activator.CreateInstance(typeof(Type));
+    }
+
+    [Test]
+#if NET_2_0
+    [ExpectedException(typeof(MissingMethodException))]
+#else
+    [ExpectedException(typeof(MemberAccessException))]
+#endif
+    public void CreateInstanceAbstract2() {
+        Activator.CreateInstance(typeof(Type), true);
+    }
+
+    [Test]
+    [ExpectedException(typeof(MissingMethodException))]
+    public void CreateInstanceAbstract3() {
+        Activator.CreateInstance(typeof(Type), null, null);
+    }
+
+    [Test]
+    [ExpectedException(typeof(MissingMethodException))]
+    public void CreateInstanceAbstract4() {
+        Activator.CreateInstance(typeof(Type), BindingFlags.CreateInstance | 
(BindingFlags.Public | BindingFlags.Instance), null, null, 
CultureInfo.InvariantCulture, null);
+    }
+
+    [Test]
+#if NET_2_0
+    [ExpectedException(typeof(MissingMethodException))]
+#else
+    [ExpectedException(typeof(MemberAccessException))]
+#endif
+    public void CreateInstanceAbstract5() {
+        Activator.CreateInstance(typeof(Type), BindingFlags.NonPublic | 
BindingFlags.Public | BindingFlags.Instance, null, null, 
CultureInfo.InvariantCulture, null);
+    }
+
     // This method tests GetObject from the Activator class
     [Test]
       public void GetObject()

Modified: trunk/mcs/class/corlib/Test/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System/ChangeLog        2005-05-13 12:44:43 UTC 
(rev 44495)
+++ trunk/mcs/class/corlib/Test/System/ChangeLog        2005-05-13 13:01:50 UTC 
(rev 44496)
@@ -1,3 +1,8 @@
+2005-05-13  Gert Driesen <[EMAIL PROTECTED]>
+       
+       * ActivatorTest.cs: Tests for exceptions thrown by CreateInstance
+       overloads if type is abstract.
+
 2005-05-08  Gert Driesen <[EMAIL PROTECTED]>
 
        * DoubleFormatterTest.cs: re-enabled test as bug #60110 is fixed.

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to