Merge branch 'master' into msbuilddll2
[mono.git] / mcs / class / corlib / Test / System / AppDomainTest.cs
index 676c18b9cdfd988c523f6fdd037b60e1d6218ce0..9c950226391ce42bf60a5e48f7c724be13bab6ba 100644 (file)
@@ -5,6 +5,7 @@
 //     Sebastien Pouliot (sebastien@ximian.com)
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc (http://www.xamarin.com).
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+#if !MOBILE
+
 using NUnit.Framework;
 using System;
 using System.Collections;
+using System.Collections.Generic;
+using System.Configuration.Assemblies;
 using System.Globalization;
 using System.IO;
 using System.Reflection;
 using System.Reflection.Emit;
+using System.Runtime.InteropServices;
 using System.Security;
 using System.Security.Permissions;
 using System.Security.Policy;
@@ -45,11 +51,13 @@ namespace MonoTests.System
        {
                private AppDomain ad;
                private ArrayList files = new ArrayList ();
-               private string tempDir = Path.Combine (Path.GetTempPath (), "MonoTests.System.AppDomainTest");
+               private string tempDir;
 
                [SetUp]
                public void SetUp ()
                {
+                       tempDir = Path.Combine (Path.GetTempPath (), Environment.UserName);
+                       tempDir = Path.Combine (tempDir, "MonoTests.System.AppDomainTest");
                        if (!Directory.Exists (tempDir)) {
                                Directory.CreateDirectory (tempDir);
                        }
@@ -70,6 +78,1818 @@ namespace MonoTests.System
                        files.Clear ();
                }
 
+               [Test] // bug #80934
+               public void ConfigurationFile_Relative ()
+               {
+                       // Note:
+                       // We use Environment.GetCommandLineArgs () to get the location of
+                       // the entry assembly in the default domain (since the default domain
+                       // is not exposed by any API)
+                       // 
+                       // MS returns a lower-case path in Environment.GetCommandLineArgs ()
+                       // and hence we need to perform a case-insensitive comparison
+                       // if the Assert involves that path
+
+                       string configFile = "test.config";
+                       string appBase = null;
+                       string expectedConfigFile = null;
+                       string expectedAppBase = null;
+
+                       // do not set ApplicationBase
+                       appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
+                       expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
+                               appBase : appBase + Path.DirectorySeparatorChar;
+                       expectedConfigFile = Path.Combine (appBase, configFile);
+                       AppDomainSetup setup = new AppDomainSetup();
+                       setup.ConfigurationFile = configFile;
+                       ad = CreateTestDomain (setup, true);
+                       CrossDomainTester cdt = CreateCrossDomainTester (ad);
+                       if (RunningOnUnix) {
+                               Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
+                               Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
+                       } else {
+                               Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
+                               Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
+                       }
+                       AppDomain.Unload (ad);
+
+                       // set ApplicationBase
+                       appBase = Path.GetTempPath ();
+                       expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
+                               appBase : appBase + Path.DirectorySeparatorChar;
+                       expectedConfigFile = Path.Combine (appBase, configFile);
+                       setup = new AppDomainSetup ();
+                       setup.ApplicationBase = appBase;
+                       setup.ConfigurationFile = configFile;
+                       ad = CreateTestDomain (setup, true);
+                       cdt = CreateCrossDomainTester (ad);
+                       Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
+                       Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
+                       AppDomain.Unload (ad);
+               }
+
+               [Test] // bug #80934
+               public void ConfigurationFile_Absolute ()
+               {
+                       // Note:
+                       // We use Environment.GetCommandLineArgs () to get the location of
+                       // the entry assembly in the default domain (since the default domain
+                       // is not exposed by any API)
+                       // 
+                       // MS returns a lower-case path in Environment.GetCommandLineArgs ()
+                       // and hence on Windows we need to perform a case-insensitive 
+                       // comparison if the Assert involves that path
+
+                       string configFile = Path.Combine (tempDir, "test.config");
+                       string appBase = null;
+                       string expectedAppBase = null;
+
+                       // do not set ApplicationBase
+                       appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
+                       expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
+                               appBase : appBase + Path.DirectorySeparatorChar;
+                       AppDomainSetup setup = new AppDomainSetup ();
+                       setup.ConfigurationFile = configFile;
+                       ad = CreateTestDomain (setup, true);
+                       CrossDomainTester cdt = CreateCrossDomainTester (ad);
+                       Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#A1");
+                       if (RunningOnUnix) {
+                               Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
+                       } else {
+                               Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
+                       }
+                       AppDomain.Unload (ad);
+
+                       // set ApplicationBase
+                       appBase = Path.GetTempPath ();
+                       expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
+                               appBase : appBase + Path.DirectorySeparatorChar;
+                       setup = new AppDomainSetup ();
+                       setup.ApplicationBase = appBase;
+                       setup.ConfigurationFile = configFile;
+                       ad = CreateTestDomain (setup, true);
+                       cdt = CreateCrossDomainTester (ad);
+                       Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#B1");
+                       Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
+                       AppDomain.Unload (ad);
+               }
+
+               [Test] // bug #80934
+               public void ConfigurationFile_Null ()
+               {
+                       // Note:
+                       // We use Environment.GetCommandLineArgs () to get the location of
+                       // the entry assembly in the default domain (since the default domain
+                       // is not exposed by any API)
+                       // 
+                       // MS returns a lower-case path in Environment.GetCommandLineArgs ()
+                       // and hence we need to perform a case-insensitive comparison
+                       // if the Assert involves that path
+
+                       string appBase = null;
+                       string expectedAppBase = null;
+                       string expectedConfigFile = null;
+
+                       // do not set ApplicationBase
+                       appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
+                       expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
+                               appBase : appBase + Path.DirectorySeparatorChar;
+                       expectedConfigFile = Environment.GetCommandLineArgs () [0] + ".config";
+                       AppDomainSetup setup = new AppDomainSetup ();
+                       setup.ConfigurationFile = null;
+                       ad = CreateTestDomain (setup, true);
+                       CrossDomainTester cdt = CreateCrossDomainTester (ad);
+                       if (RunningOnUnix) {
+                               Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
+                               Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
+                       } else {
+                               Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
+                               Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
+                       }
+                       AppDomain.Unload (ad);
+
+                       // set ApplicationBase
+                       appBase = Path.GetTempPath ();
+                       expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
+                               appBase : appBase + Path.DirectorySeparatorChar;
+                       expectedConfigFile = Path.Combine (appBase, Path.GetFileName (Environment.GetCommandLineArgs () [0]) + ".config");
+                       setup = new AppDomainSetup ();
+                       setup.ApplicationBase = appBase;
+                       setup.ConfigurationFile = null;
+                       ad = CreateTestDomain (setup, true);
+                       cdt = CreateCrossDomainTester (ad);
+                       if (RunningOnUnix) {
+                               Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
+                       } else {
+                               Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#B1");
+                       }
+                       Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
+                       AppDomain.Unload (ad);
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
+               public void DefineDynamicAssembly1_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly1";
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
+               public void DefineDynamicAssembly1_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run);
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
+               public void DefineDynamicAssembly1_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
+               public void DefineDynamicAssembly2_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly2";
+
+#if NET_2_0
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666,
+                                       AppDomain.CurrentDomain.Evidence);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+#else
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Run |
+                               (AssemblyBuilderAccess) 666,
+                               AppDomain.CurrentDomain.Evidence);
+                       Assert.IsNotNull (ab, "#1");
+#endif
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
+               public void DefineDynamicAssembly2_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run,
+                                               AppDomain.CurrentDomain.Evidence);
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
+               public void DefineDynamicAssembly2_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run,
+                                       AppDomain.CurrentDomain.Evidence);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       AppDomain.CurrentDomain.Evidence);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       AppDomain.CurrentDomain.Evidence);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
+               public void DefineDynamicAssembly3_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly3";
+
+#if NET_2_0
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666,
+                                       Path.GetTempPath ());
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+#else
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Run |
+                               (AssemblyBuilderAccess) 666,
+                               Path.GetTempPath ());
+                       Assert.IsNotNull (ab, "#1");
+#endif
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
+               public void DefineDynamicAssembly3_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run,
+                                               Path.GetTempPath ());
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
+               public void DefineDynamicAssembly3_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath ());
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath ());
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath ());
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
+               public void DefineDynamicAssembly4_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly4";
+
+#if NET_2_0
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+#else
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Run |
+                               (AssemblyBuilderAccess) 666,
+                               Path.GetTempPath (),
+                               AppDomain.CurrentDomain.Evidence);
+                       Assert.IsNotNull (ab, "#1");
+#endif
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
+               public void DefineDynamicAssembly4_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run,
+                                               Path.GetTempPath (),
+                                               AppDomain.CurrentDomain.Evidence);
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
+               public void DefineDynamicAssembly4_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly5_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly5";
+
+#if NET_2_0
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+#else
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Run |
+                               (AssemblyBuilderAccess) 666,
+                               (PermissionSet) null,
+                               (PermissionSet) null,
+                               (PermissionSet) null);
+                       Assert.IsNotNull (ab, "#1");
+#endif
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly5_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null);
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly5_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly6_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly6";
+
+#if NET_2_0
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666,
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+#else
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Run |
+                               (AssemblyBuilderAccess) 666,
+                               AppDomain.CurrentDomain.Evidence,
+                               (PermissionSet) null,
+                               (PermissionSet) null,
+                               (PermissionSet) null);
+                       Assert.IsNotNull (ab, "#1");
+#endif
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly6_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run,
+                                               AppDomain.CurrentDomain.Evidence,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null);
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly6_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run,
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly7_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly7";
+
+#if NET_2_0
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666,
+                                       Path.GetTempPath (),
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+#else
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Run |
+                               (AssemblyBuilderAccess) 666,
+                               Path.GetTempPath (),
+                               (PermissionSet) null,
+                               (PermissionSet) null,
+                               (PermissionSet) null);
+                       Assert.IsNotNull (ab, "#1");
+#endif
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly7_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run,
+                                               Path.GetTempPath (),
+                                               (PermissionSet) null,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null);
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly7_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly8_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly8";
+
+#if NET_2_0
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+#else
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Run |
+                               (AssemblyBuilderAccess) 666,
+                               Path.GetTempPath (),
+                               AppDomain.CurrentDomain.Evidence,
+                               (PermissionSet) null,
+                               (PermissionSet) null,
+                               (PermissionSet) null);
+                       Assert.IsNotNull (ab, "#1");
+#endif
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly8_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run,
+                                               Path.GetTempPath (),
+                                               AppDomain.CurrentDomain.Evidence,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null);
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
+               public void DefineDynamicAssembly8_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
+               public void DefineDynamicAssembly9_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly9";
+
+#if NET_2_0
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       true);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+#else
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Run |
+                               (AssemblyBuilderAccess) 666,
+                               Path.GetTempPath (),
+                               AppDomain.CurrentDomain.Evidence,
+                               (PermissionSet) null,
+                               (PermissionSet) null,
+                               (PermissionSet) null,
+                               true);
+                       Assert.IsNotNull (ab, "#1");
+#endif
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
+               public void DefineDynamicAssembly9_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run,
+                                               Path.GetTempPath (),
+                                               AppDomain.CurrentDomain.Evidence,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null,
+                                               true);
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
+               public void DefineDynamicAssembly9_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       true);
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       true);
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       true);
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+#if NET_2_0
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
+               public void DefineDynamicAssembly10_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly10";
+
+#if NET_2_0
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       true,
+                                       new List<CustomAttributeBuilder> ());
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+#else
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Run |
+                               (AssemblyBuilderAccess) 666,
+                               Path.GetTempPath (),
+                               AppDomain.CurrentDomain.Evidence,
+                               (PermissionSet) null,
+                               (PermissionSet) null,
+                               (PermissionSet) null,
+                               true,
+                               new List<CustomAttributeBuilder> ());
+                       Assert.IsNotNull (ab, "#1");
+#endif
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
+               public void DefineDynamicAssembly10_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run,
+                                               Path.GetTempPath (),
+                                               AppDomain.CurrentDomain.Evidence,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null,
+                                               (PermissionSet) null,
+                                               true,
+                                               new List<CustomAttributeBuilder> ());
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
+               public void DefineDynamicAssembly10_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       true,
+                                       new List<CustomAttributeBuilder> ());
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       true,
+                                       new List<CustomAttributeBuilder> ());
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       Path.GetTempPath (),
+                                       AppDomain.CurrentDomain.Evidence,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       (PermissionSet) null,
+                                       true,
+                                       new List<CustomAttributeBuilder> ());
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
+               public void DefineDynamicAssembly11 ()
+               {
+                       List<CustomAttributeBuilder> cattrs;
+                       AssemblyBuilder ab;
+                       Attribute attr;
+                       AssemblyName name;
+                       string assemblyFile;
+                       string current_dir = Directory.GetCurrentDirectory ();
+
+                       name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly11A";
+
+                       cattrs = new List<CustomAttributeBuilder> ();
+                       cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).
+                               GetConstructor (new Type [] { typeof (string) }),
+                               new object [] { "1.2.3.4"}));
+                       cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).
+                               GetConstructor (new Type [] { typeof (string) }),
+                               new object [] { "nl-BE"}));
+                       cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).
+                               GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }),
+                               new object [] { AssemblyHashAlgorithm.MD5 }));
+                       cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).
+                               GetConstructor (new Type [] { typeof (uint) }),
+                               new object [] { (uint)0x0100 }));
+                       cattrs.Add (new CustomAttributeBuilder (typeof (CLSCompliantAttribute).
+                               GetConstructor (new Type [] { typeof (bool) }),
+                               new object [] { true }));
+
+                       ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Save, cattrs);
+
+                       ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (ComVisibleAttribute).
+                               GetConstructor (new Type [] { typeof (bool) }),
+                               new object [] { true }));
+
+                       ab.Save ("DefineDynamicAssembly11A.dll");
+
+                       assemblyFile = Path.Combine (current_dir, "DefineDynamicAssembly11A.dll");
+
+                       try {
+                               AssemblyName an = AssemblyName.GetAssemblyName (assemblyFile);
+                               Assert.AreEqual (CultureInfo.InvariantCulture, an.CultureInfo, "#A1");
+                               Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#A2");
+                               Assert.AreEqual ("DefineDynamicAssembly11A, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", an.FullName, "#A3");
+                               Assert.IsNull (an.GetPublicKey (), "#A4");
+                               Assert.AreEqual (new byte [0], an.GetPublicKeyToken (), "#A5");
+                               Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "#A6");
+                               Assert.IsNull (an.KeyPair, "#A7");
+                               Assert.AreEqual ("DefineDynamicAssembly11A", an.Name, "#A8");
+                               //Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "#A9");
+                               Assert.AreEqual (an.FullName, an.ToString (), "#A10");
+                               Assert.AreEqual (new Version (0, 0, 0, 0), an.Version, "#A11");
+                               Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, an.VersionCompatibility, "#A12");
+
+                               Assembly a;
+
+                               using (FileStream fs = File.OpenRead (assemblyFile)) {
+                                       byte [] buffer = new byte [fs.Length];
+                                       fs.Read (buffer, 0, buffer.Length);
+                                       a = Assembly.Load (buffer);
+                               }
+
+                               attr = Attribute.GetCustomAttribute (a, typeof (AssemblyVersionAttribute));
+                               Assert.IsNotNull (attr, "#A13a");
+                               Assert.AreEqual ("1.2.3.4", ((AssemblyVersionAttribute) attr).Version, "#A13b");
+                               attr = Attribute.GetCustomAttribute (a, typeof (AssemblyCultureAttribute));
+                               Assert.IsNotNull (attr, "#A14a");
+                               Assert.AreEqual ("nl-BE", ((AssemblyCultureAttribute) attr).Culture, "#A14b");
+                               attr = Attribute.GetCustomAttribute (a, typeof (AssemblyAlgorithmIdAttribute));
+                               Assert.IsNotNull (attr, "#A15a");
+                               Assert.AreEqual ((uint) AssemblyHashAlgorithm.MD5, ((AssemblyAlgorithmIdAttribute) attr).AlgorithmId, "#A15b");
+                               attr = Attribute.GetCustomAttribute (a, typeof (AssemblyFlagsAttribute));
+                               Assert.IsNotNull (attr, "#A16a");
+                               Assert.AreEqual ((uint) 0x0100, ((AssemblyFlagsAttribute) attr).Flags, "#A16b");
+                               attr = Attribute.GetCustomAttribute (a, typeof (CLSCompliantAttribute));
+                               Assert.IsNotNull (attr, "#A17a");
+                               Assert.IsTrue (((CLSCompliantAttribute) attr).IsCompliant, "#A17b");
+                               attr = Attribute.GetCustomAttribute (a, typeof (ComVisibleAttribute));
+                               Assert.IsNotNull (attr, "#A18a");
+                               Assert.IsTrue (((ComVisibleAttribute) attr).Value, "#A18b");
+                       } finally {
+                               File.Delete (assemblyFile);
+                       }
+
+                       name = new AssemblyName ();
+                       name.CultureInfo = new CultureInfo ("fr-BE");
+                       name.KeyPair = new StrongNameKeyPair (keyPair);
+                       name.Name = "DefineDynamicAssembly11B";
+                       name.Version = new Version (3, 2, 4, 1);
+
+                       cattrs = new List<CustomAttributeBuilder> ();
+                       cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).
+                               GetConstructor (new Type [] { typeof (string) }),
+                               new object [] { "1.2.3.4"}));
+                       cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).
+                               GetConstructor (new Type [] { typeof (string) }),
+                               new object [] { "nl-BE"}));
+                       cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).
+                               GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }),
+                               new object [] { AssemblyHashAlgorithm.MD5 }));
+                       cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).
+                               GetConstructor (new Type [] { typeof (uint) }),
+                               new object [] { (uint)0x0100 }));
+                       cattrs.Add (new CustomAttributeBuilder (typeof (CLSCompliantAttribute).
+                               GetConstructor (new Type [] { typeof (bool) }),
+                               new object [] { true }));
+
+                       ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Save, cattrs);
+
+                       ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (ComVisibleAttribute).
+                               GetConstructor (new Type [] { typeof (bool) }),
+                               new object [] { true }));
+
+                       ab.Save ("DefineDynamicAssembly11B.dll");
+
+                       assemblyFile = Path.Combine (current_dir, "DefineDynamicAssembly11B.dll");
+
+                       try {
+                               AssemblyName an = AssemblyName.GetAssemblyName (assemblyFile);
+                               Assert.AreEqual ("fr-BE", an.CultureInfo.Name, "#B1");
+                               Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#B2");
+                               Assert.AreEqual ("DefineDynamicAssembly11B, Version=3.2.4.1, Culture=fr-BE, PublicKeyToken=ce5276d8687ec6dc", an.FullName, "#B3");
+                               Assert.AreEqual (publicKey, an.GetPublicKey (), "#B4");
+                               Assert.AreEqual (pk_token, an.GetPublicKeyToken (), "#B5");
+                               Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "#B6");
+                               Assert.IsNull (an.KeyPair, "#B7");
+                               Assert.AreEqual ("DefineDynamicAssembly11B", an.Name, "#B8");
+                               //Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "#B9");
+                               Assert.AreEqual (an.FullName, an.ToString (), "#B10");
+                               Assert.AreEqual (new Version (3, 2, 4, 1), an.Version, "#B11");
+                               Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, an.VersionCompatibility, "#B12");
+
+                               Assembly a;
+
+                               using (FileStream fs = File.OpenRead (assemblyFile)) {
+                                       byte [] buffer = new byte [fs.Length];
+                                       fs.Read (buffer, 0, buffer.Length);
+                                       a = Assembly.Load (buffer);
+                               }
+
+                               attr = Attribute.GetCustomAttribute (a, typeof (AssemblyVersionAttribute));
+                               Assert.IsNotNull (attr, "#B13a");
+                               Assert.AreEqual ("1.2.3.4", ((AssemblyVersionAttribute) attr).Version, "#B13b");
+                               attr = Attribute.GetCustomAttribute (a, typeof (AssemblyCultureAttribute));
+                               Assert.IsNotNull (attr, "#B14a");
+                               Assert.AreEqual ("nl-BE", ((AssemblyCultureAttribute) attr).Culture, "#B14b");
+                               attr = Attribute.GetCustomAttribute (a, typeof (AssemblyAlgorithmIdAttribute));
+                               Assert.IsNotNull (attr, "#B15a");
+                               Assert.AreEqual ((uint) AssemblyHashAlgorithm.MD5, ((AssemblyAlgorithmIdAttribute) attr).AlgorithmId, "#B15b");
+                               attr = Attribute.GetCustomAttribute (a, typeof (AssemblyFlagsAttribute));
+                               Assert.IsNotNull (attr, "#B16a");
+                               Assert.AreEqual ((uint) 0x0100, ((AssemblyFlagsAttribute) attr).Flags, "#B16b");
+                               attr = Attribute.GetCustomAttribute (a, typeof (CLSCompliantAttribute));
+                               Assert.IsNotNull (attr, "#B17a");
+                               Assert.IsTrue (((CLSCompliantAttribute) attr).IsCompliant, "#B17b");
+                               attr = Attribute.GetCustomAttribute (a, typeof (ComVisibleAttribute));
+                               Assert.IsNotNull (attr, "#B18a");
+                               Assert.IsTrue (((ComVisibleAttribute) attr).Value, "#B18b");
+                       } finally {
+                               File.Delete (assemblyFile);
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
+               public void DefineDynamicAssembly11_Access_Invalid ()
+               {
+                       AssemblyName name = new AssemblyName ();
+                       name.Name = "DefineDynamicAssembly11";
+
+#if NET_2_0
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name, AssemblyBuilderAccess.Run |
+                                       (AssemblyBuilderAccess) 666,
+                                       new List<CustomAttributeBuilder> ());
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // Illegal enum value: 667
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
+                               Assert.IsNotNull (ex.ParamName, "#6");
+                               Assert.AreEqual ("access", ex.ParamName, "#7");
+                       }
+#else
+                       AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
+                               name, AssemblyBuilderAccess.Run |
+                               (AssemblyBuilderAccess) 666,
+                               new List<CustomAttributeBuilder> ());
+                       Assert.IsNotNull (ab, "#1");
+#endif
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
+               public void DefineDynamicAssembly11_Name_InvalidChars ()
+               {
+                       string [] invalid_char_names = new string [] {
+                               "\tAB",
+                               " AB",
+                               "\rAB",
+                               "A/B",
+                               ":AB",
+                               "B:A",
+                               "B\\A",
+                               "BA\\"};
+
+                       AssemblyName name = new AssemblyName ();
+
+                       foreach (string invalid_name in invalid_char_names) {
+                               name.Name = invalid_name;
+                               try {
+                                       AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                               name,
+                                               AssemblyBuilderAccess.Run,
+                                               new List<CustomAttributeBuilder> ());
+                                       Assert.Fail ("#1:" + invalid_name);
+                               } catch (ArgumentException ex) {
+                                       // Assembly names may not begin with whitespace
+                                       // or contain the characters '/', '\' or ':'
+                                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
+                                       Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
+                                       Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
+                                       Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
+                                       Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
+                               }
+                       }
+               }
+
+               [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
+               public void DefineDynamicAssembly11_Name_Null ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       (AssemblyName) null,
+                                       AssemblyBuilderAccess.Run,
+                                       new List<CustomAttributeBuilder> ());
+                               Assert.Fail ("#A1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
+                               Assert.IsNull (ex.InnerException, "#A3");
+                               Assert.IsNotNull (ex.Message, "#A4");
+                               Assert.IsNotNull (ex.ParamName, "#A5");
+                               Assert.AreEqual ("name", ex.ParamName, "#A6");
+                       }
+
+                       AssemblyName name = new AssemblyName ();
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       new List<CustomAttributeBuilder> ());
+                               Assert.Fail ("#B1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
+                               Assert.IsNull (ex.InnerException, "#B3");
+                               Assert.IsNotNull (ex.Message, "#B4");
+                               Assert.IsNull (ex.ParamName, "#B5");
+                       }
+
+                       name.Name = string.Empty;
+
+                       try {
+                               AppDomain.CurrentDomain.DefineDynamicAssembly (
+                                       name,
+                                       AssemblyBuilderAccess.Run,
+                                       new List<CustomAttributeBuilder> ());
+                               Assert.Fail ("#C1");
+                       } catch (ArgumentException ex) {
+                               // AssemblyName.Name cannot be null or an empty string
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
+                               Assert.IsNull (ex.InnerException, "#C3");
+                               Assert.IsNotNull (ex.Message, "#C4");
+                               Assert.IsNull (ex.ParamName, "#C5");
+                       }
+               }
+
+               [Test] // ExecuteAssemblyByName (String)
+               public void ExecuteAssemblyByName1_NoEntryPoint ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.ExecuteAssemblyByName ("mscorlib");
+                               Assert.Fail ("#1");
+                       } catch (MissingMethodException ex) {
+                               // Entry point not found in assembly '...'
+                               Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
+                       }
+               }
+
+               [Test] // ExecuteAssemblyByName (String, Evidence)
+               public void ExecuteAssemblyByName2_NoEntryPoint ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.ExecuteAssemblyByName (
+                                       "mscorlib", (Evidence) null);
+                               Assert.Fail ("#1");
+                       } catch (MissingMethodException ex) {
+                               // Entry point not found in assembly '...'
+                               Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
+                       }
+               }
+
+               [Test] // ExecuteAssemblyByName (String, Evidence, String [])
+               public void ExecuteAssemblyByName3_NoEntryPoint ()
+               {
+                       try {
+                               AppDomain.CurrentDomain.ExecuteAssemblyByName (
+                                       "mscorlib", (Evidence) null,
+                                       new string [0]);
+                               Assert.Fail ("#1");
+                       } catch (MissingMethodException ex) {
+                               // Entry point not found in assembly '...'
+                               Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
+                       }
+               }
+
+               [Test] // ExecuteAssemblyByName (AssemblyName, Evidence, String [])
+               public void ExecuteAssemblyByName4_NoEntryPoint ()
+               {
+                       AssemblyName aname = new AssemblyName ("mscorlib");
+
+                       try {
+                               AppDomain.CurrentDomain.ExecuteAssemblyByName (
+                                       aname, (Evidence) null, new string [0]);
+                               Assert.Fail ("#1");
+                       } catch (MissingMethodException ex) {
+                               // Entry point not found in assembly '...'
+                               Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
+                       }
+               }
+#endif
+
                [Test]
                public void SetThreadPrincipal ()
                {
@@ -244,6 +2064,86 @@ namespace MonoTests.System
                        Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
                }
 
+               [Test] // ExecuteAssembly (String)
+               public void ExecuteAssembly1_NoEntryPoint ()
+               {
+                       Assembly assembly = typeof (AppDomainTest).Assembly;
+
+                       try {
+                               AppDomain.CurrentDomain.ExecuteAssembly (
+                                       assembly.Location);
+                               Assert.Fail ("#1");
+                       } catch (MissingMethodException ex) {
+                               // Entry point not found in assembly '...'
+                               Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
+                       }
+               }
+
+               [Test] // ExecuteAssembly (String, Evidence)
+               public void ExecuteAssembly2_NoEntryPoint ()
+               {
+                       Assembly assembly = typeof (AppDomainTest).Assembly;
+
+                       try {
+                               AppDomain.CurrentDomain.ExecuteAssembly (
+                                       assembly.Location,
+                                       (Evidence) null);
+                               Assert.Fail ("#1");
+                       } catch (MissingMethodException ex) {
+                               // Entry point not found in assembly '...'
+                               Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
+                       }
+               }
+
+               [Test] // ExecuteAssembly (String, Evidence, String [])
+               public void ExecuteAssembly3_NoEntryPoint ()
+               {
+                       Assembly assembly = typeof (AppDomainTest).Assembly;
+
+                       try {
+                               AppDomain.CurrentDomain.ExecuteAssembly (
+                                       assembly.Location,
+                                       (Evidence) null,
+                                       new string [0]);
+                               Assert.Fail ("#1");
+                       } catch (MissingMethodException ex) {
+                               // Entry point not found in assembly '...'
+                               Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
+                       }
+               }
+
+               [Test] // ExecuteAssembly (String, Evidence, String [], Byte [], AssemblyHashAlgorithm)
+               [Category ("NotWorking")] // Not implemented
+               public void ExecuteAssembly4_NoEntryPoint ()
+               {
+                       Assembly assembly = typeof (AppDomainTest).Assembly;
+
+                       try {
+                               AppDomain.CurrentDomain.ExecuteAssembly (
+                                       assembly.Location,
+                                       (Evidence) null,
+                                       new string [0],
+                                       (byte []) null,
+                                       AssemblyHashAlgorithm.SHA1);
+                               Assert.Fail ("#1");
+                       } catch (MissingMethodException ex) {
+                               // Entry point not found in assembly '...'
+                               Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
+                       }
+               }
+
                [Test] // bug #79720
                [Category ("NotWorking")]
                public void Load_Loaded_Ignore ()
@@ -1104,14 +3004,9 @@ namespace MonoTests.System
                        try {
                                AppDomain.CurrentDomain.Load (aname);
                                Assert.Fail ("#C9");
-#if NET_2_0
                        } catch (SecurityException) {
                                // Invalid assembly public key
                        }
-#else
-                       } catch (FileLoadException) {
-                       }
-#endif
 
                        aname = new AssemblyName ();
                        aname.Name = "bug79522C";
@@ -1155,6 +3050,13 @@ namespace MonoTests.System
                                AppDomain.Unload (ad);
                        }
                }
+               
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void Load_EmptyString ()
+               {
+                       AppDomain.CurrentDomain.Load ("");
+               }
 
                [Test]
                public void SetAppDomainPolicy ()
@@ -1265,22 +3167,157 @@ namespace MonoTests.System
                        // we have no public way to get the default appdomain
                }
 
+               static bool resolve_called;
+
+               [Test]
+               public void AssemblyResolveParseError ()
+               {
+                       AppDomain currentDomain = AppDomain.CurrentDomain;
+                       ResolveEventHandler d = ParseErrorResolve;
+                       currentDomain.AssemblyResolve += d;
+                       try {
+                               resolve_called = false;
+                               var a = Assembly.Load ("MyDynamicType, 1.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
+                               Assert.Fail ();
+                       } catch (FileNotFoundException) {
+                               Assert.IsTrue (resolve_called);
+                       }
+                       currentDomain.AssemblyResolve -= d;
+               }
+
+               static Assembly ParseErrorResolve (object sender, ResolveEventArgs args)
+               {
+                       resolve_called = true;
+                       return null;
+               }
+
                [Test]
                public void ReflectionOnlyGetAssemblies ()
                {
                        ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
                        Assembly [] a = ad.ReflectionOnlyGetAssemblies ();
                        Assert.IsNotNull (a, "ReflectionOnlyGetAssemblies");
-                       Assert.AreEqual (0, a.Length, "Count");
+                       Assert.AreEqual (0, a.Length, "Count");                 
+
+                       string assemblyFile = Path.Combine (tempDir, "bug499013.dll");
+                       AssemblyName aname = new AssemblyName ();
+                       aname.Name = "bug499013";
+                       aname.Version = new Version (2, 4);
+
+                       GenerateAssembly (aname, assemblyFile);
+
+                       Assembly.ReflectionOnlyLoadFrom (assemblyFile);
+                       foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies ())
+                               Assert.IsTrue (assembly.GetName ().Name != "bug499013");
+               }
+
+               [Test]
+               public void ReflectionOnlyAssemblyResolve ()
+               {
+                       AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
+                       Assembly asm = Assembly.ReflectionOnlyLoad(Assembly.LoadWithPartialName("System").FullName);
+                       asm.GetTypes();
+               }
+
+        [Test]
+               public void ResourceResolve ()
+               {
+                       bool called = false;
+
+                       ResolveEventHandler del = delegate (object sender, ResolveEventArgs args) { 
+                                       called = true; 
+                                       return null;
+                       };
+                       AppDomain.CurrentDomain.ResourceResolve += del;
+                       Stream st = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("NOT_EXISTING");
+                       Assert.IsTrue (called);
+                       AppDomain.CurrentDomain.ResourceResolve -= del;
+               }                       
+
+               private static Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
+               {
+                       return Assembly.ReflectionOnlyLoad(args.Name);
                }
 #endif
 
+               public class StuffToPick
+               {
+                       public StuffToPick () {}
+                       public void Method () {}
+                       public int Property { get; set; }
+                       public event Action Event;
+                       public int Field;
+                       public void GenericMethod<T> () {}
+               }
+
+               public class StuffToPick<T>
+               {
+                       public StuffToPick () {}
+                       public void Method () {}
+                       public int Property { get; set; }
+                       public event Action Event;
+                       public int Field;
+                       public void GenericMethod<T> () {}
+               }
+
+               static void TestSerialization (CrossDomainTester tester, object o)
+               {
+                       Assert.AreSame (o, tester.ReturnArg0 (o), "serializing_type_" + o.GetType ());
+               }
+
+               [Test] //BXC #12611
+               public void ReflectionObjectsAreSerializableTest ()
+               {
+                       ad = CreateTestDomain (tempDir, true);
+                       CrossDomainTester tester = CreateCrossDomainTester (ad);
+
+                       TestSerialization (tester, typeof (StuffToPick));
+                       TestSerialization (tester, typeof (StuffToPick).GetConstructor(new Type [0]));
+                       TestSerialization (tester, typeof (StuffToPick).GetMethod ("Method"));
+                       TestSerialization (tester, typeof (StuffToPick).GetProperty ("Property"));
+                       TestSerialization (tester, typeof (StuffToPick).GetEvent ("Event"));
+                       TestSerialization (tester, typeof (StuffToPick).GetField ("Field"));
+                       TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod"));
+
+                       TestSerialization (tester, typeof (StuffToPick<>));
+                       TestSerialization (tester, typeof (StuffToPick<>).GetConstructor(new Type [0]));
+                       TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("Method"));
+                       TestSerialization (tester, typeof (StuffToPick<>).GetProperty ("Property"));
+                       TestSerialization (tester, typeof (StuffToPick<>).GetEvent ("Event"));
+                       TestSerialization (tester, typeof (StuffToPick<>).GetField ("Field"));
+                       TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("GenericMethod"));
+
+                       TestSerialization (tester, typeof (StuffToPick<int>));
+                       TestSerialization (tester, typeof (StuffToPick<int>).GetConstructor(new Type [0]));
+                       TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("Method"));
+                       TestSerialization (tester, typeof (StuffToPick<int>).GetProperty ("Property"));
+                       TestSerialization (tester, typeof (StuffToPick<int>).GetEvent ("Event"));
+                       TestSerialization (tester, typeof (StuffToPick<int>).GetField ("Field"));
+                       TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("GenericMethod"));
+               }
+
+               [Test] //BXC #12611
+               [Category ("NotWorking")] // Serialization can't handle generic methods
+               public void GenericReflectionObjectsAreSerializableTest ()
+               {
+                       ad = CreateTestDomain (tempDir, true);
+                       CrossDomainTester tester = CreateCrossDomainTester (ad);
+
+                       TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)));
+                       TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)));
+                       TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)));
+               }
+
                private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
                {
                        AppDomainSetup setup = new AppDomainSetup ();
                        setup.ApplicationBase = baseDirectory;
                        setup.ApplicationName = "testdomain";
+                       return CreateTestDomain (setup, assemblyResolver);
+               }
 
+               private static AppDomain CreateTestDomain (AppDomainSetup setup, bool assemblyResolver)
+               {
                        AppDomain ad = AppDomain.CreateDomain ("testdomain",
                                AppDomain.CurrentDomain.Evidence, setup);
 
@@ -1300,6 +3337,7 @@ namespace MonoTests.System
                        return ad;
                }
 
+
                private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
                {
                        Type testerType = typeof (CrossDomainTester);
@@ -1321,6 +3359,15 @@ namespace MonoTests.System
                        }
                }
 
+               private bool RunningOnUnix {
+                       get {
+                               // check for Unix platforms - see FAQ for more details
+                               // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
+                               int platform = (int) Environment.OSVersion.Platform;
+                               return ((platform == 4) || (platform == 128) || (platform == 6));
+                       }
+               }
+
                private class CrossDomainTester : MarshalByRefObject
                {
                        public void GenerateAssembly (AssemblyName aname, string path)
@@ -1336,6 +3383,16 @@ namespace MonoTests.System
                                }
                        }
 
+                       public string GetApplicationBase ()
+                       {
+                               return AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
+                       }
+
+                       public string GetConfigurationFile ()
+                       {
+                               return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
+                       }
+
                        public void Load (AssemblyName assemblyRef)
                        {
                                AppDomain.CurrentDomain.Load (assemblyRef);
@@ -1385,6 +3442,11 @@ namespace MonoTests.System
                                        return true;
                                }
                        }
+
+                       public object ReturnArg0 (object obj)
+                       {
+                               return obj;
+                       }
                }
 
                [Serializable ()]
@@ -1399,7 +3461,7 @@ namespace MonoTests.System
                                        new ResolveEventHandler (ResolveAssembly);
                        }
 
-                       private Assembly ResolveAssembly (Object sender, ResolveEventArgs args)
+                       private Assembly ResolveAssembly (object sender, ResolveEventArgs args)
                        {
                                if (args.Name == _assemblyName)
                                        return Assembly.LoadFrom (_assemblyFile);
@@ -1541,5 +3603,9 @@ namespace MonoTests.System
                        0xf5, 0xff, 0xce, 0xd7, 0x6e, 0x5c, 0x6f, 0xb1, 0xf5, 0x7d, 0xd3,
                        0x56, 0xf9, 0x67, 0x27, 0xa4, 0xa5, 0x48, 0x5b, 0x07, 0x93, 0x44,
                        0x00, 0x4a, 0xf8, 0xff, 0xa4, 0xcb };
+
+               static byte [] pk_token = { 0xce, 0x52, 0x76, 0xd8, 0x68, 0x7e, 0Xc6, 0xdc };
        }
 }
+
+#endif
\ No newline at end of file