2010-03-01 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / corlib / Test / System / AppDomainTest.cs
1 //
2 // AppDomainTest.cs - NUnit Test Cases for AppDomain
3 //
4 // Author:
5 //      Sebastien Pouliot (sebastien@ximian.com)
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using NUnit.Framework;
30 using System;
31 using System.Collections;
32 using System.Collections.Generic;
33 using System.Configuration.Assemblies;
34 using System.Globalization;
35 using System.IO;
36 using System.Reflection;
37 using System.Reflection.Emit;
38 using System.Runtime.InteropServices;
39 using System.Security;
40 using System.Security.Permissions;
41 using System.Security.Policy;
42 using System.Security.Principal;
43
44 namespace MonoTests.System
45 {
46         [TestFixture]
47         public class AppDomainTest
48         {
49                 private AppDomain ad;
50                 private ArrayList files = new ArrayList ();
51                 private string tempDir;
52
53                 [SetUp]
54                 public void SetUp ()
55                 {
56                         tempDir = Path.Combine (Path.GetTempPath (), Environment.UserName);
57                         tempDir = Path.Combine (tempDir, "MonoTests.System.AppDomainTest");
58                         if (!Directory.Exists (tempDir)) {
59                                 Directory.CreateDirectory (tempDir);
60                         }
61                 }
62
63                 [TearDown]
64                 public void TearDown ()
65                 {
66                         if (ad != null) {
67                                 try {
68                                         AppDomain.Unload (ad);
69                                         ad = null;
70                                 } catch { } // do not affect unit test results in TearDown
71                         }
72                         foreach (string fname in files) {
73                                 File.Delete (fname);
74                         }
75                         files.Clear ();
76                 }
77
78                 [Test] // bug #80934
79                 public void ConfigurationFile_Relative ()
80                 {
81                         // Note:
82                         // We use Environment.GetCommandLineArgs () to get the location of
83                         // the entry assembly in the default domain (since the default domain
84                         // is not exposed by any API)
85                         // 
86                         // MS returns a lower-case path in Environment.GetCommandLineArgs ()
87                         // and hence we need to perform a case-insensitive comparison
88                         // if the Assert involves that path
89
90                         string configFile = "test.config";
91                         string appBase = null;
92                         string expectedConfigFile = null;
93                         string expectedAppBase = null;
94
95                         // do not set ApplicationBase
96                         appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
97                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
98                                 appBase : appBase + Path.DirectorySeparatorChar;
99                         expectedConfigFile = Path.Combine (appBase, configFile);
100                         AppDomainSetup setup = new AppDomainSetup();
101                         setup.ConfigurationFile = configFile;
102                         ad = CreateTestDomain (setup, true);
103                         CrossDomainTester cdt = CreateCrossDomainTester (ad);
104                         if (RunningOnUnix) {
105                                 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
106                                 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
107                         } else {
108                                 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
109                                 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
110                         }
111                         AppDomain.Unload (ad);
112
113                         // set ApplicationBase
114                         appBase = Path.GetTempPath ();
115                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
116                                 appBase : appBase + Path.DirectorySeparatorChar;
117                         expectedConfigFile = Path.Combine (appBase, configFile);
118                         setup = new AppDomainSetup ();
119                         setup.ApplicationBase = appBase;
120                         setup.ConfigurationFile = configFile;
121                         ad = CreateTestDomain (setup, true);
122                         cdt = CreateCrossDomainTester (ad);
123                         Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
124                         Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
125                         AppDomain.Unload (ad);
126                 }
127
128                 [Test] // bug #80934
129                 public void ConfigurationFile_Absolute ()
130                 {
131                         // Note:
132                         // We use Environment.GetCommandLineArgs () to get the location of
133                         // the entry assembly in the default domain (since the default domain
134                         // is not exposed by any API)
135                         // 
136                         // MS returns a lower-case path in Environment.GetCommandLineArgs ()
137                         // and hence on Windows we need to perform a case-insensitive 
138                         // comparison if the Assert involves that path
139
140                         string configFile = Path.Combine (tempDir, "test.config");
141                         string appBase = null;
142                         string expectedAppBase = null;
143
144                         // do not set ApplicationBase
145                         appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
146                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
147                                 appBase : appBase + Path.DirectorySeparatorChar;
148                         AppDomainSetup setup = new AppDomainSetup ();
149                         setup.ConfigurationFile = configFile;
150                         ad = CreateTestDomain (setup, true);
151                         CrossDomainTester cdt = CreateCrossDomainTester (ad);
152                         Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#A1");
153                         if (RunningOnUnix) {
154                                 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
155                         } else {
156                                 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
157                         }
158                         AppDomain.Unload (ad);
159
160                         // set ApplicationBase
161                         appBase = Path.GetTempPath ();
162                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
163                                 appBase : appBase + Path.DirectorySeparatorChar;
164                         setup = new AppDomainSetup ();
165                         setup.ApplicationBase = appBase;
166                         setup.ConfigurationFile = configFile;
167                         ad = CreateTestDomain (setup, true);
168                         cdt = CreateCrossDomainTester (ad);
169                         Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#B1");
170                         Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
171                         AppDomain.Unload (ad);
172                 }
173
174                 [Test] // bug #80934
175                 public void ConfigurationFile_Null ()
176                 {
177                         // Note:
178                         // We use Environment.GetCommandLineArgs () to get the location of
179                         // the entry assembly in the default domain (since the default domain
180                         // is not exposed by any API)
181                         // 
182                         // MS returns a lower-case path in Environment.GetCommandLineArgs ()
183                         // and hence we need to perform a case-insensitive comparison
184                         // if the Assert involves that path
185
186                         string appBase = null;
187                         string expectedAppBase = null;
188                         string expectedConfigFile = null;
189
190                         // do not set ApplicationBase
191                         appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
192                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
193                                 appBase : appBase + Path.DirectorySeparatorChar;
194                         expectedConfigFile = Environment.GetCommandLineArgs () [0] + ".config";
195                         AppDomainSetup setup = new AppDomainSetup ();
196                         setup.ConfigurationFile = null;
197                         ad = CreateTestDomain (setup, true);
198                         CrossDomainTester cdt = CreateCrossDomainTester (ad);
199                         if (RunningOnUnix) {
200                                 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
201                                 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
202                         } else {
203                                 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
204                                 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
205                         }
206                         AppDomain.Unload (ad);
207
208                         // set ApplicationBase
209                         appBase = Path.GetTempPath ();
210                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
211                                 appBase : appBase + Path.DirectorySeparatorChar;
212                         expectedConfigFile = Path.Combine (appBase, Path.GetFileName (Environment.GetCommandLineArgs () [0]) + ".config");
213                         setup = new AppDomainSetup ();
214                         setup.ApplicationBase = appBase;
215                         setup.ConfigurationFile = null;
216                         ad = CreateTestDomain (setup, true);
217                         cdt = CreateCrossDomainTester (ad);
218                         if (RunningOnUnix) {
219                                 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
220                         } else {
221                                 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#B1");
222                         }
223                         Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
224                         AppDomain.Unload (ad);
225                 }
226
227                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
228                 public void DefineDynamicAssembly1_Access_Invalid ()
229                 {
230                         AssemblyName name = new AssemblyName ();
231                         name.Name = "DefineDynamicAssembly1";
232
233                         try {
234                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
235                                         name, AssemblyBuilderAccess.Run |
236                                         (AssemblyBuilderAccess) 666);
237                                 Assert.Fail ("#1");
238                         } catch (ArgumentException ex) {
239                                 // Illegal enum value: 667
240                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
241                                 Assert.IsNull (ex.InnerException, "#3");
242                                 Assert.IsNotNull (ex.Message, "#4");
243                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
244                                 Assert.IsNotNull (ex.ParamName, "#6");
245                                 Assert.AreEqual ("access", ex.ParamName, "#7");
246                         }
247                 }
248
249                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
250                 public void DefineDynamicAssembly1_Name_InvalidChars ()
251                 {
252                         string [] invalid_char_names = new string [] {
253                                 "\tAB",
254                                 " AB",
255                                 "\rAB",
256                                 "A/B",
257                                 ":AB",
258                                 "B:A",
259                                 "B\\A",
260                                 "BA\\"};
261
262                         AssemblyName name = new AssemblyName ();
263
264                         foreach (string invalid_name in invalid_char_names) {
265                                 name.Name = invalid_name;
266                                 try {
267                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
268                                                 name,
269                                                 AssemblyBuilderAccess.Run);
270                                         Assert.Fail ("#1:" + invalid_name);
271                                 } catch (ArgumentException ex) {
272                                         // Assembly names may not begin with whitespace
273                                         // or contain the characters '/', '\' or ':'
274                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
275                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
276                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
277                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
278                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
279                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
280                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
281                                 }
282                         }
283                 }
284
285                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
286                 public void DefineDynamicAssembly1_Name_Null ()
287                 {
288                         try {
289                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
290                                         (AssemblyName) null,
291                                         AssemblyBuilderAccess.Run);
292                                 Assert.Fail ("#A1");
293                         } catch (ArgumentNullException ex) {
294                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
295                                 Assert.IsNull (ex.InnerException, "#A3");
296                                 Assert.IsNotNull (ex.Message, "#A4");
297                                 Assert.IsNotNull (ex.ParamName, "#A5");
298                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
299                         }
300
301                         AssemblyName name = new AssemblyName ();
302
303                         try {
304                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
305                                         name,
306                                         AssemblyBuilderAccess.Run);
307                                 Assert.Fail ("#B1");
308                         } catch (ArgumentException ex) {
309                                 // AssemblyName.Name cannot be null or an empty string
310                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
311                                 Assert.IsNull (ex.InnerException, "#B3");
312                                 Assert.IsNotNull (ex.Message, "#B4");
313                                 Assert.IsNull (ex.ParamName, "#B5");
314                         }
315
316                         name.Name = string.Empty;
317
318                         try {
319                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
320                                         name,
321                                         AssemblyBuilderAccess.Run);
322                                 Assert.Fail ("#C1");
323                         } catch (ArgumentException ex) {
324                                 // AssemblyName.Name cannot be null or an empty string
325                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
326                                 Assert.IsNull (ex.InnerException, "#C3");
327                                 Assert.IsNotNull (ex.Message, "#C4");
328                                 Assert.IsNull (ex.ParamName, "#C5");
329                         }
330                 }
331
332                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
333                 public void DefineDynamicAssembly2_Access_Invalid ()
334                 {
335                         AssemblyName name = new AssemblyName ();
336                         name.Name = "DefineDynamicAssembly2";
337
338 #if NET_2_0
339                         try {
340                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
341                                         name, AssemblyBuilderAccess.Run |
342                                         (AssemblyBuilderAccess) 666,
343                                         AppDomain.CurrentDomain.Evidence);
344                                 Assert.Fail ("#1");
345                         } catch (ArgumentException ex) {
346                                 // Illegal enum value: 667
347                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
348                                 Assert.IsNull (ex.InnerException, "#3");
349                                 Assert.IsNotNull (ex.Message, "#4");
350                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
351                                 Assert.IsNotNull (ex.ParamName, "#6");
352                                 Assert.AreEqual ("access", ex.ParamName, "#7");
353                         }
354 #else
355                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
356                                 name, AssemblyBuilderAccess.Run |
357                                 (AssemblyBuilderAccess) 666,
358                                 AppDomain.CurrentDomain.Evidence);
359                         Assert.IsNotNull (ab, "#1");
360 #endif
361                 }
362
363                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
364                 public void DefineDynamicAssembly2_Name_InvalidChars ()
365                 {
366                         string [] invalid_char_names = new string [] {
367                                 "\tAB",
368                                 " AB",
369                                 "\rAB",
370                                 "A/B",
371                                 ":AB",
372                                 "B:A",
373                                 "B\\A",
374                                 "BA\\"};
375
376                         AssemblyName name = new AssemblyName ();
377
378                         foreach (string invalid_name in invalid_char_names) {
379                                 name.Name = invalid_name;
380                                 try {
381                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
382                                                 name,
383                                                 AssemblyBuilderAccess.Run,
384                                                 AppDomain.CurrentDomain.Evidence);
385                                         Assert.Fail ("#1:" + invalid_name);
386                                 } catch (ArgumentException ex) {
387                                         // Assembly names may not begin with whitespace
388                                         // or contain the characters '/', '\' or ':'
389                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
390                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
391                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
392                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
393                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
394                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
395                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
396                                 }
397                         }
398                 }
399
400                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
401                 public void DefineDynamicAssembly2_Name_Null ()
402                 {
403                         try {
404                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
405                                         (AssemblyName) null,
406                                         AssemblyBuilderAccess.Run,
407                                         AppDomain.CurrentDomain.Evidence);
408                                 Assert.Fail ("#A1");
409                         } catch (ArgumentNullException ex) {
410                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
411                                 Assert.IsNull (ex.InnerException, "#A3");
412                                 Assert.IsNotNull (ex.Message, "#A4");
413                                 Assert.IsNotNull (ex.ParamName, "#A5");
414                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
415                         }
416
417                         AssemblyName name = new AssemblyName ();
418
419                         try {
420                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
421                                         name,
422                                         AssemblyBuilderAccess.Run,
423                                         AppDomain.CurrentDomain.Evidence);
424                                 Assert.Fail ("#B1");
425                         } catch (ArgumentException ex) {
426                                 // AssemblyName.Name cannot be null or an empty string
427                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
428                                 Assert.IsNull (ex.InnerException, "#B3");
429                                 Assert.IsNotNull (ex.Message, "#B4");
430                                 Assert.IsNull (ex.ParamName, "#B5");
431                         }
432
433                         name.Name = string.Empty;
434
435                         try {
436                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
437                                         name,
438                                         AssemblyBuilderAccess.Run,
439                                         AppDomain.CurrentDomain.Evidence);
440                                 Assert.Fail ("#C1");
441                         } catch (ArgumentException ex) {
442                                 // AssemblyName.Name cannot be null or an empty string
443                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
444                                 Assert.IsNull (ex.InnerException, "#C3");
445                                 Assert.IsNotNull (ex.Message, "#C4");
446                                 Assert.IsNull (ex.ParamName, "#C5");
447                         }
448                 }
449
450                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
451                 public void DefineDynamicAssembly3_Access_Invalid ()
452                 {
453                         AssemblyName name = new AssemblyName ();
454                         name.Name = "DefineDynamicAssembly3";
455
456 #if NET_2_0
457                         try {
458                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
459                                         name, AssemblyBuilderAccess.Run |
460                                         (AssemblyBuilderAccess) 666,
461                                         Path.GetTempPath ());
462                                 Assert.Fail ("#1");
463                         } catch (ArgumentException ex) {
464                                 // Illegal enum value: 667
465                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
466                                 Assert.IsNull (ex.InnerException, "#3");
467                                 Assert.IsNotNull (ex.Message, "#4");
468                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
469                                 Assert.IsNotNull (ex.ParamName, "#6");
470                                 Assert.AreEqual ("access", ex.ParamName, "#7");
471                         }
472 #else
473                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
474                                 name, AssemblyBuilderAccess.Run |
475                                 (AssemblyBuilderAccess) 666,
476                                 Path.GetTempPath ());
477                         Assert.IsNotNull (ab, "#1");
478 #endif
479                 }
480
481                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
482                 public void DefineDynamicAssembly3_Name_InvalidChars ()
483                 {
484                         string [] invalid_char_names = new string [] {
485                                 "\tAB",
486                                 " AB",
487                                 "\rAB",
488                                 "A/B",
489                                 ":AB",
490                                 "B:A",
491                                 "B\\A",
492                                 "BA\\"};
493
494                         AssemblyName name = new AssemblyName ();
495
496                         foreach (string invalid_name in invalid_char_names) {
497                                 name.Name = invalid_name;
498                                 try {
499                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
500                                                 name,
501                                                 AssemblyBuilderAccess.Run,
502                                                 Path.GetTempPath ());
503                                         Assert.Fail ("#1:" + invalid_name);
504                                 } catch (ArgumentException ex) {
505                                         // Assembly names may not begin with whitespace
506                                         // or contain the characters '/', '\' or ':'
507                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
508                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
509                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
510                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
511                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
512                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
513                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
514                                 }
515                         }
516                 }
517
518                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
519                 public void DefineDynamicAssembly3_Name_Null ()
520                 {
521                         try {
522                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
523                                         (AssemblyName) null,
524                                         AssemblyBuilderAccess.Run,
525                                         Path.GetTempPath ());
526                                 Assert.Fail ("#A1");
527                         } catch (ArgumentNullException ex) {
528                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
529                                 Assert.IsNull (ex.InnerException, "#A3");
530                                 Assert.IsNotNull (ex.Message, "#A4");
531                                 Assert.IsNotNull (ex.ParamName, "#A5");
532                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
533                         }
534
535                         AssemblyName name = new AssemblyName ();
536
537                         try {
538                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
539                                         name,
540                                         AssemblyBuilderAccess.Run,
541                                         Path.GetTempPath ());
542                                 Assert.Fail ("#B1");
543                         } catch (ArgumentException ex) {
544                                 // AssemblyName.Name cannot be null or an empty string
545                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
546                                 Assert.IsNull (ex.InnerException, "#B3");
547                                 Assert.IsNotNull (ex.Message, "#B4");
548                                 Assert.IsNull (ex.ParamName, "#B5");
549                         }
550
551                         name.Name = string.Empty;
552
553                         try {
554                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
555                                         name,
556                                         AssemblyBuilderAccess.Run,
557                                         Path.GetTempPath ());
558                                 Assert.Fail ("#C1");
559                         } catch (ArgumentException ex) {
560                                 // AssemblyName.Name cannot be null or an empty string
561                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
562                                 Assert.IsNull (ex.InnerException, "#C3");
563                                 Assert.IsNotNull (ex.Message, "#C4");
564                                 Assert.IsNull (ex.ParamName, "#C5");
565                         }
566                 }
567
568                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
569                 public void DefineDynamicAssembly4_Access_Invalid ()
570                 {
571                         AssemblyName name = new AssemblyName ();
572                         name.Name = "DefineDynamicAssembly4";
573
574 #if NET_2_0
575                         try {
576                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
577                                         name, AssemblyBuilderAccess.Run |
578                                         (AssemblyBuilderAccess) 666,
579                                         Path.GetTempPath (),
580                                         AppDomain.CurrentDomain.Evidence);
581                                 Assert.Fail ("#1");
582                         } catch (ArgumentException ex) {
583                                 // Illegal enum value: 667
584                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
585                                 Assert.IsNull (ex.InnerException, "#3");
586                                 Assert.IsNotNull (ex.Message, "#4");
587                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
588                                 Assert.IsNotNull (ex.ParamName, "#6");
589                                 Assert.AreEqual ("access", ex.ParamName, "#7");
590                         }
591 #else
592                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
593                                 name, AssemblyBuilderAccess.Run |
594                                 (AssemblyBuilderAccess) 666,
595                                 Path.GetTempPath (),
596                                 AppDomain.CurrentDomain.Evidence);
597                         Assert.IsNotNull (ab, "#1");
598 #endif
599                 }
600
601                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
602                 public void DefineDynamicAssembly4_Name_InvalidChars ()
603                 {
604                         string [] invalid_char_names = new string [] {
605                                 "\tAB",
606                                 " AB",
607                                 "\rAB",
608                                 "A/B",
609                                 ":AB",
610                                 "B:A",
611                                 "B\\A",
612                                 "BA\\"};
613
614                         AssemblyName name = new AssemblyName ();
615
616                         foreach (string invalid_name in invalid_char_names) {
617                                 name.Name = invalid_name;
618                                 try {
619                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
620                                                 name,
621                                                 AssemblyBuilderAccess.Run,
622                                                 Path.GetTempPath (),
623                                                 AppDomain.CurrentDomain.Evidence);
624                                         Assert.Fail ("#1:" + invalid_name);
625                                 } catch (ArgumentException ex) {
626                                         // Assembly names may not begin with whitespace
627                                         // or contain the characters '/', '\' or ':'
628                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
629                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
630                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
631                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
632                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
633                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
634                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
635                                 }
636                         }
637                 }
638
639                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
640                 public void DefineDynamicAssembly4_Name_Null ()
641                 {
642                         try {
643                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
644                                         (AssemblyName) null,
645                                         AssemblyBuilderAccess.Run,
646                                         Path.GetTempPath (),
647                                         AppDomain.CurrentDomain.Evidence);
648                                 Assert.Fail ("#A1");
649                         } catch (ArgumentNullException ex) {
650                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
651                                 Assert.IsNull (ex.InnerException, "#A3");
652                                 Assert.IsNotNull (ex.Message, "#A4");
653                                 Assert.IsNotNull (ex.ParamName, "#A5");
654                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
655                         }
656
657                         AssemblyName name = new AssemblyName ();
658
659                         try {
660                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
661                                         name,
662                                         AssemblyBuilderAccess.Run,
663                                         Path.GetTempPath (),
664                                         AppDomain.CurrentDomain.Evidence);
665                                 Assert.Fail ("#B1");
666                         } catch (ArgumentException ex) {
667                                 // AssemblyName.Name cannot be null or an empty string
668                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
669                                 Assert.IsNull (ex.InnerException, "#B3");
670                                 Assert.IsNotNull (ex.Message, "#B4");
671                                 Assert.IsNull (ex.ParamName, "#B5");
672                         }
673
674                         name.Name = string.Empty;
675
676                         try {
677                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
678                                         name,
679                                         AssemblyBuilderAccess.Run,
680                                         Path.GetTempPath (),
681                                         AppDomain.CurrentDomain.Evidence);
682                                 Assert.Fail ("#C1");
683                         } catch (ArgumentException ex) {
684                                 // AssemblyName.Name cannot be null or an empty string
685                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
686                                 Assert.IsNull (ex.InnerException, "#C3");
687                                 Assert.IsNotNull (ex.Message, "#C4");
688                                 Assert.IsNull (ex.ParamName, "#C5");
689                         }
690                 }
691
692                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
693                 public void DefineDynamicAssembly5_Access_Invalid ()
694                 {
695                         AssemblyName name = new AssemblyName ();
696                         name.Name = "DefineDynamicAssembly5";
697
698 #if NET_2_0
699                         try {
700                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
701                                         name, AssemblyBuilderAccess.Run |
702                                         (AssemblyBuilderAccess) 666,
703                                         (PermissionSet) null,
704                                         (PermissionSet) null,
705                                         (PermissionSet) null);
706                                 Assert.Fail ("#1");
707                         } catch (ArgumentException ex) {
708                                 // Illegal enum value: 667
709                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
710                                 Assert.IsNull (ex.InnerException, "#3");
711                                 Assert.IsNotNull (ex.Message, "#4");
712                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
713                                 Assert.IsNotNull (ex.ParamName, "#6");
714                                 Assert.AreEqual ("access", ex.ParamName, "#7");
715                         }
716 #else
717                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
718                                 name, AssemblyBuilderAccess.Run |
719                                 (AssemblyBuilderAccess) 666,
720                                 (PermissionSet) null,
721                                 (PermissionSet) null,
722                                 (PermissionSet) null);
723                         Assert.IsNotNull (ab, "#1");
724 #endif
725                 }
726
727                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
728                 public void DefineDynamicAssembly5_Name_InvalidChars ()
729                 {
730                         string [] invalid_char_names = new string [] {
731                                 "\tAB",
732                                 " AB",
733                                 "\rAB",
734                                 "A/B",
735                                 ":AB",
736                                 "B:A",
737                                 "B\\A",
738                                 "BA\\"};
739
740                         AssemblyName name = new AssemblyName ();
741
742                         foreach (string invalid_name in invalid_char_names) {
743                                 name.Name = invalid_name;
744                                 try {
745                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
746                                                 name,
747                                                 AssemblyBuilderAccess.Run,
748                                                 (PermissionSet) null,
749                                                 (PermissionSet) null,
750                                                 (PermissionSet) null);
751                                         Assert.Fail ("#1:" + invalid_name);
752                                 } catch (ArgumentException ex) {
753                                         // Assembly names may not begin with whitespace
754                                         // or contain the characters '/', '\' or ':'
755                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
756                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
757                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
758                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
759                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
760                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
761                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
762                                 }
763                         }
764                 }
765
766                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
767                 public void DefineDynamicAssembly5_Name_Null ()
768                 {
769                         try {
770                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
771                                         (AssemblyName) null,
772                                         AssemblyBuilderAccess.Run,
773                                         (PermissionSet) null,
774                                         (PermissionSet) null,
775                                         (PermissionSet) null);
776                                 Assert.Fail ("#A1");
777                         } catch (ArgumentNullException ex) {
778                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
779                                 Assert.IsNull (ex.InnerException, "#A3");
780                                 Assert.IsNotNull (ex.Message, "#A4");
781                                 Assert.IsNotNull (ex.ParamName, "#A5");
782                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
783                         }
784
785                         AssemblyName name = new AssemblyName ();
786
787                         try {
788                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
789                                         name,
790                                         AssemblyBuilderAccess.Run,
791                                         (PermissionSet) null,
792                                         (PermissionSet) null,
793                                         (PermissionSet) null);
794                                 Assert.Fail ("#B1");
795                         } catch (ArgumentException ex) {
796                                 // AssemblyName.Name cannot be null or an empty string
797                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
798                                 Assert.IsNull (ex.InnerException, "#B3");
799                                 Assert.IsNotNull (ex.Message, "#B4");
800                                 Assert.IsNull (ex.ParamName, "#B5");
801                         }
802
803                         name.Name = string.Empty;
804
805                         try {
806                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
807                                         name,
808                                         AssemblyBuilderAccess.Run,
809                                         (PermissionSet) null,
810                                         (PermissionSet) null,
811                                         (PermissionSet) null);
812                                 Assert.Fail ("#C1");
813                         } catch (ArgumentException ex) {
814                                 // AssemblyName.Name cannot be null or an empty string
815                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
816                                 Assert.IsNull (ex.InnerException, "#C3");
817                                 Assert.IsNotNull (ex.Message, "#C4");
818                                 Assert.IsNull (ex.ParamName, "#C5");
819                         }
820                 }
821
822                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
823                 public void DefineDynamicAssembly6_Access_Invalid ()
824                 {
825                         AssemblyName name = new AssemblyName ();
826                         name.Name = "DefineDynamicAssembly6";
827
828 #if NET_2_0
829                         try {
830                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
831                                         name, AssemblyBuilderAccess.Run |
832                                         (AssemblyBuilderAccess) 666,
833                                         AppDomain.CurrentDomain.Evidence,
834                                         (PermissionSet) null,
835                                         (PermissionSet) null,
836                                         (PermissionSet) null);
837                                 Assert.Fail ("#1");
838                         } catch (ArgumentException ex) {
839                                 // Illegal enum value: 667
840                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
841                                 Assert.IsNull (ex.InnerException, "#3");
842                                 Assert.IsNotNull (ex.Message, "#4");
843                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
844                                 Assert.IsNotNull (ex.ParamName, "#6");
845                                 Assert.AreEqual ("access", ex.ParamName, "#7");
846                         }
847 #else
848                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
849                                 name, AssemblyBuilderAccess.Run |
850                                 (AssemblyBuilderAccess) 666,
851                                 AppDomain.CurrentDomain.Evidence,
852                                 (PermissionSet) null,
853                                 (PermissionSet) null,
854                                 (PermissionSet) null);
855                         Assert.IsNotNull (ab, "#1");
856 #endif
857                 }
858
859                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
860                 public void DefineDynamicAssembly6_Name_InvalidChars ()
861                 {
862                         string [] invalid_char_names = new string [] {
863                                 "\tAB",
864                                 " AB",
865                                 "\rAB",
866                                 "A/B",
867                                 ":AB",
868                                 "B:A",
869                                 "B\\A",
870                                 "BA\\"};
871
872                         AssemblyName name = new AssemblyName ();
873
874                         foreach (string invalid_name in invalid_char_names) {
875                                 name.Name = invalid_name;
876                                 try {
877                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
878                                                 name,
879                                                 AssemblyBuilderAccess.Run,
880                                                 AppDomain.CurrentDomain.Evidence,
881                                                 (PermissionSet) null,
882                                                 (PermissionSet) null,
883                                                 (PermissionSet) null);
884                                         Assert.Fail ("#1:" + invalid_name);
885                                 } catch (ArgumentException ex) {
886                                         // Assembly names may not begin with whitespace
887                                         // or contain the characters '/', '\' or ':'
888                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
889                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
890                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
891                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
892                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
893                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
894                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
895                                 }
896                         }
897                 }
898
899                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
900                 public void DefineDynamicAssembly6_Name_Null ()
901                 {
902                         try {
903                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
904                                         (AssemblyName) null,
905                                         AssemblyBuilderAccess.Run,
906                                         AppDomain.CurrentDomain.Evidence,
907                                         (PermissionSet) null,
908                                         (PermissionSet) null,
909                                         (PermissionSet) null);
910                                 Assert.Fail ("#A1");
911                         } catch (ArgumentNullException ex) {
912                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
913                                 Assert.IsNull (ex.InnerException, "#A3");
914                                 Assert.IsNotNull (ex.Message, "#A4");
915                                 Assert.IsNotNull (ex.ParamName, "#A5");
916                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
917                         }
918
919                         AssemblyName name = new AssemblyName ();
920
921                         try {
922                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
923                                         name,
924                                         AssemblyBuilderAccess.Run,
925                                         AppDomain.CurrentDomain.Evidence,
926                                         (PermissionSet) null,
927                                         (PermissionSet) null,
928                                         (PermissionSet) null);
929                                 Assert.Fail ("#B1");
930                         } catch (ArgumentException ex) {
931                                 // AssemblyName.Name cannot be null or an empty string
932                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
933                                 Assert.IsNull (ex.InnerException, "#B3");
934                                 Assert.IsNotNull (ex.Message, "#B4");
935                                 Assert.IsNull (ex.ParamName, "#B5");
936                         }
937
938                         name.Name = string.Empty;
939
940                         try {
941                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
942                                         name,
943                                         AssemblyBuilderAccess.Run,
944                                         AppDomain.CurrentDomain.Evidence,
945                                         (PermissionSet) null,
946                                         (PermissionSet) null,
947                                         (PermissionSet) null);
948                                 Assert.Fail ("#C1");
949                         } catch (ArgumentException ex) {
950                                 // AssemblyName.Name cannot be null or an empty string
951                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
952                                 Assert.IsNull (ex.InnerException, "#C3");
953                                 Assert.IsNotNull (ex.Message, "#C4");
954                                 Assert.IsNull (ex.ParamName, "#C5");
955                         }
956                 }
957
958                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
959                 public void DefineDynamicAssembly7_Access_Invalid ()
960                 {
961                         AssemblyName name = new AssemblyName ();
962                         name.Name = "DefineDynamicAssembly7";
963
964 #if NET_2_0
965                         try {
966                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
967                                         name, AssemblyBuilderAccess.Run |
968                                         (AssemblyBuilderAccess) 666,
969                                         Path.GetTempPath (),
970                                         (PermissionSet) null,
971                                         (PermissionSet) null,
972                                         (PermissionSet) null);
973                                 Assert.Fail ("#1");
974                         } catch (ArgumentException ex) {
975                                 // Illegal enum value: 667
976                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
977                                 Assert.IsNull (ex.InnerException, "#3");
978                                 Assert.IsNotNull (ex.Message, "#4");
979                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
980                                 Assert.IsNotNull (ex.ParamName, "#6");
981                                 Assert.AreEqual ("access", ex.ParamName, "#7");
982                         }
983 #else
984                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
985                                 name, AssemblyBuilderAccess.Run |
986                                 (AssemblyBuilderAccess) 666,
987                                 Path.GetTempPath (),
988                                 (PermissionSet) null,
989                                 (PermissionSet) null,
990                                 (PermissionSet) null);
991                         Assert.IsNotNull (ab, "#1");
992 #endif
993                 }
994
995                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
996                 public void DefineDynamicAssembly7_Name_InvalidChars ()
997                 {
998                         string [] invalid_char_names = new string [] {
999                                 "\tAB",
1000                                 " AB",
1001                                 "\rAB",
1002                                 "A/B",
1003                                 ":AB",
1004                                 "B:A",
1005                                 "B\\A",
1006                                 "BA\\"};
1007
1008                         AssemblyName name = new AssemblyName ();
1009
1010                         foreach (string invalid_name in invalid_char_names) {
1011                                 name.Name = invalid_name;
1012                                 try {
1013                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
1014                                                 name,
1015                                                 AssemblyBuilderAccess.Run,
1016                                                 Path.GetTempPath (),
1017                                                 (PermissionSet) null,
1018                                                 (PermissionSet) null,
1019                                                 (PermissionSet) null);
1020                                         Assert.Fail ("#1:" + invalid_name);
1021                                 } catch (ArgumentException ex) {
1022                                         // Assembly names may not begin with whitespace
1023                                         // or contain the characters '/', '\' or ':'
1024                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1025                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1026                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1027                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1028                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1029                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1030                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1031                                 }
1032                         }
1033                 }
1034
1035                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
1036                 public void DefineDynamicAssembly7_Name_Null ()
1037                 {
1038                         try {
1039                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1040                                         (AssemblyName) null,
1041                                         AssemblyBuilderAccess.Run,
1042                                         Path.GetTempPath (),
1043                                         (PermissionSet) null,
1044                                         (PermissionSet) null,
1045                                         (PermissionSet) null);
1046                                 Assert.Fail ("#A1");
1047                         } catch (ArgumentNullException ex) {
1048                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1049                                 Assert.IsNull (ex.InnerException, "#A3");
1050                                 Assert.IsNotNull (ex.Message, "#A4");
1051                                 Assert.IsNotNull (ex.ParamName, "#A5");
1052                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
1053                         }
1054
1055                         AssemblyName name = new AssemblyName ();
1056
1057                         try {
1058                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1059                                         name,
1060                                         AssemblyBuilderAccess.Run,
1061                                         Path.GetTempPath (),
1062                                         (PermissionSet) null,
1063                                         (PermissionSet) null,
1064                                         (PermissionSet) null);
1065                                 Assert.Fail ("#B1");
1066                         } catch (ArgumentException ex) {
1067                                 // AssemblyName.Name cannot be null or an empty string
1068                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1069                                 Assert.IsNull (ex.InnerException, "#B3");
1070                                 Assert.IsNotNull (ex.Message, "#B4");
1071                                 Assert.IsNull (ex.ParamName, "#B5");
1072                         }
1073
1074                         name.Name = string.Empty;
1075
1076                         try {
1077                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1078                                         name,
1079                                         AssemblyBuilderAccess.Run,
1080                                         Path.GetTempPath (),
1081                                         (PermissionSet) null,
1082                                         (PermissionSet) null,
1083                                         (PermissionSet) null);
1084                                 Assert.Fail ("#C1");
1085                         } catch (ArgumentException ex) {
1086                                 // AssemblyName.Name cannot be null or an empty string
1087                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1088                                 Assert.IsNull (ex.InnerException, "#C3");
1089                                 Assert.IsNotNull (ex.Message, "#C4");
1090                                 Assert.IsNull (ex.ParamName, "#C5");
1091                         }
1092                 }
1093
1094                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
1095                 public void DefineDynamicAssembly8_Access_Invalid ()
1096                 {
1097                         AssemblyName name = new AssemblyName ();
1098                         name.Name = "DefineDynamicAssembly8";
1099
1100 #if NET_2_0
1101                         try {
1102                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1103                                         name, AssemblyBuilderAccess.Run |
1104                                         (AssemblyBuilderAccess) 666,
1105                                         Path.GetTempPath (),
1106                                         AppDomain.CurrentDomain.Evidence,
1107                                         (PermissionSet) null,
1108                                         (PermissionSet) null,
1109                                         (PermissionSet) null);
1110                                 Assert.Fail ("#1");
1111                         } catch (ArgumentException ex) {
1112                                 // Illegal enum value: 667
1113                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1114                                 Assert.IsNull (ex.InnerException, "#3");
1115                                 Assert.IsNotNull (ex.Message, "#4");
1116                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1117                                 Assert.IsNotNull (ex.ParamName, "#6");
1118                                 Assert.AreEqual ("access", ex.ParamName, "#7");
1119                         }
1120 #else
1121                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1122                                 name, AssemblyBuilderAccess.Run |
1123                                 (AssemblyBuilderAccess) 666,
1124                                 Path.GetTempPath (),
1125                                 AppDomain.CurrentDomain.Evidence,
1126                                 (PermissionSet) null,
1127                                 (PermissionSet) null,
1128                                 (PermissionSet) null);
1129                         Assert.IsNotNull (ab, "#1");
1130 #endif
1131                 }
1132
1133                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
1134                 public void DefineDynamicAssembly8_Name_InvalidChars ()
1135                 {
1136                         string [] invalid_char_names = new string [] {
1137                                 "\tAB",
1138                                 " AB",
1139                                 "\rAB",
1140                                 "A/B",
1141                                 ":AB",
1142                                 "B:A",
1143                                 "B\\A",
1144                                 "BA\\"};
1145
1146                         AssemblyName name = new AssemblyName ();
1147
1148                         foreach (string invalid_name in invalid_char_names) {
1149                                 name.Name = invalid_name;
1150                                 try {
1151                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
1152                                                 name,
1153                                                 AssemblyBuilderAccess.Run,
1154                                                 Path.GetTempPath (),
1155                                                 AppDomain.CurrentDomain.Evidence,
1156                                                 (PermissionSet) null,
1157                                                 (PermissionSet) null,
1158                                                 (PermissionSet) null);
1159                                         Assert.Fail ("#1:" + invalid_name);
1160                                 } catch (ArgumentException ex) {
1161                                         // Assembly names may not begin with whitespace
1162                                         // or contain the characters '/', '\' or ':'
1163                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1164                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1165                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1166                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1167                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1168                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1169                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1170                                 }
1171                         }
1172                 }
1173
1174                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
1175                 public void DefineDynamicAssembly8_Name_Null ()
1176                 {
1177                         try {
1178                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1179                                         (AssemblyName) null,
1180                                         AssemblyBuilderAccess.Run,
1181                                         Path.GetTempPath (),
1182                                         AppDomain.CurrentDomain.Evidence,
1183                                         (PermissionSet) null,
1184                                         (PermissionSet) null,
1185                                         (PermissionSet) null);
1186                                 Assert.Fail ("#A1");
1187                         } catch (ArgumentNullException ex) {
1188                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1189                                 Assert.IsNull (ex.InnerException, "#A3");
1190                                 Assert.IsNotNull (ex.Message, "#A4");
1191                                 Assert.IsNotNull (ex.ParamName, "#A5");
1192                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
1193                         }
1194
1195                         AssemblyName name = new AssemblyName ();
1196
1197                         try {
1198                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1199                                         name,
1200                                         AssemblyBuilderAccess.Run,
1201                                         Path.GetTempPath (),
1202                                         AppDomain.CurrentDomain.Evidence,
1203                                         (PermissionSet) null,
1204                                         (PermissionSet) null,
1205                                         (PermissionSet) null);
1206                                 Assert.Fail ("#B1");
1207                         } catch (ArgumentException ex) {
1208                                 // AssemblyName.Name cannot be null or an empty string
1209                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1210                                 Assert.IsNull (ex.InnerException, "#B3");
1211                                 Assert.IsNotNull (ex.Message, "#B4");
1212                                 Assert.IsNull (ex.ParamName, "#B5");
1213                         }
1214
1215                         name.Name = string.Empty;
1216
1217                         try {
1218                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1219                                         name,
1220                                         AssemblyBuilderAccess.Run,
1221                                         Path.GetTempPath (),
1222                                         AppDomain.CurrentDomain.Evidence,
1223                                         (PermissionSet) null,
1224                                         (PermissionSet) null,
1225                                         (PermissionSet) null);
1226                                 Assert.Fail ("#C1");
1227                         } catch (ArgumentException ex) {
1228                                 // AssemblyName.Name cannot be null or an empty string
1229                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1230                                 Assert.IsNull (ex.InnerException, "#C3");
1231                                 Assert.IsNotNull (ex.Message, "#C4");
1232                                 Assert.IsNull (ex.ParamName, "#C5");
1233                         }
1234                 }
1235
1236                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
1237                 public void DefineDynamicAssembly9_Access_Invalid ()
1238                 {
1239                         AssemblyName name = new AssemblyName ();
1240                         name.Name = "DefineDynamicAssembly9";
1241
1242 #if NET_2_0
1243                         try {
1244                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1245                                         name, AssemblyBuilderAccess.Run |
1246                                         (AssemblyBuilderAccess) 666,
1247                                         Path.GetTempPath (),
1248                                         AppDomain.CurrentDomain.Evidence,
1249                                         (PermissionSet) null,
1250                                         (PermissionSet) null,
1251                                         (PermissionSet) null,
1252                                         true);
1253                                 Assert.Fail ("#1");
1254                         } catch (ArgumentException ex) {
1255                                 // Illegal enum value: 667
1256                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1257                                 Assert.IsNull (ex.InnerException, "#3");
1258                                 Assert.IsNotNull (ex.Message, "#4");
1259                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1260                                 Assert.IsNotNull (ex.ParamName, "#6");
1261                                 Assert.AreEqual ("access", ex.ParamName, "#7");
1262                         }
1263 #else
1264                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1265                                 name, AssemblyBuilderAccess.Run |
1266                                 (AssemblyBuilderAccess) 666,
1267                                 Path.GetTempPath (),
1268                                 AppDomain.CurrentDomain.Evidence,
1269                                 (PermissionSet) null,
1270                                 (PermissionSet) null,
1271                                 (PermissionSet) null,
1272                                 true);
1273                         Assert.IsNotNull (ab, "#1");
1274 #endif
1275                 }
1276
1277                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
1278                 public void DefineDynamicAssembly9_Name_InvalidChars ()
1279                 {
1280                         string [] invalid_char_names = new string [] {
1281                                 "\tAB",
1282                                 " AB",
1283                                 "\rAB",
1284                                 "A/B",
1285                                 ":AB",
1286                                 "B:A",
1287                                 "B\\A",
1288                                 "BA\\"};
1289
1290                         AssemblyName name = new AssemblyName ();
1291
1292                         foreach (string invalid_name in invalid_char_names) {
1293                                 name.Name = invalid_name;
1294                                 try {
1295                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
1296                                                 name,
1297                                                 AssemblyBuilderAccess.Run,
1298                                                 Path.GetTempPath (),
1299                                                 AppDomain.CurrentDomain.Evidence,
1300                                                 (PermissionSet) null,
1301                                                 (PermissionSet) null,
1302                                                 (PermissionSet) null,
1303                                                 true);
1304                                         Assert.Fail ("#1:" + invalid_name);
1305                                 } catch (ArgumentException ex) {
1306                                         // Assembly names may not begin with whitespace
1307                                         // or contain the characters '/', '\' or ':'
1308                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1309                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1310                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1311                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1312                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1313                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1314                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1315                                 }
1316                         }
1317                 }
1318
1319                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
1320                 public void DefineDynamicAssembly9_Name_Null ()
1321                 {
1322                         try {
1323                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1324                                         (AssemblyName) null,
1325                                         AssemblyBuilderAccess.Run,
1326                                         Path.GetTempPath (),
1327                                         AppDomain.CurrentDomain.Evidence,
1328                                         (PermissionSet) null,
1329                                         (PermissionSet) null,
1330                                         (PermissionSet) null,
1331                                         true);
1332                                 Assert.Fail ("#A1");
1333                         } catch (ArgumentNullException ex) {
1334                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1335                                 Assert.IsNull (ex.InnerException, "#A3");
1336                                 Assert.IsNotNull (ex.Message, "#A4");
1337                                 Assert.IsNotNull (ex.ParamName, "#A5");
1338                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
1339                         }
1340
1341                         AssemblyName name = new AssemblyName ();
1342
1343                         try {
1344                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1345                                         name,
1346                                         AssemblyBuilderAccess.Run,
1347                                         Path.GetTempPath (),
1348                                         AppDomain.CurrentDomain.Evidence,
1349                                         (PermissionSet) null,
1350                                         (PermissionSet) null,
1351                                         (PermissionSet) null,
1352                                         true);
1353                                 Assert.Fail ("#B1");
1354                         } catch (ArgumentException ex) {
1355                                 // AssemblyName.Name cannot be null or an empty string
1356                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1357                                 Assert.IsNull (ex.InnerException, "#B3");
1358                                 Assert.IsNotNull (ex.Message, "#B4");
1359                                 Assert.IsNull (ex.ParamName, "#B5");
1360                         }
1361
1362                         name.Name = string.Empty;
1363
1364                         try {
1365                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1366                                         name,
1367                                         AssemblyBuilderAccess.Run,
1368                                         Path.GetTempPath (),
1369                                         AppDomain.CurrentDomain.Evidence,
1370                                         (PermissionSet) null,
1371                                         (PermissionSet) null,
1372                                         (PermissionSet) null,
1373                                         true);
1374                                 Assert.Fail ("#C1");
1375                         } catch (ArgumentException ex) {
1376                                 // AssemblyName.Name cannot be null or an empty string
1377                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1378                                 Assert.IsNull (ex.InnerException, "#C3");
1379                                 Assert.IsNotNull (ex.Message, "#C4");
1380                                 Assert.IsNull (ex.ParamName, "#C5");
1381                         }
1382                 }
1383
1384 #if NET_2_0
1385                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1386                 public void DefineDynamicAssembly10_Access_Invalid ()
1387                 {
1388                         AssemblyName name = new AssemblyName ();
1389                         name.Name = "DefineDynamicAssembly10";
1390
1391 #if NET_2_0
1392                         try {
1393                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1394                                         name, AssemblyBuilderAccess.Run |
1395                                         (AssemblyBuilderAccess) 666,
1396                                         Path.GetTempPath (),
1397                                         AppDomain.CurrentDomain.Evidence,
1398                                         (PermissionSet) null,
1399                                         (PermissionSet) null,
1400                                         (PermissionSet) null,
1401                                         true,
1402                                         new List<CustomAttributeBuilder> ());
1403                                 Assert.Fail ("#1");
1404                         } catch (ArgumentException ex) {
1405                                 // Illegal enum value: 667
1406                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1407                                 Assert.IsNull (ex.InnerException, "#3");
1408                                 Assert.IsNotNull (ex.Message, "#4");
1409                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1410                                 Assert.IsNotNull (ex.ParamName, "#6");
1411                                 Assert.AreEqual ("access", ex.ParamName, "#7");
1412                         }
1413 #else
1414                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1415                                 name, AssemblyBuilderAccess.Run |
1416                                 (AssemblyBuilderAccess) 666,
1417                                 Path.GetTempPath (),
1418                                 AppDomain.CurrentDomain.Evidence,
1419                                 (PermissionSet) null,
1420                                 (PermissionSet) null,
1421                                 (PermissionSet) null,
1422                                 true,
1423                                 new List<CustomAttributeBuilder> ());
1424                         Assert.IsNotNull (ab, "#1");
1425 #endif
1426                 }
1427
1428                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1429                 public void DefineDynamicAssembly10_Name_InvalidChars ()
1430                 {
1431                         string [] invalid_char_names = new string [] {
1432                                 "\tAB",
1433                                 " AB",
1434                                 "\rAB",
1435                                 "A/B",
1436                                 ":AB",
1437                                 "B:A",
1438                                 "B\\A",
1439                                 "BA\\"};
1440
1441                         AssemblyName name = new AssemblyName ();
1442
1443                         foreach (string invalid_name in invalid_char_names) {
1444                                 name.Name = invalid_name;
1445                                 try {
1446                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
1447                                                 name,
1448                                                 AssemblyBuilderAccess.Run,
1449                                                 Path.GetTempPath (),
1450                                                 AppDomain.CurrentDomain.Evidence,
1451                                                 (PermissionSet) null,
1452                                                 (PermissionSet) null,
1453                                                 (PermissionSet) null,
1454                                                 true,
1455                                                 new List<CustomAttributeBuilder> ());
1456                                         Assert.Fail ("#1:" + invalid_name);
1457                                 } catch (ArgumentException ex) {
1458                                         // Assembly names may not begin with whitespace
1459                                         // or contain the characters '/', '\' or ':'
1460                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1461                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1462                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1463                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1464                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1465                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1466                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1467                                 }
1468                         }
1469                 }
1470
1471                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1472                 public void DefineDynamicAssembly10_Name_Null ()
1473                 {
1474                         try {
1475                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1476                                         (AssemblyName) null,
1477                                         AssemblyBuilderAccess.Run,
1478                                         Path.GetTempPath (),
1479                                         AppDomain.CurrentDomain.Evidence,
1480                                         (PermissionSet) null,
1481                                         (PermissionSet) null,
1482                                         (PermissionSet) null,
1483                                         true,
1484                                         new List<CustomAttributeBuilder> ());
1485                                 Assert.Fail ("#A1");
1486                         } catch (ArgumentNullException ex) {
1487                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1488                                 Assert.IsNull (ex.InnerException, "#A3");
1489                                 Assert.IsNotNull (ex.Message, "#A4");
1490                                 Assert.IsNotNull (ex.ParamName, "#A5");
1491                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
1492                         }
1493
1494                         AssemblyName name = new AssemblyName ();
1495
1496                         try {
1497                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1498                                         name,
1499                                         AssemblyBuilderAccess.Run,
1500                                         Path.GetTempPath (),
1501                                         AppDomain.CurrentDomain.Evidence,
1502                                         (PermissionSet) null,
1503                                         (PermissionSet) null,
1504                                         (PermissionSet) null,
1505                                         true,
1506                                         new List<CustomAttributeBuilder> ());
1507                                 Assert.Fail ("#B1");
1508                         } catch (ArgumentException ex) {
1509                                 // AssemblyName.Name cannot be null or an empty string
1510                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1511                                 Assert.IsNull (ex.InnerException, "#B3");
1512                                 Assert.IsNotNull (ex.Message, "#B4");
1513                                 Assert.IsNull (ex.ParamName, "#B5");
1514                         }
1515
1516                         name.Name = string.Empty;
1517
1518                         try {
1519                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1520                                         name,
1521                                         AssemblyBuilderAccess.Run,
1522                                         Path.GetTempPath (),
1523                                         AppDomain.CurrentDomain.Evidence,
1524                                         (PermissionSet) null,
1525                                         (PermissionSet) null,
1526                                         (PermissionSet) null,
1527                                         true,
1528                                         new List<CustomAttributeBuilder> ());
1529                                 Assert.Fail ("#C1");
1530                         } catch (ArgumentException ex) {
1531                                 // AssemblyName.Name cannot be null or an empty string
1532                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1533                                 Assert.IsNull (ex.InnerException, "#C3");
1534                                 Assert.IsNotNull (ex.Message, "#C4");
1535                                 Assert.IsNull (ex.ParamName, "#C5");
1536                         }
1537                 }
1538
1539                 [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
1540                 public void DefineDynamicAssembly11 ()
1541                 {
1542                         List<CustomAttributeBuilder> cattrs;
1543                         AssemblyBuilder ab;
1544                         Attribute attr;
1545                         AssemblyName name;
1546                         string assemblyFile;
1547                         string current_dir = Directory.GetCurrentDirectory ();
1548
1549                         name = new AssemblyName ();
1550                         name.Name = "DefineDynamicAssembly11A";
1551
1552                         cattrs = new List<CustomAttributeBuilder> ();
1553                         cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).
1554                                 GetConstructor (new Type [] { typeof (string) }),
1555                                 new object [] { "1.2.3.4"}));
1556                         cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).
1557                                 GetConstructor (new Type [] { typeof (string) }),
1558                                 new object [] { "nl-BE"}));
1559                         cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).
1560                                 GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }),
1561                                 new object [] { AssemblyHashAlgorithm.MD5 }));
1562                         cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).
1563                                 GetConstructor (new Type [] { typeof (uint) }),
1564                                 new object [] { (uint)0x0100 }));
1565                         cattrs.Add (new CustomAttributeBuilder (typeof (CLSCompliantAttribute).
1566                                 GetConstructor (new Type [] { typeof (bool) }),
1567                                 new object [] { true }));
1568
1569                         ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1570                                 name, AssemblyBuilderAccess.Save, cattrs);
1571
1572                         ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (ComVisibleAttribute).
1573                                 GetConstructor (new Type [] { typeof (bool) }),
1574                                 new object [] { true }));
1575
1576                         ab.Save ("DefineDynamicAssembly11A.dll");
1577
1578                         assemblyFile = Path.Combine (current_dir, "DefineDynamicAssembly11A.dll");
1579
1580                         try {
1581                                 AssemblyName an = AssemblyName.GetAssemblyName (assemblyFile);
1582                                 Assert.AreEqual (CultureInfo.InvariantCulture, an.CultureInfo, "#A1");
1583                                 Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#A2");
1584                                 Assert.AreEqual ("DefineDynamicAssembly11A, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", an.FullName, "#A3");
1585                                 Assert.IsNull (an.GetPublicKey (), "#A4");
1586                                 Assert.AreEqual (new byte [0], an.GetPublicKeyToken (), "#A5");
1587                                 Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "#A6");
1588                                 Assert.IsNull (an.KeyPair, "#A7");
1589                                 Assert.AreEqual ("DefineDynamicAssembly11A", an.Name, "#A8");
1590                                 //Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "#A9");
1591                                 Assert.AreEqual (an.FullName, an.ToString (), "#A10");
1592                                 Assert.AreEqual (new Version (0, 0, 0, 0), an.Version, "#A11");
1593                                 Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, an.VersionCompatibility, "#A12");
1594
1595                                 Assembly a;
1596
1597                                 using (FileStream fs = File.OpenRead (assemblyFile)) {
1598                                         byte [] buffer = new byte [fs.Length];
1599                                         fs.Read (buffer, 0, buffer.Length);
1600                                         a = Assembly.Load (buffer);
1601                                 }
1602
1603                                 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyVersionAttribute));
1604                                 Assert.IsNotNull (attr, "#A13a");
1605                                 Assert.AreEqual ("1.2.3.4", ((AssemblyVersionAttribute) attr).Version, "#A13b");
1606                                 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyCultureAttribute));
1607                                 Assert.IsNotNull (attr, "#A14a");
1608                                 Assert.AreEqual ("nl-BE", ((AssemblyCultureAttribute) attr).Culture, "#A14b");
1609                                 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyAlgorithmIdAttribute));
1610                                 Assert.IsNotNull (attr, "#A15a");
1611                                 Assert.AreEqual ((uint) AssemblyHashAlgorithm.MD5, ((AssemblyAlgorithmIdAttribute) attr).AlgorithmId, "#A15b");
1612                                 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyFlagsAttribute));
1613                                 Assert.IsNotNull (attr, "#A16a");
1614                                 Assert.AreEqual ((uint) 0x0100, ((AssemblyFlagsAttribute) attr).Flags, "#A16b");
1615                                 attr = Attribute.GetCustomAttribute (a, typeof (CLSCompliantAttribute));
1616                                 Assert.IsNotNull (attr, "#A17a");
1617                                 Assert.IsTrue (((CLSCompliantAttribute) attr).IsCompliant, "#A17b");
1618                                 attr = Attribute.GetCustomAttribute (a, typeof (ComVisibleAttribute));
1619                                 Assert.IsNotNull (attr, "#A18a");
1620                                 Assert.IsTrue (((ComVisibleAttribute) attr).Value, "#A18b");
1621                         } finally {
1622                                 File.Delete (assemblyFile);
1623                         }
1624
1625                         name = new AssemblyName ();
1626                         name.CultureInfo = new CultureInfo ("fr-BE");
1627                         name.KeyPair = new StrongNameKeyPair (keyPair);
1628                         name.Name = "DefineDynamicAssembly11B";
1629                         name.Version = new Version (3, 2, 4, 1);
1630
1631                         cattrs = new List<CustomAttributeBuilder> ();
1632                         cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).
1633                                 GetConstructor (new Type [] { typeof (string) }),
1634                                 new object [] { "1.2.3.4"}));
1635                         cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).
1636                                 GetConstructor (new Type [] { typeof (string) }),
1637                                 new object [] { "nl-BE"}));
1638                         cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).
1639                                 GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }),
1640                                 new object [] { AssemblyHashAlgorithm.MD5 }));
1641                         cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).
1642                                 GetConstructor (new Type [] { typeof (uint) }),
1643                                 new object [] { (uint)0x0100 }));
1644                         cattrs.Add (new CustomAttributeBuilder (typeof (CLSCompliantAttribute).
1645                                 GetConstructor (new Type [] { typeof (bool) }),
1646                                 new object [] { true }));
1647
1648                         ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1649                                 name, AssemblyBuilderAccess.Save, cattrs);
1650
1651                         ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (ComVisibleAttribute).
1652                                 GetConstructor (new Type [] { typeof (bool) }),
1653                                 new object [] { true }));
1654
1655                         ab.Save ("DefineDynamicAssembly11B.dll");
1656
1657                         assemblyFile = Path.Combine (current_dir, "DefineDynamicAssembly11B.dll");
1658
1659                         try {
1660                                 AssemblyName an = AssemblyName.GetAssemblyName (assemblyFile);
1661                                 Assert.AreEqual ("fr-BE", an.CultureInfo.Name, "#B1");
1662                                 Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#B2");
1663                                 Assert.AreEqual ("DefineDynamicAssembly11B, Version=3.2.4.1, Culture=fr-BE, PublicKeyToken=ce5276d8687ec6dc", an.FullName, "#B3");
1664                                 Assert.AreEqual (publicKey, an.GetPublicKey (), "#B4");
1665                                 Assert.AreEqual (pk_token, an.GetPublicKeyToken (), "#B5");
1666                                 Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "#B6");
1667                                 Assert.IsNull (an.KeyPair, "#B7");
1668                                 Assert.AreEqual ("DefineDynamicAssembly11B", an.Name, "#B8");
1669                                 //Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "#B9");
1670                                 Assert.AreEqual (an.FullName, an.ToString (), "#B10");
1671                                 Assert.AreEqual (new Version (3, 2, 4, 1), an.Version, "#B11");
1672                                 Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, an.VersionCompatibility, "#B12");
1673
1674                                 Assembly a;
1675
1676                                 using (FileStream fs = File.OpenRead (assemblyFile)) {
1677                                         byte [] buffer = new byte [fs.Length];
1678                                         fs.Read (buffer, 0, buffer.Length);
1679                                         a = Assembly.Load (buffer);
1680                                 }
1681
1682                                 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyVersionAttribute));
1683                                 Assert.IsNotNull (attr, "#B13a");
1684                                 Assert.AreEqual ("1.2.3.4", ((AssemblyVersionAttribute) attr).Version, "#B13b");
1685                                 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyCultureAttribute));
1686                                 Assert.IsNotNull (attr, "#B14a");
1687                                 Assert.AreEqual ("nl-BE", ((AssemblyCultureAttribute) attr).Culture, "#B14b");
1688                                 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyAlgorithmIdAttribute));
1689                                 Assert.IsNotNull (attr, "#B15a");
1690                                 Assert.AreEqual ((uint) AssemblyHashAlgorithm.MD5, ((AssemblyAlgorithmIdAttribute) attr).AlgorithmId, "#B15b");
1691                                 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyFlagsAttribute));
1692                                 Assert.IsNotNull (attr, "#B16a");
1693                                 Assert.AreEqual ((uint) 0x0100, ((AssemblyFlagsAttribute) attr).Flags, "#B16b");
1694                                 attr = Attribute.GetCustomAttribute (a, typeof (CLSCompliantAttribute));
1695                                 Assert.IsNotNull (attr, "#B17a");
1696                                 Assert.IsTrue (((CLSCompliantAttribute) attr).IsCompliant, "#B17b");
1697                                 attr = Attribute.GetCustomAttribute (a, typeof (ComVisibleAttribute));
1698                                 Assert.IsNotNull (attr, "#B18a");
1699                                 Assert.IsTrue (((ComVisibleAttribute) attr).Value, "#B18b");
1700                         } finally {
1701                                 File.Delete (assemblyFile);
1702                         }
1703                 }
1704
1705                 [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
1706                 public void DefineDynamicAssembly11_Access_Invalid ()
1707                 {
1708                         AssemblyName name = new AssemblyName ();
1709                         name.Name = "DefineDynamicAssembly11";
1710
1711 #if NET_2_0
1712                         try {
1713                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1714                                         name, AssemblyBuilderAccess.Run |
1715                                         (AssemblyBuilderAccess) 666,
1716                                         new List<CustomAttributeBuilder> ());
1717                                 Assert.Fail ("#1");
1718                         } catch (ArgumentException ex) {
1719                                 // Illegal enum value: 667
1720                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1721                                 Assert.IsNull (ex.InnerException, "#3");
1722                                 Assert.IsNotNull (ex.Message, "#4");
1723                                 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1724                                 Assert.IsNotNull (ex.ParamName, "#6");
1725                                 Assert.AreEqual ("access", ex.ParamName, "#7");
1726                         }
1727 #else
1728                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1729                                 name, AssemblyBuilderAccess.Run |
1730                                 (AssemblyBuilderAccess) 666,
1731                                 new List<CustomAttributeBuilder> ());
1732                         Assert.IsNotNull (ab, "#1");
1733 #endif
1734                 }
1735
1736                 [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
1737                 public void DefineDynamicAssembly11_Name_InvalidChars ()
1738                 {
1739                         string [] invalid_char_names = new string [] {
1740                                 "\tAB",
1741                                 " AB",
1742                                 "\rAB",
1743                                 "A/B",
1744                                 ":AB",
1745                                 "B:A",
1746                                 "B\\A",
1747                                 "BA\\"};
1748
1749                         AssemblyName name = new AssemblyName ();
1750
1751                         foreach (string invalid_name in invalid_char_names) {
1752                                 name.Name = invalid_name;
1753                                 try {
1754                                         AppDomain.CurrentDomain.DefineDynamicAssembly (
1755                                                 name,
1756                                                 AssemblyBuilderAccess.Run,
1757                                                 new List<CustomAttributeBuilder> ());
1758                                         Assert.Fail ("#1:" + invalid_name);
1759                                 } catch (ArgumentException ex) {
1760                                         // Assembly names may not begin with whitespace
1761                                         // or contain the characters '/', '\' or ':'
1762                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1763                                         Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1764                                         Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1765                                         Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1766                                         Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1767                                         Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1768                                         Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1769                                 }
1770                         }
1771                 }
1772
1773                 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1774                 public void DefineDynamicAssembly11_Name_Null ()
1775                 {
1776                         try {
1777                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1778                                         (AssemblyName) null,
1779                                         AssemblyBuilderAccess.Run,
1780                                         new List<CustomAttributeBuilder> ());
1781                                 Assert.Fail ("#A1");
1782                         } catch (ArgumentNullException ex) {
1783                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1784                                 Assert.IsNull (ex.InnerException, "#A3");
1785                                 Assert.IsNotNull (ex.Message, "#A4");
1786                                 Assert.IsNotNull (ex.ParamName, "#A5");
1787                                 Assert.AreEqual ("name", ex.ParamName, "#A6");
1788                         }
1789
1790                         AssemblyName name = new AssemblyName ();
1791
1792                         try {
1793                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1794                                         name,
1795                                         AssemblyBuilderAccess.Run,
1796                                         new List<CustomAttributeBuilder> ());
1797                                 Assert.Fail ("#B1");
1798                         } catch (ArgumentException ex) {
1799                                 // AssemblyName.Name cannot be null or an empty string
1800                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1801                                 Assert.IsNull (ex.InnerException, "#B3");
1802                                 Assert.IsNotNull (ex.Message, "#B4");
1803                                 Assert.IsNull (ex.ParamName, "#B5");
1804                         }
1805
1806                         name.Name = string.Empty;
1807
1808                         try {
1809                                 AppDomain.CurrentDomain.DefineDynamicAssembly (
1810                                         name,
1811                                         AssemblyBuilderAccess.Run,
1812                                         new List<CustomAttributeBuilder> ());
1813                                 Assert.Fail ("#C1");
1814                         } catch (ArgumentException ex) {
1815                                 // AssemblyName.Name cannot be null or an empty string
1816                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1817                                 Assert.IsNull (ex.InnerException, "#C3");
1818                                 Assert.IsNotNull (ex.Message, "#C4");
1819                                 Assert.IsNull (ex.ParamName, "#C5");
1820                         }
1821                 }
1822
1823                 [Test] // ExecuteAssemblyByName (String)
1824                 public void ExecuteAssemblyByName1_NoEntryPoint ()
1825                 {
1826                         try {
1827                                 AppDomain.CurrentDomain.ExecuteAssemblyByName ("mscorlib");
1828                                 Assert.Fail ("#1");
1829                         } catch (MissingMethodException ex) {
1830                                 // Entry point not found in assembly '...'
1831                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1832                                 Assert.IsNull (ex.InnerException, "#3");
1833                                 Assert.IsNotNull (ex.Message, "#4");
1834                                 Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5");
1835                         }
1836                 }
1837
1838                 [Test] // ExecuteAssemblyByName (String, Evidence)
1839                 public void ExecuteAssemblyByName2_NoEntryPoint ()
1840                 {
1841                         try {
1842                                 AppDomain.CurrentDomain.ExecuteAssemblyByName (
1843                                         "mscorlib", (Evidence) null);
1844                                 Assert.Fail ("#1");
1845                         } catch (MissingMethodException ex) {
1846                                 // Entry point not found in assembly '...'
1847                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1848                                 Assert.IsNull (ex.InnerException, "#3");
1849                                 Assert.IsNotNull (ex.Message, "#4");
1850                                 Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5");
1851                         }
1852                 }
1853
1854                 [Test] // ExecuteAssemblyByName (String, Evidence, String [])
1855                 public void ExecuteAssemblyByName3_NoEntryPoint ()
1856                 {
1857                         try {
1858                                 AppDomain.CurrentDomain.ExecuteAssemblyByName (
1859                                         "mscorlib", (Evidence) null,
1860                                         new string [0]);
1861                                 Assert.Fail ("#1");
1862                         } catch (MissingMethodException ex) {
1863                                 // Entry point not found in assembly '...'
1864                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1865                                 Assert.IsNull (ex.InnerException, "#3");
1866                                 Assert.IsNotNull (ex.Message, "#4");
1867                                 Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5");
1868                         }
1869                 }
1870
1871                 [Test] // ExecuteAssemblyByName (AssemblyName, Evidence, String [])
1872                 public void ExecuteAssemblyByName4_NoEntryPoint ()
1873                 {
1874                         AssemblyName aname = new AssemblyName ("mscorlib");
1875
1876                         try {
1877                                 AppDomain.CurrentDomain.ExecuteAssemblyByName (
1878                                         aname, (Evidence) null, new string [0]);
1879                                 Assert.Fail ("#1");
1880                         } catch (MissingMethodException ex) {
1881                                 // Entry point not found in assembly '...'
1882                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1883                                 Assert.IsNull (ex.InnerException, "#3");
1884                                 Assert.IsNotNull (ex.Message, "#4");
1885                                 Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5");
1886                         }
1887                 }
1888 #endif
1889
1890                 [Test]
1891                 public void SetThreadPrincipal ()
1892                 {
1893                         IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
1894                         IPrincipal p = new GenericPrincipal (i, null);
1895                         ad = AppDomain.CreateDomain ("SetThreadPrincipal");
1896                         ad.SetThreadPrincipal (p);
1897                 }
1898
1899                 [Test]
1900                 [ExpectedException (typeof (ArgumentNullException))]
1901                 public void SetThreadPrincipalNull ()
1902                 {
1903                         AppDomain.CurrentDomain.SetThreadPrincipal (null);
1904                 }
1905
1906                 [Test]
1907                 [ExpectedException (typeof (PolicyException))]
1908                 public void SetThreadPrincipalTwice ()
1909                 {
1910                         IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
1911                         IPrincipal p = new GenericPrincipal (i, null);
1912                         ad = AppDomain.CreateDomain ("SetThreadPrincipalTwice");
1913                         ad.SetThreadPrincipal (p);
1914                         // you only live twice (or so James told me ;-)
1915                         ad.SetThreadPrincipal (p);
1916                 }
1917
1918                 [Test]
1919                 [ExpectedException (typeof (AppDomainUnloadedException))]
1920                 public void SetThreadPrincipalUnloaded ()
1921                 {
1922                         ad = AppDomain.CreateDomain ("Ximian");
1923                         AppDomain.Unload (ad);
1924                         IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
1925                         IPrincipal p = new GenericPrincipal (i, null);
1926                         ad.SetThreadPrincipal (p);
1927                 }
1928
1929                 [Test]
1930                 public void SetPrincipalPolicy_NoPrincipal ()
1931                 {
1932                         AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
1933                 }
1934
1935                 [Test]
1936                 public void SetPrincipalPolicy_UnauthenticatedPrincipal ()
1937                 {
1938                         AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.UnauthenticatedPrincipal);
1939                 }
1940
1941                 [Test]
1942                 public void SetPrincipalPolicy_WindowsPrincipal ()
1943                 {
1944                         AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.WindowsPrincipal);
1945                 }
1946
1947                 [Test]
1948                 [ExpectedException (typeof (AppDomainUnloadedException))]
1949                 public void SetPrincipalPolicyUnloaded ()
1950                 {
1951                         ad = AppDomain.CreateDomain ("Ximian");
1952                         AppDomain.Unload (ad);
1953                         ad.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
1954                 }
1955
1956                 [Test]
1957                 public void CreateDomain_String ()
1958                 {
1959                         ad = AppDomain.CreateDomain ("CreateDomain_String");
1960                         Assert.IsNotNull (ad.Evidence, "Evidence");
1961                         // Evidence are copied (or referenced?) from default app domain
1962                         // we can't get default so we use the current (which should have copied the default)
1963                         Assert.AreEqual (AppDomain.CurrentDomain.Evidence.Count, ad.Evidence.Count, "Evidence.Count");
1964                 }
1965
1966                 [Test]
1967                 [ExpectedException (typeof (ArgumentNullException))]
1968                 public void CreateDomain_String_Null ()
1969                 {
1970                         ad = AppDomain.CreateDomain (null);
1971                 }
1972
1973                 [Test]
1974                 [Category ("NotDotNet")]
1975                 public void CreateDomain_StringEvidence ()
1976                 {
1977                         Evidence e = new Evidence ();
1978                         ad = AppDomain.CreateDomain ("CreateDomain_StringEvidence", e);
1979                         Assert.IsNotNull (ad.Evidence, "Evidence");
1980                         Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
1981
1982                         e.AddHost (new Zone (SecurityZone.MyComputer));
1983                         Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
1984                         // evidence isn't copied but referenced
1985                 }
1986
1987                 [Test]
1988                 [ExpectedException (typeof (ArgumentNullException))]
1989                 public void CreateDomain_StringNullEvidence ()
1990                 {
1991                         ad = AppDomain.CreateDomain (null, new Evidence ());
1992                 }
1993
1994                 [Test]
1995                 public void CreateDomain_StringEvidenceNull ()
1996                 {
1997                         ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceNull", null);
1998                         Assert.IsNotNull (ad.Evidence, "Evidence");
1999                         // Evidence are copied (or referenced?) from default app domain
2000                         // we can't get default so we use the current (which should have copied the default)
2001                         Evidence e = AppDomain.CurrentDomain.Evidence;
2002                         Assert.AreEqual (e.Count, ad.Evidence.Count, "Evidence.Count-1");
2003                         e.AddHost (new Zone (SecurityZone.MyComputer));
2004                         Assert.AreEqual (e.Count - 1, ad.Evidence.Count, "Evidence.Count-2");
2005                         // evidence are copied
2006                 }
2007
2008                 [Test]
2009                 [Category ("NotDotNet")]
2010                 public void CreateDomain_StringEvidenceAppDomainSetup ()
2011                 {
2012                         Evidence e = new Evidence ();
2013                         AppDomainSetup info = new AppDomainSetup ();
2014                         info.ApplicationName = "ApplicationName";
2015
2016                         ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceAppDomainSetup", e, info);
2017                         Assert.IsNotNull (ad.Evidence, "Evidence");
2018                         Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
2019                         Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
2020                         Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName);
2021
2022                         e.AddHost (new Zone (SecurityZone.MyComputer));
2023                         Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
2024                         // evidence isn't copied but referenced
2025                 }
2026
2027                 [Test]
2028                 [ExpectedException (typeof (ArgumentNullException))]
2029                 public void CreateDomain_StringNullEvidenceAppDomainSetup ()
2030                 {
2031                         AppDomainSetup info = new AppDomainSetup ();
2032                         ad = AppDomain.CreateDomain (null, new Evidence (), info);
2033                 }
2034
2035                 [Test]
2036                 public void CreateDomain_StringEvidenceNullAppDomainSetup ()
2037                 {
2038                         AppDomainSetup info = new AppDomainSetup ();
2039                         info.ApplicationName = "ApplicationName";
2040                         ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceNullAppDomainSetup", null, info);
2041                         Assert.IsNotNull (ad.Evidence, "Evidence");
2042                         // Evidence are copied (or referenced?) from default app domain
2043                         // we can't get default so we use the current (which should have copied the default)
2044                         Assert.AreEqual (AppDomain.CurrentDomain.Evidence.Count, ad.Evidence.Count, "Evidence.Count");
2045                         Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName, "ApplicationName-1");
2046                         info.ApplicationName = "Test";
2047                         Assert.AreEqual ("Test", info.ApplicationName, "ApplicationName-2");
2048                         Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName, "ApplicationName-3");
2049                         // copied
2050                 }
2051
2052                 [Test]
2053                 [Category ("NotDotNet")]
2054                 public void CreateDomain_StringEvidenceAppDomainSetupNull ()
2055                 {
2056                         Evidence e = new Evidence ();
2057                         ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceAppDomainSetupNull", e, null);
2058                         Assert.IsNotNull (ad.Evidence, "Evidence");
2059                         Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
2060                         // SetupInformation is copied from default app domain
2061                         Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
2062                 }
2063
2064                 [Test] // ExecuteAssembly (String)
2065                 public void ExecuteAssembly1_NoEntryPoint ()
2066                 {
2067                         Assembly assembly = typeof (AppDomainTest).Assembly;
2068
2069                         try {
2070                                 AppDomain.CurrentDomain.ExecuteAssembly (
2071                                         assembly.Location);
2072                                 Assert.Fail ("#1");
2073 #if NET_2_0
2074                         } catch (MissingMethodException ex) {
2075                                 // Entry point not found in assembly '...'
2076                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2077                                 Assert.IsNull (ex.InnerException, "#3");
2078                                 Assert.IsNotNull (ex.Message, "#4");
2079                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2080                         }
2081 #else
2082                         } catch (COMException ex) {
2083                                 // Unspecified error
2084                                 Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
2085                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
2086                                 Assert.IsNull (ex.InnerException, "#4");
2087                                 Assert.IsNotNull (ex.Message, "#5");
2088                         }
2089 #endif
2090                 }
2091
2092                 [Test] // ExecuteAssembly (String, Evidence)
2093                 public void ExecuteAssembly2_NoEntryPoint ()
2094                 {
2095                         Assembly assembly = typeof (AppDomainTest).Assembly;
2096
2097                         try {
2098                                 AppDomain.CurrentDomain.ExecuteAssembly (
2099                                         assembly.Location,
2100                                         (Evidence) null);
2101                                 Assert.Fail ("#1");
2102 #if NET_2_0
2103                         } catch (MissingMethodException ex) {
2104                                 // Entry point not found in assembly '...'
2105                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2106                                 Assert.IsNull (ex.InnerException, "#3");
2107                                 Assert.IsNotNull (ex.Message, "#4");
2108                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2109                         }
2110 #else
2111                         } catch (COMException ex) {
2112                                 // Unspecified error
2113                                 Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
2114                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
2115                                 Assert.IsNull (ex.InnerException, "#4");
2116                                 Assert.IsNotNull (ex.Message, "#5");
2117                         }
2118 #endif
2119                 }
2120
2121                 [Test] // ExecuteAssembly (String, Evidence, String [])
2122                 public void ExecuteAssembly3_NoEntryPoint ()
2123                 {
2124                         Assembly assembly = typeof (AppDomainTest).Assembly;
2125
2126                         try {
2127                                 AppDomain.CurrentDomain.ExecuteAssembly (
2128                                         assembly.Location,
2129                                         (Evidence) null,
2130                                         new string [0]);
2131                                 Assert.Fail ("#1");
2132 #if NET_2_0
2133                         } catch (MissingMethodException ex) {
2134                                 // Entry point not found in assembly '...'
2135                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2136                                 Assert.IsNull (ex.InnerException, "#3");
2137                                 Assert.IsNotNull (ex.Message, "#4");
2138                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2139                         }
2140 #else
2141                         } catch (COMException ex) {
2142                                 // Unspecified error
2143                                 Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
2144                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
2145                                 Assert.IsNull (ex.InnerException, "#4");
2146                                 Assert.IsNotNull (ex.Message, "#5");
2147                         }
2148 #endif
2149                 }
2150
2151                 [Test] // ExecuteAssembly (String, Evidence, String [], Byte [], AssemblyHashAlgorithm)
2152                 [Category ("NotWorking")] // Not implemented
2153                 public void ExecuteAssembly4_NoEntryPoint ()
2154                 {
2155                         Assembly assembly = typeof (AppDomainTest).Assembly;
2156
2157                         try {
2158                                 AppDomain.CurrentDomain.ExecuteAssembly (
2159                                         assembly.Location,
2160                                         (Evidence) null,
2161                                         new string [0],
2162                                         (byte []) null,
2163                                         AssemblyHashAlgorithm.SHA1);
2164                                 Assert.Fail ("#1");
2165 #if NET_2_0
2166                         } catch (MissingMethodException ex) {
2167                                 // Entry point not found in assembly '...'
2168                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2169                                 Assert.IsNull (ex.InnerException, "#3");
2170                                 Assert.IsNotNull (ex.Message, "#4");
2171                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2172                         }
2173 #else
2174                         } catch (COMException ex) {
2175                                 // Unspecified error
2176                                 Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
2177                                 Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
2178                                 Assert.IsNull (ex.InnerException, "#4");
2179                                 Assert.IsNotNull (ex.Message, "#5");
2180                         }
2181 #endif
2182                 }
2183
2184                 [Test] // bug #79720
2185                 [Category ("NotWorking")]
2186                 public void Load_Loaded_Ignore ()
2187                 {
2188                         int assemblyStartCount = AppDomain.CurrentDomain.GetAssemblies ().Length;
2189
2190                         // PART A
2191
2192                         string assemblyFile = Path.Combine (tempDir, "bug79720A.dll");
2193                         AssemblyName aname = new AssemblyName ();
2194                         aname.Name = "bug79720A";
2195                         aname.Version = new Version (2, 4);
2196
2197                         GenerateAssembly (aname, assemblyFile);
2198
2199                         Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A1");
2200
2201                         aname = new AssemblyName ();
2202                         aname.Name = "bug79720A";
2203                         try {
2204                                 AppDomain.CurrentDomain.Load (aname);
2205                                 Assert.Fail ("#A2");
2206                         } catch (FileNotFoundException) {
2207                         }
2208
2209                         aname = new AssemblyName ();
2210                         aname.Name = "bug79720A";
2211                         aname.Version = new Version (0, 0, 0, 0);
2212                         try {
2213                                 AppDomain.CurrentDomain.Load (aname);
2214                                 Assert.Fail ("#A3");
2215                         } catch (FileNotFoundException) {
2216                         }
2217
2218                         aname = new AssemblyName ();
2219                         aname.Name = "bug79720A";
2220                         aname.Version = new Version (2, 4);
2221                         try {
2222                                 AppDomain.CurrentDomain.Load (aname);
2223                                 Assert.Fail ("#A4");
2224                         } catch (FileNotFoundException) {
2225                         }
2226
2227                         Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A5");
2228
2229                         Assembly.LoadFrom (assemblyFile);
2230
2231                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A6");
2232
2233                         aname = new AssemblyName ();
2234                         aname.Name = "bug79720A";
2235                         try {
2236                                 AppDomain.CurrentDomain.Load (aname);
2237                                 Assert.Fail ("#A7");
2238                         } catch (FileNotFoundException) {
2239                         }
2240
2241                         aname = new AssemblyName ();
2242                         aname.Name = "bug79720A";
2243                         aname.Version = new Version (0, 0, 0, 0);
2244                         try {
2245                                 AppDomain.CurrentDomain.Load (aname);
2246                                 Assert.Fail ("#A8");
2247                         } catch (FileNotFoundException) {
2248                         }
2249
2250                         aname = new AssemblyName ();
2251                         aname.Name = "bug79720A";
2252                         aname.Version = new Version (2, 4);
2253                         try {
2254                                 AppDomain.CurrentDomain.Load (aname);
2255                                 Assert.Fail ("#A9");
2256                         } catch (FileNotFoundException) {
2257                         }
2258
2259                         aname = new AssemblyName ();
2260                         aname.Name = "bug79720A";
2261                         aname.Version = new Version (2, 4);
2262                         aname.CultureInfo = CultureInfo.InvariantCulture;
2263                         try {
2264                                 AppDomain.CurrentDomain.Load (aname);
2265                                 Assert.Fail ("#A10");
2266                         } catch (FileNotFoundException) {
2267                         }
2268
2269                         aname = new AssemblyName ();
2270                         aname.Name = "bug79720A";
2271                         aname.Version = new Version (2, 4, 0, 0);
2272                         aname.CultureInfo = CultureInfo.InvariantCulture;
2273                         try {
2274                                 AppDomain.CurrentDomain.Load (aname);
2275                                 Assert.Fail ("#A11");
2276                         } catch (FileNotFoundException) {
2277                         }
2278
2279                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A12");
2280
2281                         // PART B
2282
2283                         assemblyFile = Path.Combine (tempDir, "bug79720B.dll");
2284                         aname = new AssemblyName ();
2285                         aname.Name = "bug79720B";
2286                         aname.Version = new Version (2, 4, 1);
2287                         aname.CultureInfo = new CultureInfo ("nl-BE");
2288
2289                         GenerateAssembly (aname, assemblyFile);
2290
2291                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B1");
2292
2293                         aname = new AssemblyName ();
2294                         aname.Name = "bug79720B";
2295                         try {
2296                                 AppDomain.CurrentDomain.Load (aname);
2297                                 Assert.Fail ("#B2");
2298                         } catch (FileNotFoundException) {
2299                         }
2300
2301                         aname = new AssemblyName ();
2302                         aname.Name = "bug79720B";
2303                         aname.Version = new Version (0, 0, 0, 0);
2304                         try {
2305                                 AppDomain.CurrentDomain.Load (aname);
2306                                 Assert.Fail ("#B3");
2307                         } catch (FileNotFoundException) {
2308                         }
2309
2310                         aname = new AssemblyName ();
2311                         aname.Name = "bug79720B";
2312                         aname.Version = new Version (2, 4, 1);
2313                         try {
2314                                 AppDomain.CurrentDomain.Load (aname);
2315                                 Assert.Fail ("#B4");
2316                         } catch (FileNotFoundException) {
2317                         }
2318
2319                         aname = new AssemblyName ();
2320                         aname.Name = "bug79720B";
2321                         aname.Version = new Version (2, 4, 1);
2322                         aname.CultureInfo = new CultureInfo ("nl-BE");
2323                         try {
2324                                 AppDomain.CurrentDomain.Load (aname);
2325                                 Assert.Fail ("#B5");
2326                         } catch (FileNotFoundException) {
2327                         }
2328
2329                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B6");
2330
2331                         Assembly.LoadFrom (assemblyFile);
2332
2333                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B7");
2334
2335                         aname = new AssemblyName ();
2336                         aname.Name = "bug79720B";
2337                         try {
2338                                 AppDomain.CurrentDomain.Load (aname);
2339                                 Assert.Fail ("#B8");
2340                         } catch (FileNotFoundException) {
2341                         }
2342
2343                         aname = new AssemblyName ();
2344                         aname.Name = "bug79720B";
2345                         aname.Version = new Version (0, 0, 0, 0);
2346                         try {
2347                                 AppDomain.CurrentDomain.Load (aname);
2348                                 Assert.Fail ("#B9");
2349                         } catch (FileNotFoundException) {
2350                         }
2351
2352                         aname = new AssemblyName ();
2353                         aname.Name = "bug79720B";
2354                         aname.Version = new Version (2, 4, 1);
2355                         try {
2356                                 AppDomain.CurrentDomain.Load (aname);
2357                                 Assert.Fail ("#B10");
2358                         } catch (FileNotFoundException) {
2359                         }
2360
2361                         aname = new AssemblyName ();
2362                         aname.Name = "bug79720B";
2363                         aname.Version = new Version (2, 4, 1);
2364                         aname.CultureInfo = new CultureInfo ("nl-BE");
2365                         try {
2366                                 AppDomain.CurrentDomain.Load (aname);
2367                                 Assert.Fail ("#B11");
2368                         } catch (FileNotFoundException) {
2369                         }
2370
2371                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B12");
2372
2373                         // PART C
2374
2375                         assemblyFile = Path.Combine (tempDir, "bug79720C.dll");
2376                         aname = new AssemblyName ();
2377                         aname.Name = "bug79720C";
2378                         aname.CultureInfo = new CultureInfo ("nl-BE");
2379                         aname.Version = new Version (2, 4);
2380                         aname.KeyPair = new StrongNameKeyPair (keyPair);
2381
2382                         GenerateAssembly (aname, assemblyFile);
2383
2384                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C1");
2385
2386                         aname = new AssemblyName ();
2387                         aname.Name = "bug79720C";
2388                         try {
2389                                 AppDomain.CurrentDomain.Load (aname);
2390                                 Assert.Fail ("#C2");
2391                         } catch (FileNotFoundException) {
2392                         }
2393
2394                         aname = new AssemblyName ();
2395                         aname.Name = "bug79720C";
2396                         aname.Version = new Version (0, 0, 0, 0);
2397                         try {
2398                                 AppDomain.CurrentDomain.Load (aname);
2399                                 Assert.Fail ("#C3");
2400                         } catch (FileNotFoundException) {
2401                         }
2402
2403                         aname = new AssemblyName ();
2404                         aname.Name = "bug79720C";
2405                         aname.Version = new Version (2, 4, 1);
2406                         try {
2407                                 AppDomain.CurrentDomain.Load (aname);
2408                                 Assert.Fail ("#C4");
2409                         } catch (FileNotFoundException) {
2410                         }
2411
2412                         aname = new AssemblyName ();
2413                         aname.Name = "bug79720C";
2414                         aname.Version = new Version (2, 4, 1);
2415                         aname.CultureInfo = new CultureInfo ("nl-BE");
2416                         try {
2417                                 AppDomain.CurrentDomain.Load (aname);
2418                                 Assert.Fail ("#C5");
2419                         } catch (FileNotFoundException) {
2420                         }
2421
2422                         aname = new AssemblyName ();
2423                         aname.Name = "bug79720C";
2424                         aname.Version = new Version (2, 4, 1);
2425                         aname.CultureInfo = new CultureInfo ("nl-BE");
2426                         aname.SetPublicKey (publicKey);
2427                         try {
2428                                 AppDomain.CurrentDomain.Load (aname);
2429                                 Assert.Fail ("#C6");
2430                         } catch (FileNotFoundException) {
2431                         }
2432
2433                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C7");
2434
2435                         Assembly.LoadFrom (assemblyFile);
2436
2437                         Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C8");
2438
2439                         aname = new AssemblyName ();
2440                         aname.Name = "bug79720C";
2441                         try {
2442                                 AppDomain.CurrentDomain.Load (aname);
2443                                 Assert.Fail ("#C9");
2444                         } catch (FileNotFoundException) {
2445                         }
2446
2447                         aname = new AssemblyName ();
2448                         aname.Name = "bug79720C";
2449                         aname.Version = new Version (0, 0, 0, 0);
2450                         try {
2451                                 AppDomain.CurrentDomain.Load (aname);
2452                                 Assert.Fail ("#C10");
2453                         } catch (FileNotFoundException) {
2454                         }
2455
2456                         aname = new AssemblyName ();
2457                         aname.Name = "bug79720C";
2458                         aname.Version = new Version (2, 4);
2459                         try {
2460                                 AppDomain.CurrentDomain.Load (aname);
2461                                 Assert.Fail ("#C11");
2462                         } catch (FileNotFoundException) {
2463                         }
2464
2465                         aname = new AssemblyName ();
2466                         aname.Name = "bug79720C";
2467                         aname.Version = new Version (2, 4);
2468                         aname.CultureInfo = new CultureInfo ("nl-BE");
2469                         try {
2470                                 AppDomain.CurrentDomain.Load (aname);
2471                                 Assert.Fail ("#C12");
2472                         } catch (FileNotFoundException) {
2473                         }
2474
2475                         aname = new AssemblyName ();
2476                         aname.Name = "bug79720C";
2477                         aname.Version = new Version (2, 4);
2478                         aname.CultureInfo = new CultureInfo ("nl-BE");
2479                         aname.SetPublicKey (publicKey);
2480                         try {
2481                                 AppDomain.CurrentDomain.Load (aname);
2482                                 Assert.Fail ("#C13");
2483                         } catch (FileNotFoundException) {
2484                         }
2485
2486                         Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C14");
2487                 }
2488
2489                 [Test]
2490                 [Category ("NotWorking")]
2491                 public void Load_Loaded_Multiple ()
2492                 {
2493                         string cultureDir = Path.Combine (tempDir, "nl-BE");
2494                         if (!Directory.Exists (cultureDir))
2495                                 Directory.CreateDirectory (cultureDir);
2496
2497                         AppDomain ad = CreateTestDomain (tempDir, true);
2498                         try {
2499                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
2500
2501                                 int assemblyCount = cdt.AssemblyCount;
2502
2503                                 // PART A
2504
2505                                 AssemblyName aname = new AssemblyName ();
2506                                 aname.Name = "multipleA";
2507                                 aname.Version = new Version (1, 2, 3, 4);
2508                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "multipleA.dll"));
2509
2510                                 Assert.AreEqual (assemblyCount + 1, cdt.AssemblyCount, "#A1");
2511
2512                                 aname = new AssemblyName ();
2513                                 aname.Name = "multipleA";
2514                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A2");
2515
2516                                 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A3");
2517
2518                                 aname = new AssemblyName ();
2519                                 aname.Name = "multipleA";
2520                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A4");
2521
2522                                 aname = new AssemblyName ();
2523                                 aname.Name = "multipleA";
2524                                 aname.CultureInfo = CultureInfo.InvariantCulture;
2525                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A5");
2526
2527                                 aname = new AssemblyName ();
2528                                 aname.Name = "multipleA";
2529                                 aname.CultureInfo = CultureInfo.InvariantCulture;
2530                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A6");
2531
2532                                 aname = new AssemblyName ();
2533                                 aname.Name = "multipleA";
2534                                 aname.CultureInfo = CultureInfo.InvariantCulture;
2535                                 aname.Version = new Version (1, 2, 3, 4);
2536                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A7");
2537
2538                                 aname = new AssemblyName ();
2539                                 aname.Name = "multipleA";
2540                                 aname.CultureInfo = CultureInfo.InvariantCulture;
2541                                 aname.Version = new Version (1, 2, 3, 4);
2542                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A8");
2543
2544                                 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A9");
2545
2546                                 // PART B
2547
2548                                 aname = new AssemblyName ();
2549                                 aname.Name = "multipleB";
2550                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2551                                 aname.Version = new Version (2, 4, 1, 0);
2552                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleB.dll"));
2553
2554                                 Assert.AreEqual (assemblyCount + 3, cdt.AssemblyCount, "#B1");
2555
2556                                 aname = new AssemblyName ();
2557                                 aname.Name = "multipleB";
2558                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B2");
2559
2560                                 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B3");
2561
2562                                 aname = new AssemblyName ();
2563                                 aname.Name = "multipleB";
2564                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B4");
2565
2566                                 aname = new AssemblyName ();
2567                                 aname.Name = "multipleB";
2568                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2569                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B5");
2570
2571                                 aname = new AssemblyName ();
2572                                 aname.Name = "multipleB";
2573                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2574                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B6");
2575
2576                                 aname = new AssemblyName ();
2577                                 aname.Name = "multipleB";
2578                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2579                                 aname.Version = new Version (2, 4, 1, 0);
2580                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B7");
2581
2582                                 aname = new AssemblyName ();
2583                                 aname.Name = "multipleB";
2584                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2585                                 aname.Version = new Version (2, 4, 1, 0);
2586                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B8");
2587
2588                                 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B9");
2589
2590                                 // PART C
2591
2592                                 aname = new AssemblyName ();
2593                                 aname.Name = "multipleC";
2594                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2595                                 aname.Version = new Version (2, 4, 0, 0);
2596                                 aname.KeyPair = new StrongNameKeyPair (keyPair);
2597                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleC.dll"));
2598
2599                                 Assert.AreEqual (assemblyCount + 5, cdt.AssemblyCount, "#C1");
2600
2601                                 aname = new AssemblyName ();
2602                                 aname.Name = "multipleC";
2603                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2604                                 aname.Version = new Version (2, 4, 0, 0);
2605                                 aname.SetPublicKey (publicKey);
2606                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C2");
2607
2608                                 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C3");
2609
2610                                 aname = new AssemblyName ();
2611                                 aname.Name = "multipleC";
2612                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2613                                 aname.Version = new Version (2, 4, 0, 0);
2614                                 aname.SetPublicKey (publicKey);
2615                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C4");
2616
2617                                 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C5");
2618                         } finally {
2619                                 AppDomain.Unload (ad);
2620                         }
2621                 }
2622
2623                 [Test] // bug #79522
2624                 [Category ("NotWorking")]
2625                 public void Load_Manifest_Mismatch ()
2626                 {
2627                         string assemblyFile = Path.Combine (tempDir, "bug79522A.dll");
2628                         AssemblyName aname = new AssemblyName ();
2629                         aname.Name = "bug79522A";
2630                         aname.Version = new Version (2, 4);
2631
2632                         GenerateAssembly (aname, assemblyFile);
2633
2634                         aname = new AssemblyName ();
2635                         aname.CodeBase = assemblyFile;
2636                         aname.Name = "whateveryouwant";
2637                         aname.Version = new Version (1, 1);
2638
2639                         // despite the fact that no assembly with the specified name
2640                         // exists, the assembly pointed to by the CodeBase of the
2641                         // AssemblyName will be loaded
2642                         //
2643                         // however the display name of the loaded assembly does not
2644                         // match the display name of the AssemblyName, and as a result
2645                         // a FileLoadException is thrown
2646                         try {
2647                                 AppDomain.CurrentDomain.Load (aname);
2648                                 Assert.Fail ("#A1");
2649                         } catch (FileLoadException) {
2650                         }
2651
2652                         // if we set CodeBase to some garbage, then we'll get a
2653                         // FileNotFoundException instead
2654                         aname.CodeBase = "whatever";
2655                         try {
2656                                 AppDomain.CurrentDomain.Load (aname);
2657                                 Assert.Fail ("#A2");
2658                         } catch (FileNotFoundException) {
2659                         }
2660
2661                         aname = new AssemblyName ();
2662                         aname.Name = "bug79522A";
2663                         aname.CodeBase = assemblyFile;
2664 #if NET_2_0
2665                         AppDomain.CurrentDomain.Load (aname);
2666 #else
2667                         try {
2668                                 AppDomain.CurrentDomain.Load (aname);
2669                                 Assert.Fail ("#A3");
2670                         } catch (FileLoadException) {
2671                         }
2672 #endif
2673
2674                         aname = new AssemblyName ();
2675                         aname.Name = "bug79522A";
2676                         aname.CodeBase = assemblyFile;
2677                         aname.Version = new Version (2, 5);
2678 #if NET_2_0
2679                         // the version number is not considered when comparing the manifest
2680                         // of the assembly found using codebase
2681                         AppDomain.CurrentDomain.Load (aname);
2682 #else
2683                         try {
2684                                 AppDomain.CurrentDomain.Load (aname);
2685                                 Assert.Fail ("#A4");
2686                         } catch (FileLoadException) {
2687                         }
2688 #endif
2689
2690                         aname = new AssemblyName ();
2691                         aname.Name = "bug79522A";
2692                         aname.CodeBase = assemblyFile;
2693                         aname.Version = new Version (2, 4, 1);
2694 #if NET_2_0
2695                         // the version number is not considered when comparing the manifest
2696                         // of the assembly found using codebase
2697                         AppDomain.CurrentDomain.Load (aname);
2698 #else
2699                         try {
2700                                 AppDomain.CurrentDomain.Load (aname);
2701                                 Assert.Fail ("#A5");
2702                         } catch (FileLoadException) {
2703                         }
2704 #endif
2705
2706                         // if version is set, then culture must also be set
2707                         aname = new AssemblyName ();
2708                         aname.Name = "bug79522A";
2709                         aname.CodeBase = assemblyFile;
2710                         aname.Version = new Version (2, 4);
2711 #if NET_2_0
2712                         AppDomain.CurrentDomain.Load (aname);
2713 #else
2714                         try {
2715                                 AppDomain.CurrentDomain.Load (aname);
2716                                 Assert.Fail ("#A6");
2717                         } catch (FileLoadException) {
2718                         }
2719 #endif
2720
2721                         // version number does not need to be set
2722                         aname = new AssemblyName ();
2723                         aname.Name = "bug79522A";
2724                         aname.CodeBase = assemblyFile;
2725                         aname.CultureInfo = CultureInfo.InvariantCulture;
2726                         AppDomain.CurrentDomain.Load (aname);
2727
2728                         // if set, the version number must match exactly
2729                         aname = new AssemblyName ();
2730                         aname.Name = "bug79522A";
2731                         aname.CodeBase = assemblyFile;
2732                         aname.CultureInfo = CultureInfo.InvariantCulture;
2733                         aname.Version = new Version (2, 4);
2734                         AppDomain.CurrentDomain.Load (aname);
2735
2736                         // if both culture and version are set, then the version diff
2737                         // is ignored
2738                         aname = new AssemblyName ();
2739                         aname.Name = "bug79522A";
2740                         aname.CodeBase = assemblyFile;
2741                         aname.CultureInfo = CultureInfo.InvariantCulture;
2742                         aname.Version = new Version (2, 5);
2743                         AppDomain.CurrentDomain.Load (aname);
2744
2745                         // loaded assembly is not signed
2746                         aname = new AssemblyName ();
2747                         aname.Name = "bug79522A";
2748                         aname.CodeBase = assemblyFile;
2749                         aname.CultureInfo = CultureInfo.InvariantCulture;
2750                         aname.Version = new Version (2, 4);
2751                         aname.SetPublicKey (publicKey);
2752                         try {
2753                                 AppDomain.CurrentDomain.Load (aname);
2754                                 Assert.Fail ("#A7");
2755                         } catch (FileLoadException) {
2756                         }
2757
2758                         // if set, the culture must match
2759                         aname = new AssemblyName ();
2760                         aname.Name = "bug79522A";
2761                         aname.CodeBase = assemblyFile;
2762                         aname.Version = new Version (2, 4);
2763                         aname.CultureInfo = new CultureInfo ("en-US");
2764                         try {
2765                                 AppDomain.CurrentDomain.Load (aname);
2766                                 Assert.Fail ("#A8");
2767                         } catch (FileLoadException) {
2768                         }
2769
2770                         // PART B
2771
2772                         assemblyFile = Path.Combine (tempDir, "bug79522B.dll");
2773                         aname = new AssemblyName ();
2774                         aname.Name = "bug79522B";
2775                         aname.CultureInfo = new CultureInfo ("nl-BE");
2776                         aname.Version = new Version (2, 4, 1);
2777
2778                         GenerateAssembly (aname, assemblyFile);
2779
2780                         aname = new AssemblyName ();
2781                         aname.CodeBase = assemblyFile;
2782                         aname.Name = "whateveryouwant";
2783                         aname.CultureInfo = new CultureInfo ("nl-BE");
2784                         aname.Version = new Version (1, 1);
2785
2786                         // despite the fact that no assembly with the specified name
2787                         // exists, the assembly pointed to by the CodeBase of the
2788                         // AssemblyName will be loaded
2789                         //
2790                         // however the display name of the loaded assembly does not
2791                         // match the display name of the AssemblyName, and as a result
2792                         // a FileLoadException is thrown
2793                         try {
2794                                 AppDomain.CurrentDomain.Load (aname);
2795                                 Assert.Fail ("#B1");
2796                         } catch (FileLoadException) {
2797                         }
2798
2799                         // if we set CodeBase to some garbage, then we'll get a
2800                         // FileNotFoundException instead
2801                         aname.CodeBase = "whatever";
2802                         try {
2803                                 AppDomain.CurrentDomain.Load (aname);
2804                                 Assert.Fail ("#B2");
2805                         } catch (FileNotFoundException) {
2806                         }
2807
2808                         aname = new AssemblyName ();
2809                         aname.Name = "bug79522B";
2810                         aname.CodeBase = assemblyFile;
2811 #if NET_2_0
2812                         // the version number is not considered when comparing the manifest
2813                         // of the assembly found using codebase
2814                         AppDomain.CurrentDomain.Load (aname);
2815 #else
2816                         try {
2817                                 AppDomain.CurrentDomain.Load (aname);
2818                                 Assert.Fail ("#B3");
2819                         } catch (FileLoadException) {
2820                         }
2821 #endif
2822
2823                         aname = new AssemblyName ();
2824                         aname.Name = "bug79522B";
2825                         aname.CodeBase = assemblyFile;
2826                         aname.Version = new Version (5, 5);
2827 #if NET_2_0
2828                         // the version number is not considered when comparing the manifest
2829                         // of the assembly found using codebase
2830                         AppDomain.CurrentDomain.Load (aname);
2831 #else
2832                         try {
2833                                 AppDomain.CurrentDomain.Load (aname);
2834                                 Assert.Fail ("#B3");
2835                         } catch (FileLoadException) {
2836                         }
2837 #endif
2838
2839                         aname = new AssemblyName ();
2840                         aname.Name = "bug79522B";
2841                         aname.CodeBase = assemblyFile;
2842                         aname.Version = new Version (2, 4, 1);
2843 #if NET_2_0
2844                         AppDomain.CurrentDomain.Load (aname);
2845 #else
2846                         // when the loaded assembly has a specific culture, then that
2847                         // culture must be set if you set the Version on the aname
2848                         try {
2849                                 AppDomain.CurrentDomain.Load (aname);
2850                                 Assert.Fail ("#B4");
2851                         } catch (FileLoadException) {
2852                         }
2853 #endif
2854
2855                         // version does not need to be set
2856                         aname = new AssemblyName ();
2857                         aname.Name = "bug79522B";
2858                         aname.CodeBase = assemblyFile;
2859                         aname.CultureInfo = new CultureInfo ("nl-BE");
2860                         AppDomain.CurrentDomain.Load (aname);
2861
2862                         // if both culture and version are set, then the version diff
2863                         // is ignored
2864                         aname = new AssemblyName ();
2865                         aname.Name = "bug79522B";
2866                         aname.CodeBase = assemblyFile;
2867                         aname.CultureInfo = new CultureInfo ("nl-BE");
2868                         aname.Version = new Version (6, 5);
2869                         AppDomain.CurrentDomain.Load (aname);
2870
2871                         // loaded assembly is not signed
2872                         aname = new AssemblyName ();
2873                         aname.Name = "bug79522B";
2874                         aname.CodeBase = assemblyFile;
2875                         aname.CultureInfo = new CultureInfo ("nl-BE");
2876                         aname.SetPublicKey (publicKey);
2877                         try {
2878                                 AppDomain.CurrentDomain.Load (aname);
2879                                 Assert.Fail ("#B5");
2880                         } catch (FileLoadException) {
2881                         }
2882
2883                         // if set, the culture must match
2884                         aname = new AssemblyName ();
2885                         aname.Name = "bug79522B";
2886                         aname.CodeBase = assemblyFile;
2887                         aname.Version = new Version (2, 4, 1);
2888                         aname.CultureInfo = new CultureInfo ("en-US");
2889                         try {
2890                                 AppDomain.CurrentDomain.Load (aname);
2891                                 Assert.Fail ("#B6");
2892                         } catch (FileLoadException) {
2893                         }
2894
2895                         // PART C
2896
2897                         assemblyFile = Path.Combine (tempDir, "bug79522C.dll");
2898                         aname = new AssemblyName ();
2899                         aname.Name = "bug79522C";
2900                         aname.CultureInfo = new CultureInfo ("nl-BE");
2901                         aname.Version = new Version (2, 4);
2902                         aname.KeyPair = new StrongNameKeyPair (keyPair);
2903
2904                         GenerateAssembly (aname, assemblyFile);
2905
2906                         aname = new AssemblyName ();
2907                         aname.CodeBase = assemblyFile;
2908                         aname.Name = "whateveryouwant";
2909                         aname.CultureInfo = new CultureInfo ("nl-BE");
2910                         aname.Version = new Version (1, 1);
2911                         aname.SetPublicKey (publicKey);
2912
2913                         // despite the fact that no assembly with the specified name
2914                         // exists, the assembly pointed to by the CodeBase of the
2915                         // AssemblyName will be loaded
2916                         //
2917                         // however the display name of the loaded assembly does not
2918                         // match the display name of the AssemblyName, and as a result
2919                         // a FileLoadException is thrown
2920                         try {
2921                                 AppDomain.CurrentDomain.Load (aname);
2922                                 Assert.Fail ("#C1");
2923                         } catch (FileLoadException) {
2924                         }
2925
2926                         // if we set CodeBase to some garbage, then we'll get a
2927                         // FileNotFoundException instead
2928                         aname.CodeBase = "whatever";
2929                         try {
2930                                 AppDomain.CurrentDomain.Load (aname);
2931                                 Assert.Fail ("#C2");
2932                         } catch (FileNotFoundException) {
2933                         }
2934
2935                         aname = new AssemblyName ();
2936                         aname.Name = "bug79522C";
2937                         aname.CodeBase = assemblyFile;
2938 #if NET_2_0
2939                         AppDomain.CurrentDomain.Load (aname);
2940 #else
2941                         try {
2942                                 AppDomain.CurrentDomain.Load (aname);
2943                                 Assert.Fail ("#C3");
2944                         } catch (FileLoadException) {
2945                         }
2946 #endif
2947
2948                         aname = new AssemblyName ();
2949                         aname.Name = "bug79522C";
2950                         aname.CodeBase = assemblyFile;
2951                         aname.Version = new Version (5, 5);
2952                         try {
2953                                 AppDomain.CurrentDomain.Load (aname);
2954                                 Assert.Fail ("#C3");
2955                         } catch (FileLoadException) {
2956                         }
2957
2958                         aname = new AssemblyName ();
2959                         aname.Name = "bug79522C";
2960                         aname.CodeBase = assemblyFile;
2961                         aname.Version = new Version (2, 4);
2962 #if NET_2_0
2963                         AppDomain.CurrentDomain.Load (aname);
2964 #else
2965                         // when the loaded assembly has a specific culture/publickey,
2966                         // then that culture/publickey must be set if you set the
2967                         // Version on the aname
2968                         try {
2969                                 AppDomain.CurrentDomain.Load (aname);
2970                                 Assert.Fail ("#C4");
2971                         } catch (FileLoadException) {
2972                         }
2973 #endif
2974
2975                         aname = new AssemblyName ();
2976                         aname.Name = "bug79522C";
2977                         aname.CodeBase = assemblyFile;
2978                         aname.CultureInfo = new CultureInfo ("nl-BE");
2979                         aname.Version = new Version (2, 4);
2980 #if NET_2_0
2981                         AppDomain.CurrentDomain.Load (aname);
2982 #else
2983                         // if loaded assembly is signed, then the public key must be set
2984                         try {
2985                                 AppDomain.CurrentDomain.Load (aname);
2986                                 Assert.Fail ("#C5");
2987                         } catch (FileLoadException) {
2988                         }
2989 #endif
2990
2991                         aname = new AssemblyName ();
2992                         aname.Name = "bug79522C";
2993                         aname.CodeBase = assemblyFile;
2994                         aname.CultureInfo = new CultureInfo ("nl-BE");
2995                         aname.SetPublicKey (publicKey);
2996 #if NET_2_0
2997                         AppDomain.CurrentDomain.Load (aname);
2998 #else
2999                         // if public key is set, then version must be set
3000                         try {
3001                                 AppDomain.CurrentDomain.Load (aname);
3002                                 Assert.Fail ("#C6");
3003                         } catch (FileLoadException) {
3004                         }
3005 #endif
3006
3007                         aname = new AssemblyName ();
3008                         aname.Name = "bug79522C";
3009                         aname.CodeBase = assemblyFile;
3010                         aname.CultureInfo = new CultureInfo ("nl-BE");
3011 #if NET_2_0
3012                         AppDomain.CurrentDomain.Load (aname);
3013 #else
3014                         try {
3015                                 AppDomain.CurrentDomain.Load (aname);
3016                                 Assert.Fail ("#C7");
3017                         } catch (FileLoadException) {
3018                         }
3019 #endif
3020
3021                         // if culture and version are set, then the version must match
3022                         aname = new AssemblyName ();
3023                         aname.Name = "bug79522C";
3024                         aname.CodeBase = assemblyFile;
3025                         aname.CultureInfo = new CultureInfo ("nl-BE");
3026                         aname.SetPublicKey (publicKey);
3027                         aname.Version = new Version (5, 6);
3028                         try {
3029                                 AppDomain.CurrentDomain.Load (aname);
3030                                 Assert.Fail ("#C8");
3031                         } catch (FileLoadException) {
3032                         }
3033
3034                         // publickey must match
3035                         aname = new AssemblyName ();
3036                         aname.Name = "bug79522C";
3037                         aname.CodeBase = assemblyFile;
3038                         aname.CultureInfo = new CultureInfo ("nl-BE");
3039                         aname.Version = new Version (2, 4);
3040                         aname.SetPublicKey (publicKey2);
3041                         try {
3042                                 AppDomain.CurrentDomain.Load (aname);
3043                                 Assert.Fail ("#C9");
3044 #if NET_2_0
3045                         } catch (SecurityException) {
3046                                 // Invalid assembly public key
3047                         }
3048 #else
3049                         } catch (FileLoadException) {
3050                         }
3051 #endif
3052
3053                         aname = new AssemblyName ();
3054                         aname.Name = "bug79522C";
3055                         aname.CodeBase = assemblyFile;
3056                         aname.SetPublicKey (publicKey);
3057                         aname.CultureInfo = new CultureInfo ("nl-BE");
3058                         aname.Version = new Version (2, 4);
3059                         AppDomain.CurrentDomain.Load (aname);
3060                 }
3061
3062                 [Test] // bug #79715
3063                 public void Load_PartialVersion ()
3064                 {
3065                         AppDomain ad = CreateTestDomain (tempDir, true);
3066                         try {
3067                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
3068
3069                                 AssemblyName aname = new AssemblyName ();
3070                                 aname.Name = "bug79715";
3071                                 aname.Version = new Version (1, 2, 3, 4);
3072                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "bug79715.dll"));
3073
3074                                 aname = new AssemblyName ();
3075                                 aname.Name = "bug79715";
3076                                 aname.Version = new Version (1, 2);
3077                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A1");
3078                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#A2");
3079
3080                                 aname = new AssemblyName ();
3081                                 aname.Name = "bug79715";
3082                                 aname.Version = new Version (1, 2, 3);
3083                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B1");
3084                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#B2");
3085
3086                                 aname = new AssemblyName ();
3087                                 aname.Name = "bug79715";
3088                                 aname.Version = new Version (1, 2, 3, 4);
3089                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C1");
3090                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#C2");
3091                         } finally {
3092                                 AppDomain.Unload (ad);
3093                         }
3094                 }
3095                 
3096                 [Test]
3097                 [ExpectedException (typeof (ArgumentException))]
3098                 public void Load_EmptyString ()
3099                 {
3100                         AppDomain.CurrentDomain.Load ("");
3101                 }
3102
3103                 [Test]
3104                 public void SetAppDomainPolicy ()
3105                 {
3106                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
3107                         ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
3108                         // not much to see
3109                 }
3110
3111                 [Test]
3112                 [ExpectedException (typeof (ArgumentNullException))]
3113                 public void SetAppDomainPolicy_Null ()
3114                 {
3115                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
3116                         ad.SetAppDomainPolicy (null);
3117                 }
3118
3119                 [Test]
3120                 [ExpectedException (typeof (PolicyException))]
3121                 public void SetAppDomainPolicy_Dual ()
3122                 {
3123                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Dual");
3124                         PolicyLevel pl = PolicyLevel.CreateAppDomainLevel ();
3125                         PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
3126                         pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
3127                         ad.SetAppDomainPolicy (pl);
3128
3129                         // only one time!
3130                         pl = PolicyLevel.CreateAppDomainLevel ();
3131                         ps = new PermissionSet (PermissionState.None);
3132                         pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
3133                         ad.SetAppDomainPolicy (pl);
3134                 }
3135
3136                 [Test]
3137                 [ExpectedException (typeof (AppDomainUnloadedException))]
3138                 public void SetAppDomainPolicy_Unloaded ()
3139                 {
3140                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Unloaded");
3141                         AppDomain.Unload (ad);
3142                         ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
3143                 }
3144
3145                 [Test]
3146                 [ExpectedException (typeof (ArgumentNullException))]
3147                 public void GetData_Null ()
3148                 {
3149                         AppDomain.CurrentDomain.GetData (null);
3150                 }
3151
3152                 [Test]
3153                 public void SetData ()
3154                 {
3155                         AppDomain.CurrentDomain.SetData ("data", "data");
3156                         Assert.AreEqual ("data", AppDomain.CurrentDomain.GetData ("data"), "GetData");
3157                         AppDomain.CurrentDomain.SetData ("data", null);
3158                         Assert.IsNull (AppDomain.CurrentDomain.GetData ("data"), "GetData-Null");
3159                 }
3160
3161                 [Test]
3162                 [ExpectedException (typeof (ArgumentNullException))]
3163                 public void SetData_Null ()
3164                 {
3165                         AppDomain.CurrentDomain.SetData (null, "data");
3166                 }
3167
3168 #if NET_2_0
3169                 [Test]
3170                 public void ApplyPolicy ()
3171                 {
3172                         ad = AppDomain.CreateDomain ("ApplyPolicy");
3173                         string fullname = Assembly.GetExecutingAssembly ().FullName;
3174                         string result = ad.ApplyPolicy (fullname);
3175                         Assert.AreEqual (fullname, result, "ApplyPolicy");
3176                         // doesn't even requires an assembly name
3177                         Assert.AreEqual ("123", ad.ApplyPolicy ("123"), "Invalid FullName");
3178                 }
3179
3180                 [Test]
3181                 [ExpectedException (typeof (ArgumentException))]
3182                 public void ApplyPolicy_Empty ()
3183                 {
3184                         ad = AppDomain.CreateDomain ("ApplyPolicy_Empty");
3185                         ad.ApplyPolicy (String.Empty);
3186                 }
3187
3188                 [Test]
3189                 [ExpectedException (typeof (ArgumentNullException))]
3190                 public void ApplyPolicy_Null ()
3191                 {
3192                         ad = AppDomain.CreateDomain ("ApplyPolicy_Null");
3193                         ad.ApplyPolicy (null);
3194                 }
3195
3196                 [Test]
3197                 public void DomainManager ()
3198                 {
3199                         Assert.IsNull (AppDomain.CurrentDomain.DomainManager, "CurrentDomain.DomainManager");
3200                         ad = AppDomain.CreateDomain ("DomainManager");
3201                         Assert.IsNull (ad.DomainManager, "ad.DomainManager");
3202                 }
3203
3204                 [Test]
3205                 public void IsDefaultAppDomain ()
3206                 {
3207                         ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
3208                         Assert.IsFalse (ad.IsDefaultAppDomain (), "IsDefaultAppDomain");
3209                         // we have no public way to get the default appdomain
3210                 }
3211
3212                 [Test]
3213                 public void ReflectionOnlyGetAssemblies ()
3214                 {
3215                         ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
3216                         Assembly [] a = ad.ReflectionOnlyGetAssemblies ();
3217                         Assert.IsNotNull (a, "ReflectionOnlyGetAssemblies");
3218                         Assert.AreEqual (0, a.Length, "Count");                 
3219
3220                         string assemblyFile = Path.Combine (tempDir, "bug499013.dll");
3221                         AssemblyName aname = new AssemblyName ();
3222                         aname.Name = "bug499013";
3223                         aname.Version = new Version (2, 4);
3224
3225                         GenerateAssembly (aname, assemblyFile);
3226
3227                         Assembly.ReflectionOnlyLoadFrom (assemblyFile);
3228                         foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies ())
3229                                 Assert.IsTrue (assembly.GetName ().Name != "bug499013");
3230                 }
3231
3232                 [Test]
3233                 public void ReflectionOnlyAssemblyResolve ()
3234                 {
3235                         AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
3236                         Assembly asm = Assembly.ReflectionOnlyLoad(Assembly.LoadWithPartialName("System").FullName);
3237                         asm.GetTypes();
3238                 }
3239
3240                 private static Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
3241                 {
3242                         return Assembly.ReflectionOnlyLoad(args.Name);
3243                 }
3244 #endif
3245
3246                 private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
3247                 {
3248                         AppDomainSetup setup = new AppDomainSetup ();
3249                         setup.ApplicationBase = baseDirectory;
3250                         setup.ApplicationName = "testdomain";
3251                         return CreateTestDomain (setup, assemblyResolver);
3252                 }
3253
3254                 private static AppDomain CreateTestDomain (AppDomainSetup setup, bool assemblyResolver)
3255                 {
3256                         AppDomain ad = AppDomain.CreateDomain ("testdomain",
3257                                 AppDomain.CurrentDomain.Evidence, setup);
3258
3259                         if (assemblyResolver) {
3260                                 Assembly ea = Assembly.GetExecutingAssembly ();
3261                                 ad.CreateInstanceFrom (ea.CodeBase,
3262                                         typeof (AssemblyResolveHandler).FullName,
3263                                         false,
3264                                         BindingFlags.Public | BindingFlags.Instance,
3265                                         null,
3266                                         new object [] { ea.Location, ea.FullName },
3267                                         CultureInfo.InvariantCulture,
3268                                         null,
3269                                         null);
3270                         }
3271
3272                         return ad;
3273                 }
3274
3275
3276                 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
3277                 {
3278                         Type testerType = typeof (CrossDomainTester);
3279                         return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
3280                                 testerType.Assembly.FullName, testerType.FullName, false,
3281                                 BindingFlags.Public | BindingFlags.Instance, null, new object [0],
3282                                 CultureInfo.InvariantCulture, new object [0], null);
3283                 }
3284
3285                 private static void GenerateAssembly (AssemblyName aname, string path)
3286                 {
3287                         AppDomain ad = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory,
3288                                 false);
3289                         try {
3290                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
3291                                 cdt.GenerateAssembly (aname, path);
3292                         } finally {
3293                                 AppDomain.Unload (ad);
3294                         }
3295                 }
3296
3297                 private bool RunningOnUnix {
3298                         get {
3299                                 // check for Unix platforms - see FAQ for more details
3300                                 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
3301                                 int platform = (int) Environment.OSVersion.Platform;
3302                                 return ((platform == 4) || (platform == 128) || (platform == 6));
3303                         }
3304                 }
3305
3306                 private class CrossDomainTester : MarshalByRefObject
3307                 {
3308                         public void GenerateAssembly (AssemblyName aname, string path)
3309                         {
3310                                 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
3311                                         aname, AssemblyBuilderAccess.Save, Path.GetDirectoryName (path));
3312                                 ab.Save (Path.GetFileName (path));
3313                         }
3314
3315                         public int AssemblyCount {
3316                                 get {
3317                                         return AppDomain.CurrentDomain.GetAssemblies ().Length;
3318                                 }
3319                         }
3320
3321                         public string GetApplicationBase ()
3322                         {
3323                                 return AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
3324                         }
3325
3326                         public string GetConfigurationFile ()
3327                         {
3328                                 return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
3329                         }
3330
3331                         public void Load (AssemblyName assemblyRef)
3332                         {
3333                                 AppDomain.CurrentDomain.Load (assemblyRef);
3334                         }
3335
3336                         public void LoadFrom (string assemblyFile)
3337                         {
3338                                 Assembly.LoadFrom (assemblyFile);
3339                         }
3340
3341                         public bool AssertLoad (AssemblyName assemblyRef)
3342                         {
3343                                 try {
3344                                         AppDomain.CurrentDomain.Load (assemblyRef);
3345                                         return true;
3346                                 } catch {
3347                                         return false;
3348                                 }
3349                         }
3350
3351                         public bool AssertLoad (string assemblyString)
3352                         {
3353                                 try {
3354                                         AppDomain.CurrentDomain.Load (assemblyString);
3355                                         return true;
3356                                 } catch {
3357                                         return false;
3358                                 }
3359                         }
3360
3361                         public bool AssertFileLoadException (AssemblyName assemblyRef)
3362                         {
3363                                 try {
3364                                         AppDomain.CurrentDomain.Load (assemblyRef);
3365                                         return false;
3366                                 } catch (FileLoadException) {
3367                                         return true;
3368                                 }
3369                         }
3370
3371                         public bool AssertFileNotFoundException (AssemblyName assemblyRef)
3372                         {
3373                                 try {
3374                                         AppDomain.CurrentDomain.Load (assemblyRef);
3375                                         return false;
3376                                 } catch (FileNotFoundException) {
3377                                         return true;
3378                                 }
3379                         }
3380                 }
3381
3382                 [Serializable ()]
3383                 private class AssemblyResolveHandler
3384                 {
3385                         public AssemblyResolveHandler (string assemblyFile, string assemblyName)
3386                         {
3387                                 _assemblyFile = assemblyFile;
3388                                 _assemblyName = assemblyName;
3389
3390                                 AppDomain.CurrentDomain.AssemblyResolve +=
3391                                         new ResolveEventHandler (ResolveAssembly);
3392                         }
3393
3394                         private Assembly ResolveAssembly (object sender, ResolveEventArgs args)
3395                         {
3396                                 if (args.Name == _assemblyName)
3397                                         return Assembly.LoadFrom (_assemblyFile);
3398
3399                                 return null;
3400                         }
3401
3402                         private readonly string _assemblyFile;
3403                         private readonly string _assemblyName;
3404                 }
3405
3406                 static byte [] keyPair = {
3407                         0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
3408                         0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3D, 0xBD,
3409                         0x72, 0x08, 0xC6, 0x2B, 0x0E, 0xA8, 0xC1, 0xC0, 0x58, 0x07, 0x2B,
3410                         0x63, 0x5F, 0x7C, 0x9A, 0xBD, 0xCB, 0x22, 0xDB, 0x20, 0xB2, 0xA9,
3411                         0xDA, 0xDA, 0xEF, 0xE8, 0x00, 0x64, 0x2F, 0x5D, 0x8D, 0xEB, 0x78,
3412                         0x02, 0xF7, 0xA5, 0x36, 0x77, 0x28, 0xD7, 0x55, 0x8D, 0x14, 0x68,
3413                         0xDB, 0xEB, 0x24, 0x09, 0xD0, 0x2B, 0x13, 0x1B, 0x92, 0x6E, 0x2E,
3414                         0x59, 0x54, 0x4A, 0xAC, 0x18, 0xCF, 0xC9, 0x09, 0x02, 0x3F, 0x4F,
3415                         0xA8, 0x3E, 0x94, 0x00, 0x1F, 0xC2, 0xF1, 0x1A, 0x27, 0x47, 0x7D,
3416                         0x10, 0x84, 0xF5, 0x14, 0xB8, 0x61, 0x62, 0x1A, 0x0C, 0x66, 0xAB,
3417                         0xD2, 0x4C, 0x4B, 0x9F, 0xC9, 0x0F, 0x3C, 0xD8, 0x92, 0x0F, 0xF5,
3418                         0xFF, 0xCE, 0xD7, 0x6E, 0x5C, 0x6F, 0xB1, 0xF5, 0x7D, 0xD3, 0x56,
3419                         0xF9, 0x67, 0x27, 0xA4, 0xA5, 0x48, 0x5B, 0x07, 0x93, 0x44, 0x00,
3420                         0x4A, 0xF8, 0xFF, 0xA4, 0xCB, 0x73, 0xC0, 0x6A, 0x62, 0xB4, 0xB7,
3421                         0xC8, 0x92, 0x58, 0x87, 0xCD, 0x07, 0x0C, 0x7D, 0x6C, 0xC1, 0x4A,
3422                         0xFC, 0x82, 0x57, 0x0E, 0x43, 0x85, 0x09, 0x75, 0x98, 0x51, 0xBB,
3423                         0x35, 0xF5, 0x64, 0x83, 0xC7, 0x79, 0x89, 0x5C, 0x55, 0x36, 0x66,
3424                         0xAB, 0x27, 0xA4, 0xD9, 0xD4, 0x7E, 0x6B, 0x67, 0x64, 0xC1, 0x54,
3425                         0x4E, 0x37, 0xF1, 0x4E, 0xCA, 0xB3, 0xE5, 0x63, 0x91, 0x57, 0x12,
3426                         0x14, 0xA6, 0xEA, 0x8F, 0x8F, 0x2B, 0xFE, 0xF3, 0xE9, 0x16, 0x08,
3427                         0x2B, 0x86, 0xBC, 0x26, 0x0D, 0xD0, 0xC6, 0xC4, 0x1A, 0x72, 0x43,
3428                         0x76, 0xDC, 0xFF, 0x28, 0x52, 0xA1, 0xDE, 0x8D, 0xFA, 0xD5, 0x1F,
3429                         0x0B, 0xB5, 0x4F, 0xAF, 0x06, 0x79, 0x11, 0xEE, 0xA8, 0xEC, 0xD3,
3430                         0x74, 0x55, 0xA2, 0x80, 0xFC, 0xF8, 0xD9, 0x50, 0x69, 0x48, 0x01,
3431                         0xC2, 0x5A, 0x04, 0x56, 0xB4, 0x3E, 0x24, 0x32, 0x20, 0xB5, 0x2C,
3432                         0xDE, 0xBB, 0xBD, 0x13, 0xFD, 0x13, 0xF7, 0x03, 0x3E, 0xE3, 0x37,
3433                         0x84, 0x74, 0xE7, 0xD0, 0x5E, 0x9E, 0xB6, 0x26, 0xAE, 0x6E, 0xB0,
3434                         0x55, 0x6A, 0x52, 0x63, 0x6F, 0x5A, 0x9D, 0xF2, 0x67, 0xD6, 0x61,
3435                         0x4F, 0x7A, 0x45, 0xEE, 0x5C, 0x3D, 0x2B, 0x7C, 0xB2, 0x40, 0x79,
3436                         0x54, 0x84, 0xD1, 0xBE, 0x61, 0x3E, 0x5E, 0xD6, 0x18, 0x8E, 0x14,
3437                         0x98, 0xFC, 0x35, 0xBF, 0x5F, 0x1A, 0x20, 0x2E, 0x1A, 0xD8, 0xFF,
3438                         0xC4, 0x6B, 0xC0, 0xC9, 0x7D, 0x06, 0xEF, 0x09, 0xF9, 0xF3, 0x69,
3439                         0xFC, 0xBC, 0xA2, 0xE6, 0x80, 0x22, 0xB9, 0x79, 0x7E, 0xEF, 0x57,
3440                         0x9F, 0x49, 0xE1, 0xBC, 0x0D, 0xB6, 0xA1, 0xFE, 0x8D, 0xBC, 0xBB,
3441                         0xA3, 0x05, 0x02, 0x6B, 0x04, 0x45, 0xF7, 0x5D, 0xEE, 0x43, 0x06,
3442                         0xD6, 0x9C, 0x94, 0x48, 0x1A, 0x0B, 0x9C, 0xBC, 0xB4, 0x4E, 0x93,
3443                         0x60, 0x87, 0xCD, 0x58, 0xD6, 0x9A, 0x39, 0xA6, 0xC0, 0x7F, 0x8E,
3444                         0xFF, 0x25, 0xC1, 0xD7, 0x2C, 0xF6, 0xF4, 0x6F, 0x24, 0x52, 0x0B,
3445                         0x39, 0x42, 0x1B, 0x0D, 0x04, 0xC1, 0x93, 0x2A, 0x19, 0x1C, 0xF0,
3446                         0xB1, 0x9B, 0xC1, 0x24, 0x6D, 0x1B, 0x0B, 0xDA, 0x1C, 0x8B, 0x72,
3447                         0x48, 0xF0, 0x3E, 0x52, 0xBF, 0x0A, 0x84, 0x3A, 0x9B, 0xC8, 0x6D,
3448                         0x13, 0x1E, 0x72, 0xF4, 0x46, 0x93, 0x88, 0x1A, 0x5F, 0x4C, 0x3C,
3449                         0xE5, 0x9D, 0x6E, 0xBB, 0x4E, 0xDD, 0x5D, 0x1F, 0x11, 0x40, 0xF4,
3450                         0xD7, 0xAF, 0xB3, 0xAB, 0x9A, 0x99, 0x15, 0xF0, 0xDC, 0xAA, 0xFF,
3451                         0x9F, 0x2D, 0x9E, 0x56, 0x4F, 0x35, 0x5B, 0xBA, 0x06, 0x99, 0xEA,
3452                         0xC6, 0xB4, 0x48, 0x51, 0x17, 0x1E, 0xD1, 0x95, 0x84, 0x81, 0x18,
3453                         0xC0, 0xF1, 0x71, 0xDE, 0x44, 0x42, 0x02, 0x06, 0xAC, 0x0E, 0xA8,
3454                         0xE2, 0xF3, 0x1F, 0x96, 0x1F, 0xBE, 0xB6, 0x1F, 0xB5, 0x3E, 0xF6,
3455                         0x81, 0x05, 0x20, 0xFA, 0x2E, 0x40, 0x2E, 0x4D, 0xA0, 0x0E, 0xDA,
3456                         0x42, 0x9C, 0x05, 0xAA, 0x9E, 0xAF, 0x5C, 0xF7, 0x3A, 0x3F, 0xBB,
3457                         0x91, 0x73, 0x45, 0x27, 0xA8, 0xA2, 0x07, 0x4A, 0xEF, 0x59, 0x1E,
3458                         0x97, 0x9D, 0xE0, 0x30, 0x5A, 0x83, 0xCE, 0x1E, 0x57, 0x32, 0x89,
3459                         0x43, 0x41, 0x28, 0x7D, 0x14, 0x8D, 0x8B, 0x41, 0x1A, 0x56, 0x76,
3460                         0x43, 0xDB, 0x64, 0x86, 0x41, 0x64, 0x8D, 0x4C, 0x91, 0x83, 0x4E,
3461                         0xF5, 0x6C };
3462
3463                 static byte [] publicKey2 = {
3464                         0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
3465                         0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x7F, 0x7C,
3466                         0xEA, 0x4A, 0x28, 0x33, 0xD8, 0x3C, 0x86, 0x90, 0x86, 0x91, 0x11,
3467                         0xBB, 0x30, 0x0D, 0x3D, 0x69, 0x04, 0x4C, 0x48, 0xF5, 0x4F, 0xE7,
3468                         0x64, 0xA5, 0x82, 0x72, 0x5A, 0x92, 0xC4, 0x3D, 0xC5, 0x90, 0x93,
3469                         0x41, 0xC9, 0x1D, 0x34, 0x16, 0x72, 0x2B, 0x85, 0xC1, 0xF3, 0x99,
3470                         0x62, 0x07, 0x32, 0x98, 0xB7, 0xE4, 0xFA, 0x75, 0x81, 0x8D, 0x08,
3471                         0xB9, 0xFD, 0xDB, 0x00, 0x25, 0x30, 0xC4, 0x89, 0x13, 0xB6, 0x43,
3472                         0xE8, 0xCC, 0xBE, 0x03, 0x2E, 0x1A, 0x6A, 0x4D, 0x36, 0xB1, 0xEB,
3473                         0x49, 0x26, 0x6C, 0xAB, 0xC4, 0x29, 0xD7, 0x8F, 0x25, 0x11, 0xA4,
3474                         0x7C, 0x81, 0x61, 0x97, 0xCB, 0x44, 0x2D, 0x80, 0x49, 0x93, 0x48,
3475                         0xA7, 0xC9, 0xAB, 0xDB, 0xCF, 0xA3, 0x34, 0xCB, 0x6B, 0x86, 0xE0,
3476                         0x4D, 0x27, 0xFC, 0xA7, 0x4F, 0x36, 0xCA, 0x13, 0x42, 0xD3, 0x83,
3477                         0xC4, 0x06, 0x6E, 0x12, 0xE0, 0xA1, 0x3D, 0x9F, 0xA9, 0xEC, 0xD1,
3478                         0xC6, 0x08, 0x1B, 0x3D, 0xF5, 0xDB, 0x4C, 0xD4, 0xF0, 0x2C, 0xAA,
3479                         0xFC, 0xBA, 0x18, 0x6F, 0x48, 0x7E, 0xB9, 0x47, 0x68, 0x2E, 0xF6,
3480                         0x1E, 0x67, 0x1C, 0x7E, 0x0A, 0xCE, 0x10, 0x07, 0xC0, 0x0C, 0xAD,
3481                         0x5E, 0xC1, 0x53, 0x70, 0xD5, 0xE7, 0x25, 0xCA, 0x37, 0x5E, 0x49,
3482                         0x59, 0xD0, 0x67, 0x2A, 0xBE, 0x92, 0x36, 0x86, 0x8A, 0xBF, 0x3E,
3483                         0x17, 0x04, 0xFB, 0x1F, 0x46, 0xC8, 0x10, 0x5C, 0x93, 0x02, 0x43,
3484                         0x14, 0x96, 0x6A, 0xD9, 0x87, 0x17, 0x62, 0x7D, 0x3A, 0x45, 0xBE,
3485                         0x35, 0xDE, 0x75, 0x0B, 0x2A, 0xCE, 0x7D, 0xF3, 0x19, 0x85, 0x4B,
3486                         0x0D, 0x6F, 0x8D, 0x15, 0xA3, 0x60, 0x61, 0x28, 0x55, 0x46, 0xCE,
3487                         0x78, 0x31, 0x04, 0x18, 0x3C, 0x56, 0x4A, 0x3F, 0xA4, 0xC9, 0xB1,
3488                         0x41, 0xED, 0x22, 0x80, 0xA1, 0xB3, 0xE2, 0xC7, 0x1B, 0x62, 0x85,
3489                         0xE4, 0x81, 0x39, 0xCB, 0x1F, 0x95, 0xCC, 0x61, 0x61, 0xDF, 0xDE,
3490                         0xF3, 0x05, 0x68, 0xB9, 0x7D, 0x4F, 0xFF, 0xF3, 0xC0, 0x0A, 0x25,
3491                         0x62, 0xD9, 0x8A, 0x8A, 0x9E, 0x99, 0x0B, 0xFB, 0x85, 0x27, 0x8D,
3492                         0xF6, 0xD4, 0xE1, 0xB9, 0xDE, 0xB4, 0x16, 0xBD, 0xDF, 0x6A, 0x25,
3493                         0x9C, 0xAC, 0xCD, 0x91, 0xF7, 0xCB, 0xC1, 0x81, 0x22, 0x0D, 0xF4,
3494                         0x7E, 0xEC, 0x0C, 0x84, 0x13, 0x5A, 0x74, 0x59, 0x3F, 0x3E, 0x61,
3495                         0x00, 0xD6, 0xB5, 0x4A, 0xA1, 0x04, 0xB5, 0xA7, 0x1C, 0x29, 0xD0,
3496                         0xE1, 0x11, 0x19, 0xD7, 0x80, 0x5C, 0xEE, 0x08, 0x15, 0xEB, 0xC9,
3497                         0xA8, 0x98, 0xF5, 0xA0, 0xF0, 0x92, 0x2A, 0xB0, 0xD3, 0xC7, 0x8C,
3498                         0x8D, 0xBB, 0x88, 0x96, 0x4F, 0x18, 0xF0, 0x8A, 0xF9, 0x31, 0x9E,
3499                         0x44, 0x94, 0x75, 0x6F, 0x78, 0x04, 0x10, 0xEC, 0xF3, 0xB0, 0xCE,
3500                         0xA0, 0xBE, 0x7B, 0x25, 0xE1, 0xF7, 0x8A, 0xA8, 0xD4, 0x63, 0xC2,
3501                         0x65, 0x47, 0xCC, 0x5C, 0xED, 0x7D, 0x8B, 0x07, 0x4D, 0x76, 0x29,
3502                         0x53, 0xAC, 0x27, 0x8F, 0x5D, 0x78, 0x56, 0xFA, 0x99, 0x45, 0xA2,
3503                         0xCC, 0x65, 0xC4, 0x54, 0x13, 0x9F, 0x38, 0x41, 0x7A, 0x61, 0x0E,
3504                         0x0D, 0x34, 0xBC, 0x11, 0xAF, 0xE2, 0xF1, 0x8B, 0xFA, 0x2B, 0x54,
3505                         0x6C, 0xA3, 0x6C, 0x09, 0x1F, 0x0B, 0x43, 0x9B, 0x07, 0x95, 0x83,
3506                         0x3F, 0x97, 0x99, 0x89, 0xF5, 0x51, 0x41, 0xF6, 0x8E, 0x5D, 0xEF,
3507                         0x6D, 0x24, 0x71, 0x41, 0x7A, 0xAF, 0xBE, 0x81, 0x71, 0xAB, 0x76,
3508                         0x2F, 0x1A, 0x5A, 0xBA, 0xF3, 0xA6, 0x65, 0x7A, 0x80, 0x50, 0xCE,
3509                         0x23, 0xC3, 0xC7, 0x53, 0xB0, 0x7C, 0x97, 0x77, 0x27, 0x70, 0x98,
3510                         0xAE, 0xB5, 0x24, 0x66, 0xE1, 0x60, 0x39, 0x41, 0xDA, 0x54, 0x01,
3511                         0x64, 0xFB, 0x10, 0x33, 0xCE, 0x8B, 0xBE, 0x27, 0xD4, 0x21, 0x57,
3512                         0xCC, 0x0F, 0x1A, 0xC1, 0x3D, 0xF3, 0xCC, 0x39, 0xF0, 0x2F, 0xAE,
3513                         0xF1, 0xC0, 0xCD, 0x3B, 0x23, 0x87, 0x49, 0x7E, 0x40, 0x32, 0x6A,
3514                         0xD3, 0x96, 0x4A, 0xE5, 0x5E, 0x6E, 0x26, 0xFD, 0x8A, 0xCF, 0x7E,
3515                         0xFC, 0x37, 0xDE, 0x39, 0x0C, 0x53, 0x81, 0x75, 0x08, 0xAF, 0x6B,
3516                         0x39, 0x6C, 0xFB, 0xC9, 0x79, 0xC0, 0x9B, 0x5F, 0x34, 0x86, 0xB2,
3517                         0xDE, 0xC4, 0x19, 0x84, 0x5F, 0x0E, 0xED, 0x9B, 0xB8, 0xD3, 0x17,
3518                         0xDA, 0x78 };
3519
3520                 static byte [] publicKey = {
3521                         0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00,
3522                         0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53,
3523                         0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3d,
3524                         0xbd, 0x72, 0x08, 0xc6, 0x2b, 0x0e, 0xa8, 0xc1, 0xc0, 0x58, 0x07,
3525                         0x2b, 0x63, 0x5f, 0x7c, 0x9a, 0xbd, 0xcb, 0x22, 0xdb, 0x20, 0xb2,
3526                         0xa9, 0xda, 0xda, 0xef, 0xe8, 0x00, 0x64, 0x2f, 0x5d, 0x8d, 0xeb,
3527                         0x78, 0x02, 0xf7, 0xa5, 0x36, 0x77, 0x28, 0xd7, 0x55, 0x8d, 0x14,
3528                         0x68, 0xdb, 0xeb, 0x24, 0x09, 0xd0, 0x2b, 0x13, 0x1b, 0x92, 0x6e,
3529                         0x2e, 0x59, 0x54, 0x4a, 0xac, 0x18, 0xcf, 0xc9, 0x09, 0x02, 0x3f,
3530                         0x4f, 0xa8, 0x3e, 0x94, 0x00, 0x1f, 0xc2, 0xf1, 0x1a, 0x27, 0x47,
3531                         0x7d, 0x10, 0x84, 0xf5, 0x14, 0xb8, 0x61, 0x62, 0x1a, 0x0c, 0x66,
3532                         0xab, 0xd2, 0x4c, 0x4b, 0x9f, 0xc9, 0x0f, 0x3c, 0xd8, 0x92, 0x0f,
3533                         0xf5, 0xff, 0xce, 0xd7, 0x6e, 0x5c, 0x6f, 0xb1, 0xf5, 0x7d, 0xd3,
3534                         0x56, 0xf9, 0x67, 0x27, 0xa4, 0xa5, 0x48, 0x5b, 0x07, 0x93, 0x44,
3535                         0x00, 0x4a, 0xf8, 0xff, 0xa4, 0xcb };
3536
3537                 static byte [] pk_token = { 0xce, 0x52, 0x76, 0xd8, 0x68, 0x7e, 0Xc6, 0xdc };
3538         }
3539 }