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