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