[sgen] Fix pointer access.
[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                         } catch (MissingMethodException ex) {
2077                                 // Entry point not found in assembly '...'
2078                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2079                                 Assert.IsNull (ex.InnerException, "#3");
2080                                 Assert.IsNotNull (ex.Message, "#4");
2081                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2082                         }
2083                 }
2084
2085                 [Test] // ExecuteAssembly (String, Evidence)
2086                 public void ExecuteAssembly2_NoEntryPoint ()
2087                 {
2088                         Assembly assembly = typeof (AppDomainTest).Assembly;
2089
2090                         try {
2091                                 AppDomain.CurrentDomain.ExecuteAssembly (
2092                                         assembly.Location,
2093                                         (Evidence) null);
2094                                 Assert.Fail ("#1");
2095                         } catch (MissingMethodException ex) {
2096                                 // Entry point not found in assembly '...'
2097                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2098                                 Assert.IsNull (ex.InnerException, "#3");
2099                                 Assert.IsNotNull (ex.Message, "#4");
2100                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2101                         }
2102                 }
2103
2104                 [Test] // ExecuteAssembly (String, Evidence, String [])
2105                 public void ExecuteAssembly3_NoEntryPoint ()
2106                 {
2107                         Assembly assembly = typeof (AppDomainTest).Assembly;
2108
2109                         try {
2110                                 AppDomain.CurrentDomain.ExecuteAssembly (
2111                                         assembly.Location,
2112                                         (Evidence) null,
2113                                         new string [0]);
2114                                 Assert.Fail ("#1");
2115                         } catch (MissingMethodException ex) {
2116                                 // Entry point not found in assembly '...'
2117                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2118                                 Assert.IsNull (ex.InnerException, "#3");
2119                                 Assert.IsNotNull (ex.Message, "#4");
2120                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2121                         }
2122                 }
2123
2124                 [Test] // ExecuteAssembly (String, Evidence, String [], Byte [], AssemblyHashAlgorithm)
2125                 [Category ("NotWorking")] // Not implemented
2126                 public void ExecuteAssembly4_NoEntryPoint ()
2127                 {
2128                         Assembly assembly = typeof (AppDomainTest).Assembly;
2129
2130                         try {
2131                                 AppDomain.CurrentDomain.ExecuteAssembly (
2132                                         assembly.Location,
2133                                         (Evidence) null,
2134                                         new string [0],
2135                                         (byte []) null,
2136                                         AssemblyHashAlgorithm.SHA1);
2137                                 Assert.Fail ("#1");
2138                         } catch (MissingMethodException ex) {
2139                                 // Entry point not found in assembly '...'
2140                                 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2141                                 Assert.IsNull (ex.InnerException, "#3");
2142                                 Assert.IsNotNull (ex.Message, "#4");
2143                                 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2144                         }
2145                 }
2146
2147                 [Test] // bug #79720
2148                 [Category ("NotWorking")]
2149                 public void Load_Loaded_Ignore ()
2150                 {
2151                         int assemblyStartCount = AppDomain.CurrentDomain.GetAssemblies ().Length;
2152
2153                         // PART A
2154
2155                         string assemblyFile = Path.Combine (tempDir, "bug79720A.dll");
2156                         AssemblyName aname = new AssemblyName ();
2157                         aname.Name = "bug79720A";
2158                         aname.Version = new Version (2, 4);
2159
2160                         GenerateAssembly (aname, assemblyFile);
2161
2162                         Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A1");
2163
2164                         aname = new AssemblyName ();
2165                         aname.Name = "bug79720A";
2166                         try {
2167                                 AppDomain.CurrentDomain.Load (aname);
2168                                 Assert.Fail ("#A2");
2169                         } catch (FileNotFoundException) {
2170                         }
2171
2172                         aname = new AssemblyName ();
2173                         aname.Name = "bug79720A";
2174                         aname.Version = new Version (0, 0, 0, 0);
2175                         try {
2176                                 AppDomain.CurrentDomain.Load (aname);
2177                                 Assert.Fail ("#A3");
2178                         } catch (FileNotFoundException) {
2179                         }
2180
2181                         aname = new AssemblyName ();
2182                         aname.Name = "bug79720A";
2183                         aname.Version = new Version (2, 4);
2184                         try {
2185                                 AppDomain.CurrentDomain.Load (aname);
2186                                 Assert.Fail ("#A4");
2187                         } catch (FileNotFoundException) {
2188                         }
2189
2190                         Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A5");
2191
2192                         Assembly.LoadFrom (assemblyFile);
2193
2194                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A6");
2195
2196                         aname = new AssemblyName ();
2197                         aname.Name = "bug79720A";
2198                         try {
2199                                 AppDomain.CurrentDomain.Load (aname);
2200                                 Assert.Fail ("#A7");
2201                         } catch (FileNotFoundException) {
2202                         }
2203
2204                         aname = new AssemblyName ();
2205                         aname.Name = "bug79720A";
2206                         aname.Version = new Version (0, 0, 0, 0);
2207                         try {
2208                                 AppDomain.CurrentDomain.Load (aname);
2209                                 Assert.Fail ("#A8");
2210                         } catch (FileNotFoundException) {
2211                         }
2212
2213                         aname = new AssemblyName ();
2214                         aname.Name = "bug79720A";
2215                         aname.Version = new Version (2, 4);
2216                         try {
2217                                 AppDomain.CurrentDomain.Load (aname);
2218                                 Assert.Fail ("#A9");
2219                         } catch (FileNotFoundException) {
2220                         }
2221
2222                         aname = new AssemblyName ();
2223                         aname.Name = "bug79720A";
2224                         aname.Version = new Version (2, 4);
2225                         aname.CultureInfo = CultureInfo.InvariantCulture;
2226                         try {
2227                                 AppDomain.CurrentDomain.Load (aname);
2228                                 Assert.Fail ("#A10");
2229                         } catch (FileNotFoundException) {
2230                         }
2231
2232                         aname = new AssemblyName ();
2233                         aname.Name = "bug79720A";
2234                         aname.Version = new Version (2, 4, 0, 0);
2235                         aname.CultureInfo = CultureInfo.InvariantCulture;
2236                         try {
2237                                 AppDomain.CurrentDomain.Load (aname);
2238                                 Assert.Fail ("#A11");
2239                         } catch (FileNotFoundException) {
2240                         }
2241
2242                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A12");
2243
2244                         // PART B
2245
2246                         assemblyFile = Path.Combine (tempDir, "bug79720B.dll");
2247                         aname = new AssemblyName ();
2248                         aname.Name = "bug79720B";
2249                         aname.Version = new Version (2, 4, 1);
2250                         aname.CultureInfo = new CultureInfo ("nl-BE");
2251
2252                         GenerateAssembly (aname, assemblyFile);
2253
2254                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B1");
2255
2256                         aname = new AssemblyName ();
2257                         aname.Name = "bug79720B";
2258                         try {
2259                                 AppDomain.CurrentDomain.Load (aname);
2260                                 Assert.Fail ("#B2");
2261                         } catch (FileNotFoundException) {
2262                         }
2263
2264                         aname = new AssemblyName ();
2265                         aname.Name = "bug79720B";
2266                         aname.Version = new Version (0, 0, 0, 0);
2267                         try {
2268                                 AppDomain.CurrentDomain.Load (aname);
2269                                 Assert.Fail ("#B3");
2270                         } catch (FileNotFoundException) {
2271                         }
2272
2273                         aname = new AssemblyName ();
2274                         aname.Name = "bug79720B";
2275                         aname.Version = new Version (2, 4, 1);
2276                         try {
2277                                 AppDomain.CurrentDomain.Load (aname);
2278                                 Assert.Fail ("#B4");
2279                         } catch (FileNotFoundException) {
2280                         }
2281
2282                         aname = new AssemblyName ();
2283                         aname.Name = "bug79720B";
2284                         aname.Version = new Version (2, 4, 1);
2285                         aname.CultureInfo = new CultureInfo ("nl-BE");
2286                         try {
2287                                 AppDomain.CurrentDomain.Load (aname);
2288                                 Assert.Fail ("#B5");
2289                         } catch (FileNotFoundException) {
2290                         }
2291
2292                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B6");
2293
2294                         Assembly.LoadFrom (assemblyFile);
2295
2296                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B7");
2297
2298                         aname = new AssemblyName ();
2299                         aname.Name = "bug79720B";
2300                         try {
2301                                 AppDomain.CurrentDomain.Load (aname);
2302                                 Assert.Fail ("#B8");
2303                         } catch (FileNotFoundException) {
2304                         }
2305
2306                         aname = new AssemblyName ();
2307                         aname.Name = "bug79720B";
2308                         aname.Version = new Version (0, 0, 0, 0);
2309                         try {
2310                                 AppDomain.CurrentDomain.Load (aname);
2311                                 Assert.Fail ("#B9");
2312                         } catch (FileNotFoundException) {
2313                         }
2314
2315                         aname = new AssemblyName ();
2316                         aname.Name = "bug79720B";
2317                         aname.Version = new Version (2, 4, 1);
2318                         try {
2319                                 AppDomain.CurrentDomain.Load (aname);
2320                                 Assert.Fail ("#B10");
2321                         } catch (FileNotFoundException) {
2322                         }
2323
2324                         aname = new AssemblyName ();
2325                         aname.Name = "bug79720B";
2326                         aname.Version = new Version (2, 4, 1);
2327                         aname.CultureInfo = new CultureInfo ("nl-BE");
2328                         try {
2329                                 AppDomain.CurrentDomain.Load (aname);
2330                                 Assert.Fail ("#B11");
2331                         } catch (FileNotFoundException) {
2332                         }
2333
2334                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B12");
2335
2336                         // PART C
2337
2338                         assemblyFile = Path.Combine (tempDir, "bug79720C.dll");
2339                         aname = new AssemblyName ();
2340                         aname.Name = "bug79720C";
2341                         aname.CultureInfo = new CultureInfo ("nl-BE");
2342                         aname.Version = new Version (2, 4);
2343                         aname.KeyPair = new StrongNameKeyPair (keyPair);
2344
2345                         GenerateAssembly (aname, assemblyFile);
2346
2347                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C1");
2348
2349                         aname = new AssemblyName ();
2350                         aname.Name = "bug79720C";
2351                         try {
2352                                 AppDomain.CurrentDomain.Load (aname);
2353                                 Assert.Fail ("#C2");
2354                         } catch (FileNotFoundException) {
2355                         }
2356
2357                         aname = new AssemblyName ();
2358                         aname.Name = "bug79720C";
2359                         aname.Version = new Version (0, 0, 0, 0);
2360                         try {
2361                                 AppDomain.CurrentDomain.Load (aname);
2362                                 Assert.Fail ("#C3");
2363                         } catch (FileNotFoundException) {
2364                         }
2365
2366                         aname = new AssemblyName ();
2367                         aname.Name = "bug79720C";
2368                         aname.Version = new Version (2, 4, 1);
2369                         try {
2370                                 AppDomain.CurrentDomain.Load (aname);
2371                                 Assert.Fail ("#C4");
2372                         } catch (FileNotFoundException) {
2373                         }
2374
2375                         aname = new AssemblyName ();
2376                         aname.Name = "bug79720C";
2377                         aname.Version = new Version (2, 4, 1);
2378                         aname.CultureInfo = new CultureInfo ("nl-BE");
2379                         try {
2380                                 AppDomain.CurrentDomain.Load (aname);
2381                                 Assert.Fail ("#C5");
2382                         } catch (FileNotFoundException) {
2383                         }
2384
2385                         aname = new AssemblyName ();
2386                         aname.Name = "bug79720C";
2387                         aname.Version = new Version (2, 4, 1);
2388                         aname.CultureInfo = new CultureInfo ("nl-BE");
2389                         aname.SetPublicKey (publicKey);
2390                         try {
2391                                 AppDomain.CurrentDomain.Load (aname);
2392                                 Assert.Fail ("#C6");
2393                         } catch (FileNotFoundException) {
2394                         }
2395
2396                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C7");
2397
2398                         Assembly.LoadFrom (assemblyFile);
2399
2400                         Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C8");
2401
2402                         aname = new AssemblyName ();
2403                         aname.Name = "bug79720C";
2404                         try {
2405                                 AppDomain.CurrentDomain.Load (aname);
2406                                 Assert.Fail ("#C9");
2407                         } catch (FileNotFoundException) {
2408                         }
2409
2410                         aname = new AssemblyName ();
2411                         aname.Name = "bug79720C";
2412                         aname.Version = new Version (0, 0, 0, 0);
2413                         try {
2414                                 AppDomain.CurrentDomain.Load (aname);
2415                                 Assert.Fail ("#C10");
2416                         } catch (FileNotFoundException) {
2417                         }
2418
2419                         aname = new AssemblyName ();
2420                         aname.Name = "bug79720C";
2421                         aname.Version = new Version (2, 4);
2422                         try {
2423                                 AppDomain.CurrentDomain.Load (aname);
2424                                 Assert.Fail ("#C11");
2425                         } catch (FileNotFoundException) {
2426                         }
2427
2428                         aname = new AssemblyName ();
2429                         aname.Name = "bug79720C";
2430                         aname.Version = new Version (2, 4);
2431                         aname.CultureInfo = new CultureInfo ("nl-BE");
2432                         try {
2433                                 AppDomain.CurrentDomain.Load (aname);
2434                                 Assert.Fail ("#C12");
2435                         } catch (FileNotFoundException) {
2436                         }
2437
2438                         aname = new AssemblyName ();
2439                         aname.Name = "bug79720C";
2440                         aname.Version = new Version (2, 4);
2441                         aname.CultureInfo = new CultureInfo ("nl-BE");
2442                         aname.SetPublicKey (publicKey);
2443                         try {
2444                                 AppDomain.CurrentDomain.Load (aname);
2445                                 Assert.Fail ("#C13");
2446                         } catch (FileNotFoundException) {
2447                         }
2448
2449                         Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C14");
2450                 }
2451
2452                 [Test]
2453                 [Category ("NotWorking")]
2454                 public void Load_Loaded_Multiple ()
2455                 {
2456                         string cultureDir = Path.Combine (tempDir, "nl-BE");
2457                         if (!Directory.Exists (cultureDir))
2458                                 Directory.CreateDirectory (cultureDir);
2459
2460                         AppDomain ad = CreateTestDomain (tempDir, true);
2461                         try {
2462                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
2463
2464                                 int assemblyCount = cdt.AssemblyCount;
2465
2466                                 // PART A
2467
2468                                 AssemblyName aname = new AssemblyName ();
2469                                 aname.Name = "multipleA";
2470                                 aname.Version = new Version (1, 2, 3, 4);
2471                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "multipleA.dll"));
2472
2473                                 Assert.AreEqual (assemblyCount + 1, cdt.AssemblyCount, "#A1");
2474
2475                                 aname = new AssemblyName ();
2476                                 aname.Name = "multipleA";
2477                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A2");
2478
2479                                 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A3");
2480
2481                                 aname = new AssemblyName ();
2482                                 aname.Name = "multipleA";
2483                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A4");
2484
2485                                 aname = new AssemblyName ();
2486                                 aname.Name = "multipleA";
2487                                 aname.CultureInfo = CultureInfo.InvariantCulture;
2488                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A5");
2489
2490                                 aname = new AssemblyName ();
2491                                 aname.Name = "multipleA";
2492                                 aname.CultureInfo = CultureInfo.InvariantCulture;
2493                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A6");
2494
2495                                 aname = new AssemblyName ();
2496                                 aname.Name = "multipleA";
2497                                 aname.CultureInfo = CultureInfo.InvariantCulture;
2498                                 aname.Version = new Version (1, 2, 3, 4);
2499                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A7");
2500
2501                                 aname = new AssemblyName ();
2502                                 aname.Name = "multipleA";
2503                                 aname.CultureInfo = CultureInfo.InvariantCulture;
2504                                 aname.Version = new Version (1, 2, 3, 4);
2505                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A8");
2506
2507                                 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A9");
2508
2509                                 // PART B
2510
2511                                 aname = new AssemblyName ();
2512                                 aname.Name = "multipleB";
2513                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2514                                 aname.Version = new Version (2, 4, 1, 0);
2515                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleB.dll"));
2516
2517                                 Assert.AreEqual (assemblyCount + 3, cdt.AssemblyCount, "#B1");
2518
2519                                 aname = new AssemblyName ();
2520                                 aname.Name = "multipleB";
2521                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B2");
2522
2523                                 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B3");
2524
2525                                 aname = new AssemblyName ();
2526                                 aname.Name = "multipleB";
2527                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B4");
2528
2529                                 aname = new AssemblyName ();
2530                                 aname.Name = "multipleB";
2531                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2532                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B5");
2533
2534                                 aname = new AssemblyName ();
2535                                 aname.Name = "multipleB";
2536                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2537                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B6");
2538
2539                                 aname = new AssemblyName ();
2540                                 aname.Name = "multipleB";
2541                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2542                                 aname.Version = new Version (2, 4, 1, 0);
2543                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B7");
2544
2545                                 aname = new AssemblyName ();
2546                                 aname.Name = "multipleB";
2547                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2548                                 aname.Version = new Version (2, 4, 1, 0);
2549                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B8");
2550
2551                                 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B9");
2552
2553                                 // PART C
2554
2555                                 aname = new AssemblyName ();
2556                                 aname.Name = "multipleC";
2557                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2558                                 aname.Version = new Version (2, 4, 0, 0);
2559                                 aname.KeyPair = new StrongNameKeyPair (keyPair);
2560                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleC.dll"));
2561
2562                                 Assert.AreEqual (assemblyCount + 5, cdt.AssemblyCount, "#C1");
2563
2564                                 aname = new AssemblyName ();
2565                                 aname.Name = "multipleC";
2566                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2567                                 aname.Version = new Version (2, 4, 0, 0);
2568                                 aname.SetPublicKey (publicKey);
2569                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C2");
2570
2571                                 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C3");
2572
2573                                 aname = new AssemblyName ();
2574                                 aname.Name = "multipleC";
2575                                 aname.CultureInfo = new CultureInfo ("nl-BE");
2576                                 aname.Version = new Version (2, 4, 0, 0);
2577                                 aname.SetPublicKey (publicKey);
2578                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C4");
2579
2580                                 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C5");
2581                         } finally {
2582                                 AppDomain.Unload (ad);
2583                         }
2584                 }
2585
2586                 [Test] // bug #79522
2587                 [Category ("NotWorking")]
2588                 public void Load_Manifest_Mismatch ()
2589                 {
2590                         string assemblyFile = Path.Combine (tempDir, "bug79522A.dll");
2591                         AssemblyName aname = new AssemblyName ();
2592                         aname.Name = "bug79522A";
2593                         aname.Version = new Version (2, 4);
2594
2595                         GenerateAssembly (aname, assemblyFile);
2596
2597                         aname = new AssemblyName ();
2598                         aname.CodeBase = assemblyFile;
2599                         aname.Name = "whateveryouwant";
2600                         aname.Version = new Version (1, 1);
2601
2602                         // despite the fact that no assembly with the specified name
2603                         // exists, the assembly pointed to by the CodeBase of the
2604                         // AssemblyName will be loaded
2605                         //
2606                         // however the display name of the loaded assembly does not
2607                         // match the display name of the AssemblyName, and as a result
2608                         // a FileLoadException is thrown
2609                         try {
2610                                 AppDomain.CurrentDomain.Load (aname);
2611                                 Assert.Fail ("#A1");
2612                         } catch (FileLoadException) {
2613                         }
2614
2615                         // if we set CodeBase to some garbage, then we'll get a
2616                         // FileNotFoundException instead
2617                         aname.CodeBase = "whatever";
2618                         try {
2619                                 AppDomain.CurrentDomain.Load (aname);
2620                                 Assert.Fail ("#A2");
2621                         } catch (FileNotFoundException) {
2622                         }
2623
2624                         aname = new AssemblyName ();
2625                         aname.Name = "bug79522A";
2626                         aname.CodeBase = assemblyFile;
2627 #if NET_2_0
2628                         AppDomain.CurrentDomain.Load (aname);
2629 #else
2630                         try {
2631                                 AppDomain.CurrentDomain.Load (aname);
2632                                 Assert.Fail ("#A3");
2633                         } catch (FileLoadException) {
2634                         }
2635 #endif
2636
2637                         aname = new AssemblyName ();
2638                         aname.Name = "bug79522A";
2639                         aname.CodeBase = assemblyFile;
2640                         aname.Version = new Version (2, 5);
2641 #if NET_2_0
2642                         // the version number is not considered when comparing the manifest
2643                         // of the assembly found using codebase
2644                         AppDomain.CurrentDomain.Load (aname);
2645 #else
2646                         try {
2647                                 AppDomain.CurrentDomain.Load (aname);
2648                                 Assert.Fail ("#A4");
2649                         } catch (FileLoadException) {
2650                         }
2651 #endif
2652
2653                         aname = new AssemblyName ();
2654                         aname.Name = "bug79522A";
2655                         aname.CodeBase = assemblyFile;
2656                         aname.Version = new Version (2, 4, 1);
2657 #if NET_2_0
2658                         // the version number is not considered when comparing the manifest
2659                         // of the assembly found using codebase
2660                         AppDomain.CurrentDomain.Load (aname);
2661 #else
2662                         try {
2663                                 AppDomain.CurrentDomain.Load (aname);
2664                                 Assert.Fail ("#A5");
2665                         } catch (FileLoadException) {
2666                         }
2667 #endif
2668
2669                         // if version is set, then culture must also be set
2670                         aname = new AssemblyName ();
2671                         aname.Name = "bug79522A";
2672                         aname.CodeBase = assemblyFile;
2673                         aname.Version = new Version (2, 4);
2674 #if NET_2_0
2675                         AppDomain.CurrentDomain.Load (aname);
2676 #else
2677                         try {
2678                                 AppDomain.CurrentDomain.Load (aname);
2679                                 Assert.Fail ("#A6");
2680                         } catch (FileLoadException) {
2681                         }
2682 #endif
2683
2684                         // version number does not need to be set
2685                         aname = new AssemblyName ();
2686                         aname.Name = "bug79522A";
2687                         aname.CodeBase = assemblyFile;
2688                         aname.CultureInfo = CultureInfo.InvariantCulture;
2689                         AppDomain.CurrentDomain.Load (aname);
2690
2691                         // if set, the version number must match exactly
2692                         aname = new AssemblyName ();
2693                         aname.Name = "bug79522A";
2694                         aname.CodeBase = assemblyFile;
2695                         aname.CultureInfo = CultureInfo.InvariantCulture;
2696                         aname.Version = new Version (2, 4);
2697                         AppDomain.CurrentDomain.Load (aname);
2698
2699                         // if both culture and version are set, then the version diff
2700                         // is ignored
2701                         aname = new AssemblyName ();
2702                         aname.Name = "bug79522A";
2703                         aname.CodeBase = assemblyFile;
2704                         aname.CultureInfo = CultureInfo.InvariantCulture;
2705                         aname.Version = new Version (2, 5);
2706                         AppDomain.CurrentDomain.Load (aname);
2707
2708                         // loaded assembly is not signed
2709                         aname = new AssemblyName ();
2710                         aname.Name = "bug79522A";
2711                         aname.CodeBase = assemblyFile;
2712                         aname.CultureInfo = CultureInfo.InvariantCulture;
2713                         aname.Version = new Version (2, 4);
2714                         aname.SetPublicKey (publicKey);
2715                         try {
2716                                 AppDomain.CurrentDomain.Load (aname);
2717                                 Assert.Fail ("#A7");
2718                         } catch (FileLoadException) {
2719                         }
2720
2721                         // if set, the culture must match
2722                         aname = new AssemblyName ();
2723                         aname.Name = "bug79522A";
2724                         aname.CodeBase = assemblyFile;
2725                         aname.Version = new Version (2, 4);
2726                         aname.CultureInfo = new CultureInfo ("en-US");
2727                         try {
2728                                 AppDomain.CurrentDomain.Load (aname);
2729                                 Assert.Fail ("#A8");
2730                         } catch (FileLoadException) {
2731                         }
2732
2733                         // PART B
2734
2735                         assemblyFile = Path.Combine (tempDir, "bug79522B.dll");
2736                         aname = new AssemblyName ();
2737                         aname.Name = "bug79522B";
2738                         aname.CultureInfo = new CultureInfo ("nl-BE");
2739                         aname.Version = new Version (2, 4, 1);
2740
2741                         GenerateAssembly (aname, assemblyFile);
2742
2743                         aname = new AssemblyName ();
2744                         aname.CodeBase = assemblyFile;
2745                         aname.Name = "whateveryouwant";
2746                         aname.CultureInfo = new CultureInfo ("nl-BE");
2747                         aname.Version = new Version (1, 1);
2748
2749                         // despite the fact that no assembly with the specified name
2750                         // exists, the assembly pointed to by the CodeBase of the
2751                         // AssemblyName will be loaded
2752                         //
2753                         // however the display name of the loaded assembly does not
2754                         // match the display name of the AssemblyName, and as a result
2755                         // a FileLoadException is thrown
2756                         try {
2757                                 AppDomain.CurrentDomain.Load (aname);
2758                                 Assert.Fail ("#B1");
2759                         } catch (FileLoadException) {
2760                         }
2761
2762                         // if we set CodeBase to some garbage, then we'll get a
2763                         // FileNotFoundException instead
2764                         aname.CodeBase = "whatever";
2765                         try {
2766                                 AppDomain.CurrentDomain.Load (aname);
2767                                 Assert.Fail ("#B2");
2768                         } catch (FileNotFoundException) {
2769                         }
2770
2771                         aname = new AssemblyName ();
2772                         aname.Name = "bug79522B";
2773                         aname.CodeBase = assemblyFile;
2774 #if NET_2_0
2775                         // the version number is not considered when comparing the manifest
2776                         // of the assembly found using codebase
2777                         AppDomain.CurrentDomain.Load (aname);
2778 #else
2779                         try {
2780                                 AppDomain.CurrentDomain.Load (aname);
2781                                 Assert.Fail ("#B3");
2782                         } catch (FileLoadException) {
2783                         }
2784 #endif
2785
2786                         aname = new AssemblyName ();
2787                         aname.Name = "bug79522B";
2788                         aname.CodeBase = assemblyFile;
2789                         aname.Version = new Version (5, 5);
2790 #if NET_2_0
2791                         // the version number is not considered when comparing the manifest
2792                         // of the assembly found using codebase
2793                         AppDomain.CurrentDomain.Load (aname);
2794 #else
2795                         try {
2796                                 AppDomain.CurrentDomain.Load (aname);
2797                                 Assert.Fail ("#B3");
2798                         } catch (FileLoadException) {
2799                         }
2800 #endif
2801
2802                         aname = new AssemblyName ();
2803                         aname.Name = "bug79522B";
2804                         aname.CodeBase = assemblyFile;
2805                         aname.Version = new Version (2, 4, 1);
2806 #if NET_2_0
2807                         AppDomain.CurrentDomain.Load (aname);
2808 #else
2809                         // when the loaded assembly has a specific culture, then that
2810                         // culture must be set if you set the Version on the aname
2811                         try {
2812                                 AppDomain.CurrentDomain.Load (aname);
2813                                 Assert.Fail ("#B4");
2814                         } catch (FileLoadException) {
2815                         }
2816 #endif
2817
2818                         // version does not need to be set
2819                         aname = new AssemblyName ();
2820                         aname.Name = "bug79522B";
2821                         aname.CodeBase = assemblyFile;
2822                         aname.CultureInfo = new CultureInfo ("nl-BE");
2823                         AppDomain.CurrentDomain.Load (aname);
2824
2825                         // if both culture and version are set, then the version diff
2826                         // is ignored
2827                         aname = new AssemblyName ();
2828                         aname.Name = "bug79522B";
2829                         aname.CodeBase = assemblyFile;
2830                         aname.CultureInfo = new CultureInfo ("nl-BE");
2831                         aname.Version = new Version (6, 5);
2832                         AppDomain.CurrentDomain.Load (aname);
2833
2834                         // loaded assembly is not signed
2835                         aname = new AssemblyName ();
2836                         aname.Name = "bug79522B";
2837                         aname.CodeBase = assemblyFile;
2838                         aname.CultureInfo = new CultureInfo ("nl-BE");
2839                         aname.SetPublicKey (publicKey);
2840                         try {
2841                                 AppDomain.CurrentDomain.Load (aname);
2842                                 Assert.Fail ("#B5");
2843                         } catch (FileLoadException) {
2844                         }
2845
2846                         // if set, the culture must match
2847                         aname = new AssemblyName ();
2848                         aname.Name = "bug79522B";
2849                         aname.CodeBase = assemblyFile;
2850                         aname.Version = new Version (2, 4, 1);
2851                         aname.CultureInfo = new CultureInfo ("en-US");
2852                         try {
2853                                 AppDomain.CurrentDomain.Load (aname);
2854                                 Assert.Fail ("#B6");
2855                         } catch (FileLoadException) {
2856                         }
2857
2858                         // PART C
2859
2860                         assemblyFile = Path.Combine (tempDir, "bug79522C.dll");
2861                         aname = new AssemblyName ();
2862                         aname.Name = "bug79522C";
2863                         aname.CultureInfo = new CultureInfo ("nl-BE");
2864                         aname.Version = new Version (2, 4);
2865                         aname.KeyPair = new StrongNameKeyPair (keyPair);
2866
2867                         GenerateAssembly (aname, assemblyFile);
2868
2869                         aname = new AssemblyName ();
2870                         aname.CodeBase = assemblyFile;
2871                         aname.Name = "whateveryouwant";
2872                         aname.CultureInfo = new CultureInfo ("nl-BE");
2873                         aname.Version = new Version (1, 1);
2874                         aname.SetPublicKey (publicKey);
2875
2876                         // despite the fact that no assembly with the specified name
2877                         // exists, the assembly pointed to by the CodeBase of the
2878                         // AssemblyName will be loaded
2879                         //
2880                         // however the display name of the loaded assembly does not
2881                         // match the display name of the AssemblyName, and as a result
2882                         // a FileLoadException is thrown
2883                         try {
2884                                 AppDomain.CurrentDomain.Load (aname);
2885                                 Assert.Fail ("#C1");
2886                         } catch (FileLoadException) {
2887                         }
2888
2889                         // if we set CodeBase to some garbage, then we'll get a
2890                         // FileNotFoundException instead
2891                         aname.CodeBase = "whatever";
2892                         try {
2893                                 AppDomain.CurrentDomain.Load (aname);
2894                                 Assert.Fail ("#C2");
2895                         } catch (FileNotFoundException) {
2896                         }
2897
2898                         aname = new AssemblyName ();
2899                         aname.Name = "bug79522C";
2900                         aname.CodeBase = assemblyFile;
2901 #if NET_2_0
2902                         AppDomain.CurrentDomain.Load (aname);
2903 #else
2904                         try {
2905                                 AppDomain.CurrentDomain.Load (aname);
2906                                 Assert.Fail ("#C3");
2907                         } catch (FileLoadException) {
2908                         }
2909 #endif
2910
2911                         aname = new AssemblyName ();
2912                         aname.Name = "bug79522C";
2913                         aname.CodeBase = assemblyFile;
2914                         aname.Version = new Version (5, 5);
2915                         try {
2916                                 AppDomain.CurrentDomain.Load (aname);
2917                                 Assert.Fail ("#C3");
2918                         } catch (FileLoadException) {
2919                         }
2920
2921                         aname = new AssemblyName ();
2922                         aname.Name = "bug79522C";
2923                         aname.CodeBase = assemblyFile;
2924                         aname.Version = new Version (2, 4);
2925 #if NET_2_0
2926                         AppDomain.CurrentDomain.Load (aname);
2927 #else
2928                         // when the loaded assembly has a specific culture/publickey,
2929                         // then that culture/publickey must be set if you set the
2930                         // Version on the aname
2931                         try {
2932                                 AppDomain.CurrentDomain.Load (aname);
2933                                 Assert.Fail ("#C4");
2934                         } catch (FileLoadException) {
2935                         }
2936 #endif
2937
2938                         aname = new AssemblyName ();
2939                         aname.Name = "bug79522C";
2940                         aname.CodeBase = assemblyFile;
2941                         aname.CultureInfo = new CultureInfo ("nl-BE");
2942                         aname.Version = new Version (2, 4);
2943 #if NET_2_0
2944                         AppDomain.CurrentDomain.Load (aname);
2945 #else
2946                         // if loaded assembly is signed, then the public key must be set
2947                         try {
2948                                 AppDomain.CurrentDomain.Load (aname);
2949                                 Assert.Fail ("#C5");
2950                         } catch (FileLoadException) {
2951                         }
2952 #endif
2953
2954                         aname = new AssemblyName ();
2955                         aname.Name = "bug79522C";
2956                         aname.CodeBase = assemblyFile;
2957                         aname.CultureInfo = new CultureInfo ("nl-BE");
2958                         aname.SetPublicKey (publicKey);
2959 #if NET_2_0
2960                         AppDomain.CurrentDomain.Load (aname);
2961 #else
2962                         // if public key is set, then version must be set
2963                         try {
2964                                 AppDomain.CurrentDomain.Load (aname);
2965                                 Assert.Fail ("#C6");
2966                         } catch (FileLoadException) {
2967                         }
2968 #endif
2969
2970                         aname = new AssemblyName ();
2971                         aname.Name = "bug79522C";
2972                         aname.CodeBase = assemblyFile;
2973                         aname.CultureInfo = new CultureInfo ("nl-BE");
2974 #if NET_2_0
2975                         AppDomain.CurrentDomain.Load (aname);
2976 #else
2977                         try {
2978                                 AppDomain.CurrentDomain.Load (aname);
2979                                 Assert.Fail ("#C7");
2980                         } catch (FileLoadException) {
2981                         }
2982 #endif
2983
2984                         // if culture and version are set, then the version must match
2985                         aname = new AssemblyName ();
2986                         aname.Name = "bug79522C";
2987                         aname.CodeBase = assemblyFile;
2988                         aname.CultureInfo = new CultureInfo ("nl-BE");
2989                         aname.SetPublicKey (publicKey);
2990                         aname.Version = new Version (5, 6);
2991                         try {
2992                                 AppDomain.CurrentDomain.Load (aname);
2993                                 Assert.Fail ("#C8");
2994                         } catch (FileLoadException) {
2995                         }
2996
2997                         // publickey must match
2998                         aname = new AssemblyName ();
2999                         aname.Name = "bug79522C";
3000                         aname.CodeBase = assemblyFile;
3001                         aname.CultureInfo = new CultureInfo ("nl-BE");
3002                         aname.Version = new Version (2, 4);
3003                         aname.SetPublicKey (publicKey2);
3004                         try {
3005                                 AppDomain.CurrentDomain.Load (aname);
3006                                 Assert.Fail ("#C9");
3007                         } catch (SecurityException) {
3008                                 // Invalid assembly public key
3009                         }
3010
3011                         aname = new AssemblyName ();
3012                         aname.Name = "bug79522C";
3013                         aname.CodeBase = assemblyFile;
3014                         aname.SetPublicKey (publicKey);
3015                         aname.CultureInfo = new CultureInfo ("nl-BE");
3016                         aname.Version = new Version (2, 4);
3017                         AppDomain.CurrentDomain.Load (aname);
3018                 }
3019
3020                 [Test] // bug #79715
3021                 public void Load_PartialVersion ()
3022                 {
3023                         AppDomain ad = CreateTestDomain (tempDir, true);
3024                         try {
3025                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
3026
3027                                 AssemblyName aname = new AssemblyName ();
3028                                 aname.Name = "bug79715";
3029                                 aname.Version = new Version (1, 2, 3, 4);
3030                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "bug79715.dll"));
3031
3032                                 aname = new AssemblyName ();
3033                                 aname.Name = "bug79715";
3034                                 aname.Version = new Version (1, 2);
3035                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A1");
3036                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#A2");
3037
3038                                 aname = new AssemblyName ();
3039                                 aname.Name = "bug79715";
3040                                 aname.Version = new Version (1, 2, 3);
3041                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B1");
3042                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#B2");
3043
3044                                 aname = new AssemblyName ();
3045                                 aname.Name = "bug79715";
3046                                 aname.Version = new Version (1, 2, 3, 4);
3047                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C1");
3048                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#C2");
3049                         } finally {
3050                                 AppDomain.Unload (ad);
3051                         }
3052                 }
3053                 
3054                 [Test]
3055                 [ExpectedException (typeof (ArgumentException))]
3056                 public void Load_EmptyString ()
3057                 {
3058                         AppDomain.CurrentDomain.Load ("");
3059                 }
3060
3061                 [Test]
3062                 public void SetAppDomainPolicy ()
3063                 {
3064                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
3065                         ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
3066                         // not much to see
3067                 }
3068
3069                 [Test]
3070                 [ExpectedException (typeof (ArgumentNullException))]
3071                 public void SetAppDomainPolicy_Null ()
3072                 {
3073                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
3074                         ad.SetAppDomainPolicy (null);
3075                 }
3076
3077                 [Test]
3078                 [ExpectedException (typeof (PolicyException))]
3079                 public void SetAppDomainPolicy_Dual ()
3080                 {
3081                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Dual");
3082                         PolicyLevel pl = PolicyLevel.CreateAppDomainLevel ();
3083                         PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
3084                         pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
3085                         ad.SetAppDomainPolicy (pl);
3086
3087                         // only one time!
3088                         pl = PolicyLevel.CreateAppDomainLevel ();
3089                         ps = new PermissionSet (PermissionState.None);
3090                         pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
3091                         ad.SetAppDomainPolicy (pl);
3092                 }
3093
3094                 [Test]
3095                 [ExpectedException (typeof (AppDomainUnloadedException))]
3096                 public void SetAppDomainPolicy_Unloaded ()
3097                 {
3098                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Unloaded");
3099                         AppDomain.Unload (ad);
3100                         ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
3101                 }
3102
3103                 [Test]
3104                 [ExpectedException (typeof (ArgumentNullException))]
3105                 public void GetData_Null ()
3106                 {
3107                         AppDomain.CurrentDomain.GetData (null);
3108                 }
3109
3110                 [Test]
3111                 public void SetData ()
3112                 {
3113                         AppDomain.CurrentDomain.SetData ("data", "data");
3114                         Assert.AreEqual ("data", AppDomain.CurrentDomain.GetData ("data"), "GetData");
3115                         AppDomain.CurrentDomain.SetData ("data", null);
3116                         Assert.IsNull (AppDomain.CurrentDomain.GetData ("data"), "GetData-Null");
3117                 }
3118
3119                 [Test]
3120                 [ExpectedException (typeof (ArgumentNullException))]
3121                 public void SetData_Null ()
3122                 {
3123                         AppDomain.CurrentDomain.SetData (null, "data");
3124                 }
3125
3126 #if NET_2_0
3127                 [Test]
3128                 public void ApplyPolicy ()
3129                 {
3130                         ad = AppDomain.CreateDomain ("ApplyPolicy");
3131                         string fullname = Assembly.GetExecutingAssembly ().FullName;
3132                         string result = ad.ApplyPolicy (fullname);
3133                         Assert.AreEqual (fullname, result, "ApplyPolicy");
3134                         // doesn't even requires an assembly name
3135                         Assert.AreEqual ("123", ad.ApplyPolicy ("123"), "Invalid FullName");
3136                 }
3137
3138                 [Test]
3139                 [ExpectedException (typeof (ArgumentException))]
3140                 public void ApplyPolicy_Empty ()
3141                 {
3142                         ad = AppDomain.CreateDomain ("ApplyPolicy_Empty");
3143                         ad.ApplyPolicy (String.Empty);
3144                 }
3145
3146                 [Test]
3147                 [ExpectedException (typeof (ArgumentNullException))]
3148                 public void ApplyPolicy_Null ()
3149                 {
3150                         ad = AppDomain.CreateDomain ("ApplyPolicy_Null");
3151                         ad.ApplyPolicy (null);
3152                 }
3153
3154                 [Test]
3155                 public void DomainManager ()
3156                 {
3157                         Assert.IsNull (AppDomain.CurrentDomain.DomainManager, "CurrentDomain.DomainManager");
3158                         ad = AppDomain.CreateDomain ("DomainManager");
3159                         Assert.IsNull (ad.DomainManager, "ad.DomainManager");
3160                 }
3161
3162                 [Test]
3163                 public void IsDefaultAppDomain ()
3164                 {
3165                         ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
3166                         Assert.IsFalse (ad.IsDefaultAppDomain (), "IsDefaultAppDomain");
3167                         // we have no public way to get the default appdomain
3168                 }
3169
3170                 static bool resolve_called;
3171
3172                 [Test]
3173                 public void AssemblyResolveParseError ()
3174                 {
3175                         AppDomain currentDomain = AppDomain.CurrentDomain;
3176                         ResolveEventHandler d = ParseErrorResolve;
3177                         currentDomain.AssemblyResolve += d;
3178                         try {
3179                                 resolve_called = false;
3180                                 var a = Assembly.Load ("MyDynamicType, 1.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
3181                                 Assert.Fail ();
3182                         } catch (FileNotFoundException) {
3183                                 Assert.IsTrue (resolve_called);
3184                         }
3185                         currentDomain.AssemblyResolve -= d;
3186                 }
3187
3188                 static Assembly ParseErrorResolve (object sender, ResolveEventArgs args)
3189                 {
3190                         resolve_called = true;
3191                         return null;
3192                 }
3193
3194                 [Test]
3195                 public void ReflectionOnlyGetAssemblies ()
3196                 {
3197                         ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
3198                         Assembly [] a = ad.ReflectionOnlyGetAssemblies ();
3199                         Assert.IsNotNull (a, "ReflectionOnlyGetAssemblies");
3200                         Assert.AreEqual (0, a.Length, "Count");                 
3201
3202                         string assemblyFile = Path.Combine (tempDir, "bug499013.dll");
3203                         AssemblyName aname = new AssemblyName ();
3204                         aname.Name = "bug499013";
3205                         aname.Version = new Version (2, 4);
3206
3207                         GenerateAssembly (aname, assemblyFile);
3208
3209                         Assembly.ReflectionOnlyLoadFrom (assemblyFile);
3210                         foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies ())
3211                                 Assert.IsTrue (assembly.GetName ().Name != "bug499013");
3212                 }
3213
3214                 [Test]
3215                 public void ReflectionOnlyAssemblyResolve ()
3216                 {
3217                         AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
3218                         Assembly asm = Assembly.ReflectionOnlyLoad(Assembly.LoadWithPartialName("System").FullName);
3219                         asm.GetTypes();
3220                 }
3221
3222         [Test]
3223                 public void ResourceResolve ()
3224                 {
3225                         bool called = false;
3226
3227                         ResolveEventHandler del = delegate (object sender, ResolveEventArgs args) { 
3228                                         called = true; 
3229                                         return null;
3230                         };
3231                         AppDomain.CurrentDomain.ResourceResolve += del;
3232                         Stream st = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("NOT_EXISTING");
3233                         Assert.IsTrue (called);
3234                         AppDomain.CurrentDomain.ResourceResolve -= del;
3235                 }                       
3236
3237                 private static Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
3238                 {
3239                         return Assembly.ReflectionOnlyLoad(args.Name);
3240                 }
3241 #endif
3242
3243                 public class StuffToPick
3244                 {
3245                         public StuffToPick () {}
3246                         public void Method () {}
3247                         public int Property { get; set; }
3248                         public event Action Event;
3249                         public int Field;
3250                         public void GenericMethod<T> () {}
3251                 }
3252
3253                 public class StuffToPick<T>
3254                 {
3255                         public StuffToPick () {}
3256                         public void Method () {}
3257                         public int Property { get; set; }
3258                         public event Action Event;
3259                         public int Field;
3260                         public void GenericMethod<T> () {}
3261                 }
3262
3263                 static void TestSerialization (CrossDomainTester tester, object o)
3264                 {
3265                         Assert.AreSame (o, tester.ReturnArg0 (o), "serializing_type_" + o.GetType ());
3266                 }
3267
3268                 [Test] //BXC #12611
3269                 public void ReflectionObjectsAreSerializableTest ()
3270                 {
3271                         ad = CreateTestDomain (tempDir, true);
3272                         CrossDomainTester tester = CreateCrossDomainTester (ad);
3273
3274                         TestSerialization (tester, typeof (StuffToPick));
3275                         TestSerialization (tester, typeof (StuffToPick).GetConstructor(new Type [0]));
3276                         TestSerialization (tester, typeof (StuffToPick).GetMethod ("Method"));
3277                         TestSerialization (tester, typeof (StuffToPick).GetProperty ("Property"));
3278                         TestSerialization (tester, typeof (StuffToPick).GetEvent ("Event"));
3279                         TestSerialization (tester, typeof (StuffToPick).GetField ("Field"));
3280                         TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod"));
3281
3282                         TestSerialization (tester, typeof (StuffToPick<>));
3283                         TestSerialization (tester, typeof (StuffToPick<>).GetConstructor(new Type [0]));
3284                         TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("Method"));
3285                         TestSerialization (tester, typeof (StuffToPick<>).GetProperty ("Property"));
3286                         TestSerialization (tester, typeof (StuffToPick<>).GetEvent ("Event"));
3287                         TestSerialization (tester, typeof (StuffToPick<>).GetField ("Field"));
3288                         TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("GenericMethod"));
3289
3290                         TestSerialization (tester, typeof (StuffToPick<int>));
3291                         TestSerialization (tester, typeof (StuffToPick<int>).GetConstructor(new Type [0]));
3292                         TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("Method"));
3293                         TestSerialization (tester, typeof (StuffToPick<int>).GetProperty ("Property"));
3294                         TestSerialization (tester, typeof (StuffToPick<int>).GetEvent ("Event"));
3295                         TestSerialization (tester, typeof (StuffToPick<int>).GetField ("Field"));
3296                         TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("GenericMethod"));
3297                 }
3298
3299                 [Test] //BXC #12611
3300                 [Category ("NotWorking")] // Serialization can't handle generic methods
3301                 public void GenericReflectionObjectsAreSerializableTest ()
3302                 {
3303                         ad = CreateTestDomain (tempDir, true);
3304                         CrossDomainTester tester = CreateCrossDomainTester (ad);
3305
3306                         TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)));
3307                         TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)));
3308                         TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)));
3309                 }
3310
3311                 [Test]
3312                 public void ShadowCopyTypeGetTypeMissingAssemblyTest ()
3313                 {
3314                         ad = CreateShadowCopyAppDomain (tempDir, true);
3315                         CrossDomainTester tester = CreateCrossDomainTester (ad);
3316                         tester.AssertLoadMissingAssemblyType ();
3317                 }
3318
3319                 private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
3320                 {
3321                         AppDomainSetup setup = new AppDomainSetup ();
3322                         setup.ApplicationBase = baseDirectory;
3323                         setup.ApplicationName = "testdomain";
3324                         return CreateTestDomain (setup, assemblyResolver);
3325                 }
3326
3327                 private static AppDomain CreateShadowCopyAppDomain (string baseDirectory, bool assemblyResolver)
3328                 {
3329                         AppDomainSetup setup = new AppDomainSetup ();
3330                         setup.ApplicationBase = baseDirectory;
3331                         setup.ApplicationName = "testdomain";
3332                         setup.ShadowCopyFiles = "true";
3333                         return CreateTestDomain (setup, assemblyResolver);
3334                 }
3335
3336                 private static AppDomain CreateTestDomain (AppDomainSetup setup, bool assemblyResolver)
3337                 {
3338                         AppDomain ad = AppDomain.CreateDomain ("testdomain",
3339                                 AppDomain.CurrentDomain.Evidence, setup);
3340
3341                         if (assemblyResolver) {
3342                                 Assembly ea = Assembly.GetExecutingAssembly ();
3343                                 ad.CreateInstanceFrom (ea.CodeBase,
3344                                         typeof (AssemblyResolveHandler).FullName,
3345                                         false,
3346                                         BindingFlags.Public | BindingFlags.Instance,
3347                                         null,
3348                                         new object [] { ea.Location, ea.FullName },
3349                                         CultureInfo.InvariantCulture,
3350                                         null,
3351                                         null);
3352                         }
3353
3354                         return ad;
3355                 }
3356
3357
3358                 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
3359                 {
3360                         Type testerType = typeof (CrossDomainTester);
3361                         return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
3362                                 testerType.Assembly.FullName, testerType.FullName, false,
3363                                 BindingFlags.Public | BindingFlags.Instance, null, new object [0],
3364                                 CultureInfo.InvariantCulture, new object [0], null);
3365                 }
3366
3367                 private static void GenerateAssembly (AssemblyName aname, string path)
3368                 {
3369                         AppDomain ad = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory,
3370                                 false);
3371                         try {
3372                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
3373                                 cdt.GenerateAssembly (aname, path);
3374                         } finally {
3375                                 AppDomain.Unload (ad);
3376                         }
3377                 }
3378
3379                 private bool RunningOnUnix {
3380                         get {
3381                                 // check for Unix platforms - see FAQ for more details
3382                                 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
3383                                 int platform = (int) Environment.OSVersion.Platform;
3384                                 return ((platform == 4) || (platform == 128) || (platform == 6));
3385                         }
3386                 }
3387
3388                 private class CrossDomainTester : MarshalByRefObject
3389                 {
3390                         public void GenerateAssembly (AssemblyName aname, string path)
3391                         {
3392                                 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
3393                                         aname, AssemblyBuilderAccess.Save, Path.GetDirectoryName (path));
3394                                 ab.Save (Path.GetFileName (path));
3395                         }
3396
3397                         public int AssemblyCount {
3398                                 get {
3399                                         return AppDomain.CurrentDomain.GetAssemblies ().Length;
3400                                 }
3401                         }
3402
3403                         public string GetApplicationBase ()
3404                         {
3405                                 return AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
3406                         }
3407
3408                         public string GetConfigurationFile ()
3409                         {
3410                                 return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
3411                         }
3412
3413                         public void Load (AssemblyName assemblyRef)
3414                         {
3415                                 AppDomain.CurrentDomain.Load (assemblyRef);
3416                         }
3417
3418                         public void LoadFrom (string assemblyFile)
3419                         {
3420                                 Assembly.LoadFrom (assemblyFile);
3421                         }
3422
3423                         public bool AssertLoad (AssemblyName assemblyRef)
3424                         {
3425                                 try {
3426                                         AppDomain.CurrentDomain.Load (assemblyRef);
3427                                         return true;
3428                                 } catch {
3429                                         return false;
3430                                 }
3431                         }
3432
3433                         public bool AssertLoad (string assemblyString)
3434                         {
3435                                 try {
3436                                         AppDomain.CurrentDomain.Load (assemblyString);
3437                                         return true;
3438                                 } catch {
3439                                         return false;
3440                                 }
3441                         }
3442
3443                         public void AssertLoadMissingAssemblyType ()
3444                         {
3445                                 Assert.IsNull (Type.GetType ("A.B.C, MissingAssembly"));
3446                         }
3447
3448                         public bool AssertFileLoadException (AssemblyName assemblyRef)
3449                         {
3450                                 try {
3451                                         AppDomain.CurrentDomain.Load (assemblyRef);
3452                                         return false;
3453                                 } catch (FileLoadException) {
3454                                         return true;
3455                                 }
3456                         }
3457
3458                         public object ReturnArg0 (object obj)
3459                         {
3460                                 return obj;
3461                         }
3462                 }
3463
3464                 [Serializable ()]
3465                 private class AssemblyResolveHandler
3466                 {
3467                         public AssemblyResolveHandler (string assemblyFile, string assemblyName)
3468                         {
3469                                 _assemblyFile = assemblyFile;
3470                                 _assemblyName = assemblyName;
3471
3472                                 AppDomain.CurrentDomain.AssemblyResolve +=
3473                                         new ResolveEventHandler (ResolveAssembly);
3474                         }
3475
3476                         private Assembly ResolveAssembly (object sender, ResolveEventArgs args)
3477                         {
3478                                 if (args.Name == _assemblyName)
3479                                         return Assembly.LoadFrom (_assemblyFile);
3480
3481                                 return null;
3482                         }
3483
3484                         private readonly string _assemblyFile;
3485                         private readonly string _assemblyName;
3486                 }
3487
3488                 static byte [] keyPair = {
3489                         0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
3490                         0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3D, 0xBD,
3491                         0x72, 0x08, 0xC6, 0x2B, 0x0E, 0xA8, 0xC1, 0xC0, 0x58, 0x07, 0x2B,
3492                         0x63, 0x5F, 0x7C, 0x9A, 0xBD, 0xCB, 0x22, 0xDB, 0x20, 0xB2, 0xA9,
3493                         0xDA, 0xDA, 0xEF, 0xE8, 0x00, 0x64, 0x2F, 0x5D, 0x8D, 0xEB, 0x78,
3494                         0x02, 0xF7, 0xA5, 0x36, 0x77, 0x28, 0xD7, 0x55, 0x8D, 0x14, 0x68,
3495                         0xDB, 0xEB, 0x24, 0x09, 0xD0, 0x2B, 0x13, 0x1B, 0x92, 0x6E, 0x2E,
3496                         0x59, 0x54, 0x4A, 0xAC, 0x18, 0xCF, 0xC9, 0x09, 0x02, 0x3F, 0x4F,
3497                         0xA8, 0x3E, 0x94, 0x00, 0x1F, 0xC2, 0xF1, 0x1A, 0x27, 0x47, 0x7D,
3498                         0x10, 0x84, 0xF5, 0x14, 0xB8, 0x61, 0x62, 0x1A, 0x0C, 0x66, 0xAB,
3499                         0xD2, 0x4C, 0x4B, 0x9F, 0xC9, 0x0F, 0x3C, 0xD8, 0x92, 0x0F, 0xF5,
3500                         0xFF, 0xCE, 0xD7, 0x6E, 0x5C, 0x6F, 0xB1, 0xF5, 0x7D, 0xD3, 0x56,
3501                         0xF9, 0x67, 0x27, 0xA4, 0xA5, 0x48, 0x5B, 0x07, 0x93, 0x44, 0x00,
3502                         0x4A, 0xF8, 0xFF, 0xA4, 0xCB, 0x73, 0xC0, 0x6A, 0x62, 0xB4, 0xB7,
3503                         0xC8, 0x92, 0x58, 0x87, 0xCD, 0x07, 0x0C, 0x7D, 0x6C, 0xC1, 0x4A,
3504                         0xFC, 0x82, 0x57, 0x0E, 0x43, 0x85, 0x09, 0x75, 0x98, 0x51, 0xBB,
3505                         0x35, 0xF5, 0x64, 0x83, 0xC7, 0x79, 0x89, 0x5C, 0x55, 0x36, 0x66,
3506                         0xAB, 0x27, 0xA4, 0xD9, 0xD4, 0x7E, 0x6B, 0x67, 0x64, 0xC1, 0x54,
3507                         0x4E, 0x37, 0xF1, 0x4E, 0xCA, 0xB3, 0xE5, 0x63, 0x91, 0x57, 0x12,
3508                         0x14, 0xA6, 0xEA, 0x8F, 0x8F, 0x2B, 0xFE, 0xF3, 0xE9, 0x16, 0x08,
3509                         0x2B, 0x86, 0xBC, 0x26, 0x0D, 0xD0, 0xC6, 0xC4, 0x1A, 0x72, 0x43,
3510                         0x76, 0xDC, 0xFF, 0x28, 0x52, 0xA1, 0xDE, 0x8D, 0xFA, 0xD5, 0x1F,
3511                         0x0B, 0xB5, 0x4F, 0xAF, 0x06, 0x79, 0x11, 0xEE, 0xA8, 0xEC, 0xD3,
3512                         0x74, 0x55, 0xA2, 0x80, 0xFC, 0xF8, 0xD9, 0x50, 0x69, 0x48, 0x01,
3513                         0xC2, 0x5A, 0x04, 0x56, 0xB4, 0x3E, 0x24, 0x32, 0x20, 0xB5, 0x2C,
3514                         0xDE, 0xBB, 0xBD, 0x13, 0xFD, 0x13, 0xF7, 0x03, 0x3E, 0xE3, 0x37,
3515                         0x84, 0x74, 0xE7, 0xD0, 0x5E, 0x9E, 0xB6, 0x26, 0xAE, 0x6E, 0xB0,
3516                         0x55, 0x6A, 0x52, 0x63, 0x6F, 0x5A, 0x9D, 0xF2, 0x67, 0xD6, 0x61,
3517                         0x4F, 0x7A, 0x45, 0xEE, 0x5C, 0x3D, 0x2B, 0x7C, 0xB2, 0x40, 0x79,
3518                         0x54, 0x84, 0xD1, 0xBE, 0x61, 0x3E, 0x5E, 0xD6, 0x18, 0x8E, 0x14,
3519                         0x98, 0xFC, 0x35, 0xBF, 0x5F, 0x1A, 0x20, 0x2E, 0x1A, 0xD8, 0xFF,
3520                         0xC4, 0x6B, 0xC0, 0xC9, 0x7D, 0x06, 0xEF, 0x09, 0xF9, 0xF3, 0x69,
3521                         0xFC, 0xBC, 0xA2, 0xE6, 0x80, 0x22, 0xB9, 0x79, 0x7E, 0xEF, 0x57,
3522                         0x9F, 0x49, 0xE1, 0xBC, 0x0D, 0xB6, 0xA1, 0xFE, 0x8D, 0xBC, 0xBB,
3523                         0xA3, 0x05, 0x02, 0x6B, 0x04, 0x45, 0xF7, 0x5D, 0xEE, 0x43, 0x06,
3524                         0xD6, 0x9C, 0x94, 0x48, 0x1A, 0x0B, 0x9C, 0xBC, 0xB4, 0x4E, 0x93,
3525                         0x60, 0x87, 0xCD, 0x58, 0xD6, 0x9A, 0x39, 0xA6, 0xC0, 0x7F, 0x8E,
3526                         0xFF, 0x25, 0xC1, 0xD7, 0x2C, 0xF6, 0xF4, 0x6F, 0x24, 0x52, 0x0B,
3527                         0x39, 0x42, 0x1B, 0x0D, 0x04, 0xC1, 0x93, 0x2A, 0x19, 0x1C, 0xF0,
3528                         0xB1, 0x9B, 0xC1, 0x24, 0x6D, 0x1B, 0x0B, 0xDA, 0x1C, 0x8B, 0x72,
3529                         0x48, 0xF0, 0x3E, 0x52, 0xBF, 0x0A, 0x84, 0x3A, 0x9B, 0xC8, 0x6D,
3530                         0x13, 0x1E, 0x72, 0xF4, 0x46, 0x93, 0x88, 0x1A, 0x5F, 0x4C, 0x3C,
3531                         0xE5, 0x9D, 0x6E, 0xBB, 0x4E, 0xDD, 0x5D, 0x1F, 0x11, 0x40, 0xF4,
3532                         0xD7, 0xAF, 0xB3, 0xAB, 0x9A, 0x99, 0x15, 0xF0, 0xDC, 0xAA, 0xFF,
3533                         0x9F, 0x2D, 0x9E, 0x56, 0x4F, 0x35, 0x5B, 0xBA, 0x06, 0x99, 0xEA,
3534                         0xC6, 0xB4, 0x48, 0x51, 0x17, 0x1E, 0xD1, 0x95, 0x84, 0x81, 0x18,
3535                         0xC0, 0xF1, 0x71, 0xDE, 0x44, 0x42, 0x02, 0x06, 0xAC, 0x0E, 0xA8,
3536                         0xE2, 0xF3, 0x1F, 0x96, 0x1F, 0xBE, 0xB6, 0x1F, 0xB5, 0x3E, 0xF6,
3537                         0x81, 0x05, 0x20, 0xFA, 0x2E, 0x40, 0x2E, 0x4D, 0xA0, 0x0E, 0xDA,
3538                         0x42, 0x9C, 0x05, 0xAA, 0x9E, 0xAF, 0x5C, 0xF7, 0x3A, 0x3F, 0xBB,
3539                         0x91, 0x73, 0x45, 0x27, 0xA8, 0xA2, 0x07, 0x4A, 0xEF, 0x59, 0x1E,
3540                         0x97, 0x9D, 0xE0, 0x30, 0x5A, 0x83, 0xCE, 0x1E, 0x57, 0x32, 0x89,
3541                         0x43, 0x41, 0x28, 0x7D, 0x14, 0x8D, 0x8B, 0x41, 0x1A, 0x56, 0x76,
3542                         0x43, 0xDB, 0x64, 0x86, 0x41, 0x64, 0x8D, 0x4C, 0x91, 0x83, 0x4E,
3543                         0xF5, 0x6C };
3544
3545                 static byte [] publicKey2 = {
3546                         0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
3547                         0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x7F, 0x7C,
3548                         0xEA, 0x4A, 0x28, 0x33, 0xD8, 0x3C, 0x86, 0x90, 0x86, 0x91, 0x11,
3549                         0xBB, 0x30, 0x0D, 0x3D, 0x69, 0x04, 0x4C, 0x48, 0xF5, 0x4F, 0xE7,
3550                         0x64, 0xA5, 0x82, 0x72, 0x5A, 0x92, 0xC4, 0x3D, 0xC5, 0x90, 0x93,
3551                         0x41, 0xC9, 0x1D, 0x34, 0x16, 0x72, 0x2B, 0x85, 0xC1, 0xF3, 0x99,
3552                         0x62, 0x07, 0x32, 0x98, 0xB7, 0xE4, 0xFA, 0x75, 0x81, 0x8D, 0x08,
3553                         0xB9, 0xFD, 0xDB, 0x00, 0x25, 0x30, 0xC4, 0x89, 0x13, 0xB6, 0x43,
3554                         0xE8, 0xCC, 0xBE, 0x03, 0x2E, 0x1A, 0x6A, 0x4D, 0x36, 0xB1, 0xEB,
3555                         0x49, 0x26, 0x6C, 0xAB, 0xC4, 0x29, 0xD7, 0x8F, 0x25, 0x11, 0xA4,
3556                         0x7C, 0x81, 0x61, 0x97, 0xCB, 0x44, 0x2D, 0x80, 0x49, 0x93, 0x48,
3557                         0xA7, 0xC9, 0xAB, 0xDB, 0xCF, 0xA3, 0x34, 0xCB, 0x6B, 0x86, 0xE0,
3558                         0x4D, 0x27, 0xFC, 0xA7, 0x4F, 0x36, 0xCA, 0x13, 0x42, 0xD3, 0x83,
3559                         0xC4, 0x06, 0x6E, 0x12, 0xE0, 0xA1, 0x3D, 0x9F, 0xA9, 0xEC, 0xD1,
3560                         0xC6, 0x08, 0x1B, 0x3D, 0xF5, 0xDB, 0x4C, 0xD4, 0xF0, 0x2C, 0xAA,
3561                         0xFC, 0xBA, 0x18, 0x6F, 0x48, 0x7E, 0xB9, 0x47, 0x68, 0x2E, 0xF6,
3562                         0x1E, 0x67, 0x1C, 0x7E, 0x0A, 0xCE, 0x10, 0x07, 0xC0, 0x0C, 0xAD,
3563                         0x5E, 0xC1, 0x53, 0x70, 0xD5, 0xE7, 0x25, 0xCA, 0x37, 0x5E, 0x49,
3564                         0x59, 0xD0, 0x67, 0x2A, 0xBE, 0x92, 0x36, 0x86, 0x8A, 0xBF, 0x3E,
3565                         0x17, 0x04, 0xFB, 0x1F, 0x46, 0xC8, 0x10, 0x5C, 0x93, 0x02, 0x43,
3566                         0x14, 0x96, 0x6A, 0xD9, 0x87, 0x17, 0x62, 0x7D, 0x3A, 0x45, 0xBE,
3567                         0x35, 0xDE, 0x75, 0x0B, 0x2A, 0xCE, 0x7D, 0xF3, 0x19, 0x85, 0x4B,
3568                         0x0D, 0x6F, 0x8D, 0x15, 0xA3, 0x60, 0x61, 0x28, 0x55, 0x46, 0xCE,
3569                         0x78, 0x31, 0x04, 0x18, 0x3C, 0x56, 0x4A, 0x3F, 0xA4, 0xC9, 0xB1,
3570                         0x41, 0xED, 0x22, 0x80, 0xA1, 0xB3, 0xE2, 0xC7, 0x1B, 0x62, 0x85,
3571                         0xE4, 0x81, 0x39, 0xCB, 0x1F, 0x95, 0xCC, 0x61, 0x61, 0xDF, 0xDE,
3572                         0xF3, 0x05, 0x68, 0xB9, 0x7D, 0x4F, 0xFF, 0xF3, 0xC0, 0x0A, 0x25,
3573                         0x62, 0xD9, 0x8A, 0x8A, 0x9E, 0x99, 0x0B, 0xFB, 0x85, 0x27, 0x8D,
3574                         0xF6, 0xD4, 0xE1, 0xB9, 0xDE, 0xB4, 0x16, 0xBD, 0xDF, 0x6A, 0x25,
3575                         0x9C, 0xAC, 0xCD, 0x91, 0xF7, 0xCB, 0xC1, 0x81, 0x22, 0x0D, 0xF4,
3576                         0x7E, 0xEC, 0x0C, 0x84, 0x13, 0x5A, 0x74, 0x59, 0x3F, 0x3E, 0x61,
3577                         0x00, 0xD6, 0xB5, 0x4A, 0xA1, 0x04, 0xB5, 0xA7, 0x1C, 0x29, 0xD0,
3578                         0xE1, 0x11, 0x19, 0xD7, 0x80, 0x5C, 0xEE, 0x08, 0x15, 0xEB, 0xC9,
3579                         0xA8, 0x98, 0xF5, 0xA0, 0xF0, 0x92, 0x2A, 0xB0, 0xD3, 0xC7, 0x8C,
3580                         0x8D, 0xBB, 0x88, 0x96, 0x4F, 0x18, 0xF0, 0x8A, 0xF9, 0x31, 0x9E,
3581                         0x44, 0x94, 0x75, 0x6F, 0x78, 0x04, 0x10, 0xEC, 0xF3, 0xB0, 0xCE,
3582                         0xA0, 0xBE, 0x7B, 0x25, 0xE1, 0xF7, 0x8A, 0xA8, 0xD4, 0x63, 0xC2,
3583                         0x65, 0x47, 0xCC, 0x5C, 0xED, 0x7D, 0x8B, 0x07, 0x4D, 0x76, 0x29,
3584                         0x53, 0xAC, 0x27, 0x8F, 0x5D, 0x78, 0x56, 0xFA, 0x99, 0x45, 0xA2,
3585                         0xCC, 0x65, 0xC4, 0x54, 0x13, 0x9F, 0x38, 0x41, 0x7A, 0x61, 0x0E,
3586                         0x0D, 0x34, 0xBC, 0x11, 0xAF, 0xE2, 0xF1, 0x8B, 0xFA, 0x2B, 0x54,
3587                         0x6C, 0xA3, 0x6C, 0x09, 0x1F, 0x0B, 0x43, 0x9B, 0x07, 0x95, 0x83,
3588                         0x3F, 0x97, 0x99, 0x89, 0xF5, 0x51, 0x41, 0xF6, 0x8E, 0x5D, 0xEF,
3589                         0x6D, 0x24, 0x71, 0x41, 0x7A, 0xAF, 0xBE, 0x81, 0x71, 0xAB, 0x76,
3590                         0x2F, 0x1A, 0x5A, 0xBA, 0xF3, 0xA6, 0x65, 0x7A, 0x80, 0x50, 0xCE,
3591                         0x23, 0xC3, 0xC7, 0x53, 0xB0, 0x7C, 0x97, 0x77, 0x27, 0x70, 0x98,
3592                         0xAE, 0xB5, 0x24, 0x66, 0xE1, 0x60, 0x39, 0x41, 0xDA, 0x54, 0x01,
3593                         0x64, 0xFB, 0x10, 0x33, 0xCE, 0x8B, 0xBE, 0x27, 0xD4, 0x21, 0x57,
3594                         0xCC, 0x0F, 0x1A, 0xC1, 0x3D, 0xF3, 0xCC, 0x39, 0xF0, 0x2F, 0xAE,
3595                         0xF1, 0xC0, 0xCD, 0x3B, 0x23, 0x87, 0x49, 0x7E, 0x40, 0x32, 0x6A,
3596                         0xD3, 0x96, 0x4A, 0xE5, 0x5E, 0x6E, 0x26, 0xFD, 0x8A, 0xCF, 0x7E,
3597                         0xFC, 0x37, 0xDE, 0x39, 0x0C, 0x53, 0x81, 0x75, 0x08, 0xAF, 0x6B,
3598                         0x39, 0x6C, 0xFB, 0xC9, 0x79, 0xC0, 0x9B, 0x5F, 0x34, 0x86, 0xB2,
3599                         0xDE, 0xC4, 0x19, 0x84, 0x5F, 0x0E, 0xED, 0x9B, 0xB8, 0xD3, 0x17,
3600                         0xDA, 0x78 };
3601
3602                 static byte [] publicKey = {
3603                         0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00,
3604                         0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53,
3605                         0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3d,
3606                         0xbd, 0x72, 0x08, 0xc6, 0x2b, 0x0e, 0xa8, 0xc1, 0xc0, 0x58, 0x07,
3607                         0x2b, 0x63, 0x5f, 0x7c, 0x9a, 0xbd, 0xcb, 0x22, 0xdb, 0x20, 0xb2,
3608                         0xa9, 0xda, 0xda, 0xef, 0xe8, 0x00, 0x64, 0x2f, 0x5d, 0x8d, 0xeb,
3609                         0x78, 0x02, 0xf7, 0xa5, 0x36, 0x77, 0x28, 0xd7, 0x55, 0x8d, 0x14,
3610                         0x68, 0xdb, 0xeb, 0x24, 0x09, 0xd0, 0x2b, 0x13, 0x1b, 0x92, 0x6e,
3611                         0x2e, 0x59, 0x54, 0x4a, 0xac, 0x18, 0xcf, 0xc9, 0x09, 0x02, 0x3f,
3612                         0x4f, 0xa8, 0x3e, 0x94, 0x00, 0x1f, 0xc2, 0xf1, 0x1a, 0x27, 0x47,
3613                         0x7d, 0x10, 0x84, 0xf5, 0x14, 0xb8, 0x61, 0x62, 0x1a, 0x0c, 0x66,
3614                         0xab, 0xd2, 0x4c, 0x4b, 0x9f, 0xc9, 0x0f, 0x3c, 0xd8, 0x92, 0x0f,
3615                         0xf5, 0xff, 0xce, 0xd7, 0x6e, 0x5c, 0x6f, 0xb1, 0xf5, 0x7d, 0xd3,
3616                         0x56, 0xf9, 0x67, 0x27, 0xa4, 0xa5, 0x48, 0x5b, 0x07, 0x93, 0x44,
3617                         0x00, 0x4a, 0xf8, 0xff, 0xa4, 0xcb };
3618
3619                 static byte [] pk_token = { 0xce, 0x52, 0x76, 0xd8, 0x68, 0x7e, 0Xc6, 0xdc };
3620         }
3621 }
3622
3623 #endif