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