In corlib/System.Runtime.InteropServices:
[mono.git] / mcs / class / corlib / Test / System / AppDomainTest.cs
1 //
2 // AppDomainTest.cs - NUnit Test Cases for AppDomain
3 //
4 // Author:
5 //      Sebastien Pouliot (sebastien@ximian.com)
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using NUnit.Framework;
30 using System;
31 using System.Collections;
32 using System.Globalization;
33 using System.IO;
34 using System.Reflection;
35 using System.Reflection.Emit;
36 using System.Security;
37 using System.Security.Permissions;
38 using System.Security.Policy;
39 using System.Security.Principal;
40
41 namespace MonoTests.System
42 {
43         [TestFixture]
44         public class AppDomainTest
45         {
46                 private AppDomain ad;
47                 private ArrayList files = new ArrayList ();
48                 private string tempDir = Path.Combine (Path.GetTempPath (), "MonoTests.System.AppDomainTest");
49
50                 [SetUp]
51                 public void SetUp ()
52                 {
53                         if (!Directory.Exists (tempDir)) {
54                                 Directory.CreateDirectory (tempDir);
55                         }
56                 }
57
58                 [TearDown]
59                 public void TearDown ()
60                 {
61                         if (ad != null) {
62                                 try {
63                                         AppDomain.Unload (ad);
64                                         ad = null;
65                                 } catch { } // do not affect unit test results in TearDown
66                         }
67                         foreach (string fname in files) {
68                                 File.Delete (fname);
69                         }
70                         files.Clear ();
71                 }
72
73                 [Test] // bug #80934
74                 public void ConfigurationFile_Relative ()
75                 {
76                         // Note:
77                         // We use Environment.GetCommandLineArgs () to get the location of
78                         // the entry assembly in the default domain (since the default domain
79                         // is not exposed by any API)
80                         // 
81                         // MS returns a lower-case path in Environment.GetCommandLineArgs ()
82                         // and hence we need to perform a case-insensitive comparison
83                         // if the Assert involves that path
84
85                         string configFile = "test.config";
86                         string appBase = null;
87                         string expectedConfigFile = null;
88                         string expectedAppBase = null;
89
90                         // do not set ApplicationBase
91                         appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
92                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
93                                 appBase : appBase + Path.DirectorySeparatorChar;
94                         expectedConfigFile = Path.Combine (appBase, configFile);
95                         AppDomainSetup setup = new AppDomainSetup();
96                         setup.ConfigurationFile = configFile;
97                         ad = CreateTestDomain (setup, true);
98                         CrossDomainTester cdt = CreateCrossDomainTester (ad);
99                         if (RunningOnUnix) {
100                                 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
101                                 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
102                         } else {
103                                 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
104                                 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
105                         }
106                         AppDomain.Unload (ad);
107
108                         // set ApplicationBase
109                         appBase = Path.GetTempPath ();
110                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
111                                 appBase : appBase + Path.DirectorySeparatorChar;
112                         expectedConfigFile = Path.Combine (appBase, configFile);
113                         setup = new AppDomainSetup ();
114                         setup.ApplicationBase = appBase;
115                         setup.ConfigurationFile = configFile;
116                         ad = CreateTestDomain (setup, true);
117                         cdt = CreateCrossDomainTester (ad);
118                         Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
119                         Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
120                         AppDomain.Unload (ad);
121                 }
122
123                 [Test] // bug #80934
124                 public void ConfigurationFile_Absolute ()
125                 {
126                         // Note:
127                         // We use Environment.GetCommandLineArgs () to get the location of
128                         // the entry assembly in the default domain (since the default domain
129                         // is not exposed by any API)
130                         // 
131                         // MS returns a lower-case path in Environment.GetCommandLineArgs ()
132                         // and hence on Windows we need to perform a case-insensitive 
133                         // comparison if the Assert involves that path
134
135                         string configFile = Path.Combine (tempDir, "test.config");
136                         string appBase = null;
137                         string expectedAppBase = null;
138
139                         // do not set ApplicationBase
140                         appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
141                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
142                                 appBase : appBase + Path.DirectorySeparatorChar;
143                         AppDomainSetup setup = new AppDomainSetup ();
144                         setup.ConfigurationFile = configFile;
145                         ad = CreateTestDomain (setup, true);
146                         CrossDomainTester cdt = CreateCrossDomainTester (ad);
147                         Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#A1");
148                         if (RunningOnUnix) {
149                                 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
150                         } else {
151                                 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
152                         }
153                         AppDomain.Unload (ad);
154
155                         // set ApplicationBase
156                         appBase = Path.GetTempPath ();
157                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
158                                 appBase : appBase + Path.DirectorySeparatorChar;
159                         setup = new AppDomainSetup ();
160                         setup.ApplicationBase = appBase;
161                         setup.ConfigurationFile = configFile;
162                         ad = CreateTestDomain (setup, true);
163                         cdt = CreateCrossDomainTester (ad);
164                         Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#B1");
165                         Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
166                         AppDomain.Unload (ad);
167                 }
168
169                 [Test] // bug #80934
170                 //[Category ("NotWorking")]
171                 public void ConfigurationFile_Null ()
172                 {
173                         // Note:
174                         // We use Environment.GetCommandLineArgs () to get the location of
175                         // the entry assembly in the default domain (since the default domain
176                         // is not exposed by any API)
177                         // 
178                         // MS returns a lower-case path in Environment.GetCommandLineArgs ()
179                         // and hence we need to perform a case-insensitive comparison
180                         // if the Assert involves that path
181
182                         string appBase = null;
183                         string expectedAppBase = null;
184                         string expectedConfigFile = null;
185
186                         // do not set ApplicationBase
187                         appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
188                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
189                                 appBase : appBase + Path.DirectorySeparatorChar;
190                         expectedConfigFile = Environment.GetCommandLineArgs () [0] + ".config";
191                         AppDomainSetup setup = new AppDomainSetup ();
192                         setup.ConfigurationFile = null;
193                         ad = CreateTestDomain (setup, true);
194                         CrossDomainTester cdt = CreateCrossDomainTester (ad);
195                         if (RunningOnUnix) {
196                                 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
197                                 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
198                         } else {
199                                 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
200                                 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
201                         }
202                         AppDomain.Unload (ad);
203
204                         // set ApplicationBase
205                         appBase = Path.GetTempPath ();
206                         expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
207                                 appBase : appBase + Path.DirectorySeparatorChar;
208                         expectedConfigFile = Path.Combine (appBase, Path.GetFileName (Environment.GetCommandLineArgs () [0]) + ".config");
209                         setup = new AppDomainSetup ();
210                         setup.ApplicationBase = appBase;
211                         setup.ConfigurationFile = null;
212                         ad = CreateTestDomain (setup, true);
213                         cdt = CreateCrossDomainTester (ad);
214                         if (RunningOnUnix) {
215                                 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
216                         } else {
217                                 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#B1");
218                         }
219                         Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
220                         AppDomain.Unload (ad);
221                 }
222
223                 [Test]
224                 public void SetThreadPrincipal ()
225                 {
226                         IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
227                         IPrincipal p = new GenericPrincipal (i, null);
228                         ad = AppDomain.CreateDomain ("SetThreadPrincipal");
229                         ad.SetThreadPrincipal (p);
230                 }
231
232                 [Test]
233                 [ExpectedException (typeof (ArgumentNullException))]
234                 public void SetThreadPrincipalNull ()
235                 {
236                         AppDomain.CurrentDomain.SetThreadPrincipal (null);
237                 }
238
239                 [Test]
240                 [ExpectedException (typeof (PolicyException))]
241                 public void SetThreadPrincipalTwice ()
242                 {
243                         IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
244                         IPrincipal p = new GenericPrincipal (i, null);
245                         ad = AppDomain.CreateDomain ("SetThreadPrincipalTwice");
246                         ad.SetThreadPrincipal (p);
247                         // you only live twice (or so James told me ;-)
248                         ad.SetThreadPrincipal (p);
249                 }
250
251                 [Test]
252                 [ExpectedException (typeof (AppDomainUnloadedException))]
253                 public void SetThreadPrincipalUnloaded ()
254                 {
255                         ad = AppDomain.CreateDomain ("Ximian");
256                         AppDomain.Unload (ad);
257                         IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
258                         IPrincipal p = new GenericPrincipal (i, null);
259                         ad.SetThreadPrincipal (p);
260                 }
261
262                 [Test]
263                 public void SetPrincipalPolicy_NoPrincipal ()
264                 {
265                         AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
266                 }
267
268                 [Test]
269                 public void SetPrincipalPolicy_UnauthenticatedPrincipal ()
270                 {
271                         AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.UnauthenticatedPrincipal);
272                 }
273
274                 [Test]
275                 public void SetPrincipalPolicy_WindowsPrincipal ()
276                 {
277                         AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.WindowsPrincipal);
278                 }
279
280                 [Test]
281                 [ExpectedException (typeof (AppDomainUnloadedException))]
282                 public void SetPrincipalPolicyUnloaded ()
283                 {
284                         ad = AppDomain.CreateDomain ("Ximian");
285                         AppDomain.Unload (ad);
286                         ad.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
287                 }
288
289                 [Test]
290                 public void CreateDomain_String ()
291                 {
292                         ad = AppDomain.CreateDomain ("CreateDomain_String");
293                         Assert.IsNotNull (ad.Evidence, "Evidence");
294                         // Evidence are copied (or referenced?) from default app domain
295                         // we can't get default so we use the current (which should have copied the default)
296                         Assert.AreEqual (AppDomain.CurrentDomain.Evidence.Count, ad.Evidence.Count, "Evidence.Count");
297                 }
298
299                 [Test]
300                 [ExpectedException (typeof (ArgumentNullException))]
301                 public void CreateDomain_String_Null ()
302                 {
303                         ad = AppDomain.CreateDomain (null);
304                 }
305
306                 [Test]
307                 [Category ("NotDotNet")]
308                 public void CreateDomain_StringEvidence ()
309                 {
310                         Evidence e = new Evidence ();
311                         ad = AppDomain.CreateDomain ("CreateDomain_StringEvidence", e);
312                         Assert.IsNotNull (ad.Evidence, "Evidence");
313                         Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
314
315                         e.AddHost (new Zone (SecurityZone.MyComputer));
316                         Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
317                         // evidence isn't copied but referenced
318                 }
319
320                 [Test]
321                 [ExpectedException (typeof (ArgumentNullException))]
322                 public void CreateDomain_StringNullEvidence ()
323                 {
324                         ad = AppDomain.CreateDomain (null, new Evidence ());
325                 }
326
327                 [Test]
328                 public void CreateDomain_StringEvidenceNull ()
329                 {
330                         ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceNull", null);
331                         Assert.IsNotNull (ad.Evidence, "Evidence");
332                         // Evidence are copied (or referenced?) from default app domain
333                         // we can't get default so we use the current (which should have copied the default)
334                         Evidence e = AppDomain.CurrentDomain.Evidence;
335                         Assert.AreEqual (e.Count, ad.Evidence.Count, "Evidence.Count-1");
336                         e.AddHost (new Zone (SecurityZone.MyComputer));
337                         Assert.AreEqual (e.Count - 1, ad.Evidence.Count, "Evidence.Count-2");
338                         // evidence are copied
339                 }
340
341                 [Test]
342                 [Category ("NotDotNet")]
343                 public void CreateDomain_StringEvidenceAppDomainSetup ()
344                 {
345                         Evidence e = new Evidence ();
346                         AppDomainSetup info = new AppDomainSetup ();
347                         info.ApplicationName = "ApplicationName";
348
349                         ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceAppDomainSetup", e, info);
350                         Assert.IsNotNull (ad.Evidence, "Evidence");
351                         Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
352                         Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
353                         Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName);
354
355                         e.AddHost (new Zone (SecurityZone.MyComputer));
356                         Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
357                         // evidence isn't copied but referenced
358                 }
359
360                 [Test]
361                 [ExpectedException (typeof (ArgumentNullException))]
362                 public void CreateDomain_StringNullEvidenceAppDomainSetup ()
363                 {
364                         AppDomainSetup info = new AppDomainSetup ();
365                         ad = AppDomain.CreateDomain (null, new Evidence (), info);
366                 }
367
368                 [Test]
369                 public void CreateDomain_StringEvidenceNullAppDomainSetup ()
370                 {
371                         AppDomainSetup info = new AppDomainSetup ();
372                         info.ApplicationName = "ApplicationName";
373                         ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceNullAppDomainSetup", null, info);
374                         Assert.IsNotNull (ad.Evidence, "Evidence");
375                         // Evidence are copied (or referenced?) from default app domain
376                         // we can't get default so we use the current (which should have copied the default)
377                         Assert.AreEqual (AppDomain.CurrentDomain.Evidence.Count, ad.Evidence.Count, "Evidence.Count");
378                         Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName, "ApplicationName-1");
379                         info.ApplicationName = "Test";
380                         Assert.AreEqual ("Test", info.ApplicationName, "ApplicationName-2");
381                         Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName, "ApplicationName-3");
382                         // copied
383                 }
384
385                 [Test]
386                 [Category ("NotDotNet")]
387                 public void CreateDomain_StringEvidenceAppDomainSetupNull ()
388                 {
389                         Evidence e = new Evidence ();
390                         ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceAppDomainSetupNull", e, null);
391                         Assert.IsNotNull (ad.Evidence, "Evidence");
392                         Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
393                         // SetupInformation is copied from default app domain
394                         Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
395                 }
396
397                 [Test] // bug #79720
398                 [Category ("NotWorking")]
399                 public void Load_Loaded_Ignore ()
400                 {
401                         int assemblyStartCount = AppDomain.CurrentDomain.GetAssemblies ().Length;
402
403                         // PART A
404
405                         string assemblyFile = Path.Combine (tempDir, "bug79720A.dll");
406                         AssemblyName aname = new AssemblyName ();
407                         aname.Name = "bug79720A";
408                         aname.Version = new Version (2, 4);
409
410                         GenerateAssembly (aname, assemblyFile);
411
412                         Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A1");
413
414                         aname = new AssemblyName ();
415                         aname.Name = "bug79720A";
416                         try {
417                                 AppDomain.CurrentDomain.Load (aname);
418                                 Assert.Fail ("#A2");
419                         } catch (FileNotFoundException) {
420                         }
421
422                         aname = new AssemblyName ();
423                         aname.Name = "bug79720A";
424                         aname.Version = new Version (0, 0, 0, 0);
425                         try {
426                                 AppDomain.CurrentDomain.Load (aname);
427                                 Assert.Fail ("#A3");
428                         } catch (FileNotFoundException) {
429                         }
430
431                         aname = new AssemblyName ();
432                         aname.Name = "bug79720A";
433                         aname.Version = new Version (2, 4);
434                         try {
435                                 AppDomain.CurrentDomain.Load (aname);
436                                 Assert.Fail ("#A4");
437                         } catch (FileNotFoundException) {
438                         }
439
440                         Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A5");
441
442                         Assembly.LoadFrom (assemblyFile);
443
444                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A6");
445
446                         aname = new AssemblyName ();
447                         aname.Name = "bug79720A";
448                         try {
449                                 AppDomain.CurrentDomain.Load (aname);
450                                 Assert.Fail ("#A7");
451                         } catch (FileNotFoundException) {
452                         }
453
454                         aname = new AssemblyName ();
455                         aname.Name = "bug79720A";
456                         aname.Version = new Version (0, 0, 0, 0);
457                         try {
458                                 AppDomain.CurrentDomain.Load (aname);
459                                 Assert.Fail ("#A8");
460                         } catch (FileNotFoundException) {
461                         }
462
463                         aname = new AssemblyName ();
464                         aname.Name = "bug79720A";
465                         aname.Version = new Version (2, 4);
466                         try {
467                                 AppDomain.CurrentDomain.Load (aname);
468                                 Assert.Fail ("#A9");
469                         } catch (FileNotFoundException) {
470                         }
471
472                         aname = new AssemblyName ();
473                         aname.Name = "bug79720A";
474                         aname.Version = new Version (2, 4);
475                         aname.CultureInfo = CultureInfo.InvariantCulture;
476                         try {
477                                 AppDomain.CurrentDomain.Load (aname);
478                                 Assert.Fail ("#A10");
479                         } catch (FileNotFoundException) {
480                         }
481
482                         aname = new AssemblyName ();
483                         aname.Name = "bug79720A";
484                         aname.Version = new Version (2, 4, 0, 0);
485                         aname.CultureInfo = CultureInfo.InvariantCulture;
486                         try {
487                                 AppDomain.CurrentDomain.Load (aname);
488                                 Assert.Fail ("#A11");
489                         } catch (FileNotFoundException) {
490                         }
491
492                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A12");
493
494                         // PART B
495
496                         assemblyFile = Path.Combine (tempDir, "bug79720B.dll");
497                         aname = new AssemblyName ();
498                         aname.Name = "bug79720B";
499                         aname.Version = new Version (2, 4, 1);
500                         aname.CultureInfo = new CultureInfo ("nl-BE");
501
502                         GenerateAssembly (aname, assemblyFile);
503
504                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B1");
505
506                         aname = new AssemblyName ();
507                         aname.Name = "bug79720B";
508                         try {
509                                 AppDomain.CurrentDomain.Load (aname);
510                                 Assert.Fail ("#B2");
511                         } catch (FileNotFoundException) {
512                         }
513
514                         aname = new AssemblyName ();
515                         aname.Name = "bug79720B";
516                         aname.Version = new Version (0, 0, 0, 0);
517                         try {
518                                 AppDomain.CurrentDomain.Load (aname);
519                                 Assert.Fail ("#B3");
520                         } catch (FileNotFoundException) {
521                         }
522
523                         aname = new AssemblyName ();
524                         aname.Name = "bug79720B";
525                         aname.Version = new Version (2, 4, 1);
526                         try {
527                                 AppDomain.CurrentDomain.Load (aname);
528                                 Assert.Fail ("#B4");
529                         } catch (FileNotFoundException) {
530                         }
531
532                         aname = new AssemblyName ();
533                         aname.Name = "bug79720B";
534                         aname.Version = new Version (2, 4, 1);
535                         aname.CultureInfo = new CultureInfo ("nl-BE");
536                         try {
537                                 AppDomain.CurrentDomain.Load (aname);
538                                 Assert.Fail ("#B5");
539                         } catch (FileNotFoundException) {
540                         }
541
542                         Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B6");
543
544                         Assembly.LoadFrom (assemblyFile);
545
546                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B7");
547
548                         aname = new AssemblyName ();
549                         aname.Name = "bug79720B";
550                         try {
551                                 AppDomain.CurrentDomain.Load (aname);
552                                 Assert.Fail ("#B8");
553                         } catch (FileNotFoundException) {
554                         }
555
556                         aname = new AssemblyName ();
557                         aname.Name = "bug79720B";
558                         aname.Version = new Version (0, 0, 0, 0);
559                         try {
560                                 AppDomain.CurrentDomain.Load (aname);
561                                 Assert.Fail ("#B9");
562                         } catch (FileNotFoundException) {
563                         }
564
565                         aname = new AssemblyName ();
566                         aname.Name = "bug79720B";
567                         aname.Version = new Version (2, 4, 1);
568                         try {
569                                 AppDomain.CurrentDomain.Load (aname);
570                                 Assert.Fail ("#B10");
571                         } catch (FileNotFoundException) {
572                         }
573
574                         aname = new AssemblyName ();
575                         aname.Name = "bug79720B";
576                         aname.Version = new Version (2, 4, 1);
577                         aname.CultureInfo = new CultureInfo ("nl-BE");
578                         try {
579                                 AppDomain.CurrentDomain.Load (aname);
580                                 Assert.Fail ("#B11");
581                         } catch (FileNotFoundException) {
582                         }
583
584                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B12");
585
586                         // PART C
587
588                         assemblyFile = Path.Combine (tempDir, "bug79720C.dll");
589                         aname = new AssemblyName ();
590                         aname.Name = "bug79720C";
591                         aname.CultureInfo = new CultureInfo ("nl-BE");
592                         aname.Version = new Version (2, 4);
593                         aname.KeyPair = new StrongNameKeyPair (keyPair);
594
595                         GenerateAssembly (aname, assemblyFile);
596
597                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C1");
598
599                         aname = new AssemblyName ();
600                         aname.Name = "bug79720C";
601                         try {
602                                 AppDomain.CurrentDomain.Load (aname);
603                                 Assert.Fail ("#C2");
604                         } catch (FileNotFoundException) {
605                         }
606
607                         aname = new AssemblyName ();
608                         aname.Name = "bug79720C";
609                         aname.Version = new Version (0, 0, 0, 0);
610                         try {
611                                 AppDomain.CurrentDomain.Load (aname);
612                                 Assert.Fail ("#C3");
613                         } catch (FileNotFoundException) {
614                         }
615
616                         aname = new AssemblyName ();
617                         aname.Name = "bug79720C";
618                         aname.Version = new Version (2, 4, 1);
619                         try {
620                                 AppDomain.CurrentDomain.Load (aname);
621                                 Assert.Fail ("#C4");
622                         } catch (FileNotFoundException) {
623                         }
624
625                         aname = new AssemblyName ();
626                         aname.Name = "bug79720C";
627                         aname.Version = new Version (2, 4, 1);
628                         aname.CultureInfo = new CultureInfo ("nl-BE");
629                         try {
630                                 AppDomain.CurrentDomain.Load (aname);
631                                 Assert.Fail ("#C5");
632                         } catch (FileNotFoundException) {
633                         }
634
635                         aname = new AssemblyName ();
636                         aname.Name = "bug79720C";
637                         aname.Version = new Version (2, 4, 1);
638                         aname.CultureInfo = new CultureInfo ("nl-BE");
639                         aname.SetPublicKey (publicKey);
640                         try {
641                                 AppDomain.CurrentDomain.Load (aname);
642                                 Assert.Fail ("#C6");
643                         } catch (FileNotFoundException) {
644                         }
645
646                         Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C7");
647
648                         Assembly.LoadFrom (assemblyFile);
649
650                         Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C8");
651
652                         aname = new AssemblyName ();
653                         aname.Name = "bug79720C";
654                         try {
655                                 AppDomain.CurrentDomain.Load (aname);
656                                 Assert.Fail ("#C9");
657                         } catch (FileNotFoundException) {
658                         }
659
660                         aname = new AssemblyName ();
661                         aname.Name = "bug79720C";
662                         aname.Version = new Version (0, 0, 0, 0);
663                         try {
664                                 AppDomain.CurrentDomain.Load (aname);
665                                 Assert.Fail ("#C10");
666                         } catch (FileNotFoundException) {
667                         }
668
669                         aname = new AssemblyName ();
670                         aname.Name = "bug79720C";
671                         aname.Version = new Version (2, 4);
672                         try {
673                                 AppDomain.CurrentDomain.Load (aname);
674                                 Assert.Fail ("#C11");
675                         } catch (FileNotFoundException) {
676                         }
677
678                         aname = new AssemblyName ();
679                         aname.Name = "bug79720C";
680                         aname.Version = new Version (2, 4);
681                         aname.CultureInfo = new CultureInfo ("nl-BE");
682                         try {
683                                 AppDomain.CurrentDomain.Load (aname);
684                                 Assert.Fail ("#C12");
685                         } catch (FileNotFoundException) {
686                         }
687
688                         aname = new AssemblyName ();
689                         aname.Name = "bug79720C";
690                         aname.Version = new Version (2, 4);
691                         aname.CultureInfo = new CultureInfo ("nl-BE");
692                         aname.SetPublicKey (publicKey);
693                         try {
694                                 AppDomain.CurrentDomain.Load (aname);
695                                 Assert.Fail ("#C13");
696                         } catch (FileNotFoundException) {
697                         }
698
699                         Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C14");
700                 }
701
702                 [Test]
703                 [Category ("NotWorking")]
704                 public void Load_Loaded_Multiple ()
705                 {
706                         string cultureDir = Path.Combine (tempDir, "nl-BE");
707                         if (!Directory.Exists (cultureDir))
708                                 Directory.CreateDirectory (cultureDir);
709
710                         AppDomain ad = CreateTestDomain (tempDir, true);
711                         try {
712                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
713
714                                 int assemblyCount = cdt.AssemblyCount;
715
716                                 // PART A
717
718                                 AssemblyName aname = new AssemblyName ();
719                                 aname.Name = "multipleA";
720                                 aname.Version = new Version (1, 2, 3, 4);
721                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "multipleA.dll"));
722
723                                 Assert.AreEqual (assemblyCount + 1, cdt.AssemblyCount, "#A1");
724
725                                 aname = new AssemblyName ();
726                                 aname.Name = "multipleA";
727                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A2");
728
729                                 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A3");
730
731                                 aname = new AssemblyName ();
732                                 aname.Name = "multipleA";
733                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A4");
734
735                                 aname = new AssemblyName ();
736                                 aname.Name = "multipleA";
737                                 aname.CultureInfo = CultureInfo.InvariantCulture;
738                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A5");
739
740                                 aname = new AssemblyName ();
741                                 aname.Name = "multipleA";
742                                 aname.CultureInfo = CultureInfo.InvariantCulture;
743                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A6");
744
745                                 aname = new AssemblyName ();
746                                 aname.Name = "multipleA";
747                                 aname.CultureInfo = CultureInfo.InvariantCulture;
748                                 aname.Version = new Version (1, 2, 3, 4);
749                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A7");
750
751                                 aname = new AssemblyName ();
752                                 aname.Name = "multipleA";
753                                 aname.CultureInfo = CultureInfo.InvariantCulture;
754                                 aname.Version = new Version (1, 2, 3, 4);
755                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A8");
756
757                                 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A9");
758
759                                 // PART B
760
761                                 aname = new AssemblyName ();
762                                 aname.Name = "multipleB";
763                                 aname.CultureInfo = new CultureInfo ("nl-BE");
764                                 aname.Version = new Version (2, 4, 1, 0);
765                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleB.dll"));
766
767                                 Assert.AreEqual (assemblyCount + 3, cdt.AssemblyCount, "#B1");
768
769                                 aname = new AssemblyName ();
770                                 aname.Name = "multipleB";
771                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B2");
772
773                                 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B3");
774
775                                 aname = new AssemblyName ();
776                                 aname.Name = "multipleB";
777                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B4");
778
779                                 aname = new AssemblyName ();
780                                 aname.Name = "multipleB";
781                                 aname.CultureInfo = new CultureInfo ("nl-BE");
782                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B5");
783
784                                 aname = new AssemblyName ();
785                                 aname.Name = "multipleB";
786                                 aname.CultureInfo = new CultureInfo ("nl-BE");
787                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B6");
788
789                                 aname = new AssemblyName ();
790                                 aname.Name = "multipleB";
791                                 aname.CultureInfo = new CultureInfo ("nl-BE");
792                                 aname.Version = new Version (2, 4, 1, 0);
793                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B7");
794
795                                 aname = new AssemblyName ();
796                                 aname.Name = "multipleB";
797                                 aname.CultureInfo = new CultureInfo ("nl-BE");
798                                 aname.Version = new Version (2, 4, 1, 0);
799                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B8");
800
801                                 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B9");
802
803                                 // PART C
804
805                                 aname = new AssemblyName ();
806                                 aname.Name = "multipleC";
807                                 aname.CultureInfo = new CultureInfo ("nl-BE");
808                                 aname.Version = new Version (2, 4, 0, 0);
809                                 aname.KeyPair = new StrongNameKeyPair (keyPair);
810                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleC.dll"));
811
812                                 Assert.AreEqual (assemblyCount + 5, cdt.AssemblyCount, "#C1");
813
814                                 aname = new AssemblyName ();
815                                 aname.Name = "multipleC";
816                                 aname.CultureInfo = new CultureInfo ("nl-BE");
817                                 aname.Version = new Version (2, 4, 0, 0);
818                                 aname.SetPublicKey (publicKey);
819                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C2");
820
821                                 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C3");
822
823                                 aname = new AssemblyName ();
824                                 aname.Name = "multipleC";
825                                 aname.CultureInfo = new CultureInfo ("nl-BE");
826                                 aname.Version = new Version (2, 4, 0, 0);
827                                 aname.SetPublicKey (publicKey);
828                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C4");
829
830                                 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C5");
831                         } finally {
832                                 AppDomain.Unload (ad);
833                         }
834                 }
835
836                 [Test] // bug #79522
837                 [Category ("NotWorking")]
838                 public void Load_Manifest_Mismatch ()
839                 {
840                         string assemblyFile = Path.Combine (tempDir, "bug79522A.dll");
841                         AssemblyName aname = new AssemblyName ();
842                         aname.Name = "bug79522A";
843                         aname.Version = new Version (2, 4);
844
845                         GenerateAssembly (aname, assemblyFile);
846
847                         aname = new AssemblyName ();
848                         aname.CodeBase = assemblyFile;
849                         aname.Name = "whateveryouwant";
850                         aname.Version = new Version (1, 1);
851
852                         // despite the fact that no assembly with the specified name
853                         // exists, the assembly pointed to by the CodeBase of the
854                         // AssemblyName will be loaded
855                         //
856                         // however the display name of the loaded assembly does not
857                         // match the display name of the AssemblyName, and as a result
858                         // a FileLoadException is thrown
859                         try {
860                                 AppDomain.CurrentDomain.Load (aname);
861                                 Assert.Fail ("#A1");
862                         } catch (FileLoadException) {
863                         }
864
865                         // if we set CodeBase to some garbage, then we'll get a
866                         // FileNotFoundException instead
867                         aname.CodeBase = "whatever";
868                         try {
869                                 AppDomain.CurrentDomain.Load (aname);
870                                 Assert.Fail ("#A2");
871                         } catch (FileNotFoundException) {
872                         }
873
874                         aname = new AssemblyName ();
875                         aname.Name = "bug79522A";
876                         aname.CodeBase = assemblyFile;
877 #if NET_2_0
878                         AppDomain.CurrentDomain.Load (aname);
879 #else
880                         try {
881                                 AppDomain.CurrentDomain.Load (aname);
882                                 Assert.Fail ("#A3");
883                         } catch (FileLoadException) {
884                         }
885 #endif
886
887                         aname = new AssemblyName ();
888                         aname.Name = "bug79522A";
889                         aname.CodeBase = assemblyFile;
890                         aname.Version = new Version (2, 5);
891 #if NET_2_0
892                         // the version number is not considered when comparing the manifest
893                         // of the assembly found using codebase
894                         AppDomain.CurrentDomain.Load (aname);
895 #else
896                         try {
897                                 AppDomain.CurrentDomain.Load (aname);
898                                 Assert.Fail ("#A4");
899                         } catch (FileLoadException) {
900                         }
901 #endif
902
903                         aname = new AssemblyName ();
904                         aname.Name = "bug79522A";
905                         aname.CodeBase = assemblyFile;
906                         aname.Version = new Version (2, 4, 1);
907 #if NET_2_0
908                         // the version number is not considered when comparing the manifest
909                         // of the assembly found using codebase
910                         AppDomain.CurrentDomain.Load (aname);
911 #else
912                         try {
913                                 AppDomain.CurrentDomain.Load (aname);
914                                 Assert.Fail ("#A5");
915                         } catch (FileLoadException) {
916                         }
917 #endif
918
919                         // if version is set, then culture must also be set
920                         aname = new AssemblyName ();
921                         aname.Name = "bug79522A";
922                         aname.CodeBase = assemblyFile;
923                         aname.Version = new Version (2, 4);
924 #if NET_2_0
925                         AppDomain.CurrentDomain.Load (aname);
926 #else
927                         try {
928                                 AppDomain.CurrentDomain.Load (aname);
929                                 Assert.Fail ("#A6");
930                         } catch (FileLoadException) {
931                         }
932 #endif
933
934                         // version number does not need to be set
935                         aname = new AssemblyName ();
936                         aname.Name = "bug79522A";
937                         aname.CodeBase = assemblyFile;
938                         aname.CultureInfo = CultureInfo.InvariantCulture;
939                         AppDomain.CurrentDomain.Load (aname);
940
941                         // if set, the version number must match exactly
942                         aname = new AssemblyName ();
943                         aname.Name = "bug79522A";
944                         aname.CodeBase = assemblyFile;
945                         aname.CultureInfo = CultureInfo.InvariantCulture;
946                         aname.Version = new Version (2, 4);
947                         AppDomain.CurrentDomain.Load (aname);
948
949                         // if both culture and version are set, then the version diff
950                         // is ignored
951                         aname = new AssemblyName ();
952                         aname.Name = "bug79522A";
953                         aname.CodeBase = assemblyFile;
954                         aname.CultureInfo = CultureInfo.InvariantCulture;
955                         aname.Version = new Version (2, 5);
956                         AppDomain.CurrentDomain.Load (aname);
957
958                         // loaded assembly is not signed
959                         aname = new AssemblyName ();
960                         aname.Name = "bug79522A";
961                         aname.CodeBase = assemblyFile;
962                         aname.CultureInfo = CultureInfo.InvariantCulture;
963                         aname.Version = new Version (2, 4);
964                         aname.SetPublicKey (publicKey);
965                         try {
966                                 AppDomain.CurrentDomain.Load (aname);
967                                 Assert.Fail ("#A7");
968                         } catch (FileLoadException) {
969                         }
970
971                         // if set, the culture must match
972                         aname = new AssemblyName ();
973                         aname.Name = "bug79522A";
974                         aname.CodeBase = assemblyFile;
975                         aname.Version = new Version (2, 4);
976                         aname.CultureInfo = new CultureInfo ("en-US");
977                         try {
978                                 AppDomain.CurrentDomain.Load (aname);
979                                 Assert.Fail ("#A8");
980                         } catch (FileLoadException) {
981                         }
982
983                         // PART B
984
985                         assemblyFile = Path.Combine (tempDir, "bug79522B.dll");
986                         aname = new AssemblyName ();
987                         aname.Name = "bug79522B";
988                         aname.CultureInfo = new CultureInfo ("nl-BE");
989                         aname.Version = new Version (2, 4, 1);
990
991                         GenerateAssembly (aname, assemblyFile);
992
993                         aname = new AssemblyName ();
994                         aname.CodeBase = assemblyFile;
995                         aname.Name = "whateveryouwant";
996                         aname.CultureInfo = new CultureInfo ("nl-BE");
997                         aname.Version = new Version (1, 1);
998
999                         // despite the fact that no assembly with the specified name
1000                         // exists, the assembly pointed to by the CodeBase of the
1001                         // AssemblyName will be loaded
1002                         //
1003                         // however the display name of the loaded assembly does not
1004                         // match the display name of the AssemblyName, and as a result
1005                         // a FileLoadException is thrown
1006                         try {
1007                                 AppDomain.CurrentDomain.Load (aname);
1008                                 Assert.Fail ("#B1");
1009                         } catch (FileLoadException) {
1010                         }
1011
1012                         // if we set CodeBase to some garbage, then we'll get a
1013                         // FileNotFoundException instead
1014                         aname.CodeBase = "whatever";
1015                         try {
1016                                 AppDomain.CurrentDomain.Load (aname);
1017                                 Assert.Fail ("#B2");
1018                         } catch (FileNotFoundException) {
1019                         }
1020
1021                         aname = new AssemblyName ();
1022                         aname.Name = "bug79522B";
1023                         aname.CodeBase = assemblyFile;
1024 #if NET_2_0
1025                         // the version number is not considered when comparing the manifest
1026                         // of the assembly found using codebase
1027                         AppDomain.CurrentDomain.Load (aname);
1028 #else
1029                         try {
1030                                 AppDomain.CurrentDomain.Load (aname);
1031                                 Assert.Fail ("#B3");
1032                         } catch (FileLoadException) {
1033                         }
1034 #endif
1035
1036                         aname = new AssemblyName ();
1037                         aname.Name = "bug79522B";
1038                         aname.CodeBase = assemblyFile;
1039                         aname.Version = new Version (5, 5);
1040 #if NET_2_0
1041                         // the version number is not considered when comparing the manifest
1042                         // of the assembly found using codebase
1043                         AppDomain.CurrentDomain.Load (aname);
1044 #else
1045                         try {
1046                                 AppDomain.CurrentDomain.Load (aname);
1047                                 Assert.Fail ("#B3");
1048                         } catch (FileLoadException) {
1049                         }
1050 #endif
1051
1052                         aname = new AssemblyName ();
1053                         aname.Name = "bug79522B";
1054                         aname.CodeBase = assemblyFile;
1055                         aname.Version = new Version (2, 4, 1);
1056 #if NET_2_0
1057                         AppDomain.CurrentDomain.Load (aname);
1058 #else
1059                         // when the loaded assembly has a specific culture, then that
1060                         // culture must be set if you set the Version on the aname
1061                         try {
1062                                 AppDomain.CurrentDomain.Load (aname);
1063                                 Assert.Fail ("#B4");
1064                         } catch (FileLoadException) {
1065                         }
1066 #endif
1067
1068                         // version does not need to be set
1069                         aname = new AssemblyName ();
1070                         aname.Name = "bug79522B";
1071                         aname.CodeBase = assemblyFile;
1072                         aname.CultureInfo = new CultureInfo ("nl-BE");
1073                         AppDomain.CurrentDomain.Load (aname);
1074
1075                         // if both culture and version are set, then the version diff
1076                         // is ignored
1077                         aname = new AssemblyName ();
1078                         aname.Name = "bug79522B";
1079                         aname.CodeBase = assemblyFile;
1080                         aname.CultureInfo = new CultureInfo ("nl-BE");
1081                         aname.Version = new Version (6, 5);
1082                         AppDomain.CurrentDomain.Load (aname);
1083
1084                         // loaded assembly is not signed
1085                         aname = new AssemblyName ();
1086                         aname.Name = "bug79522B";
1087                         aname.CodeBase = assemblyFile;
1088                         aname.CultureInfo = new CultureInfo ("nl-BE");
1089                         aname.SetPublicKey (publicKey);
1090                         try {
1091                                 AppDomain.CurrentDomain.Load (aname);
1092                                 Assert.Fail ("#B5");
1093                         } catch (FileLoadException) {
1094                         }
1095
1096                         // if set, the culture must match
1097                         aname = new AssemblyName ();
1098                         aname.Name = "bug79522B";
1099                         aname.CodeBase = assemblyFile;
1100                         aname.Version = new Version (2, 4, 1);
1101                         aname.CultureInfo = new CultureInfo ("en-US");
1102                         try {
1103                                 AppDomain.CurrentDomain.Load (aname);
1104                                 Assert.Fail ("#B6");
1105                         } catch (FileLoadException) {
1106                         }
1107
1108                         // PART C
1109
1110                         assemblyFile = Path.Combine (tempDir, "bug79522C.dll");
1111                         aname = new AssemblyName ();
1112                         aname.Name = "bug79522C";
1113                         aname.CultureInfo = new CultureInfo ("nl-BE");
1114                         aname.Version = new Version (2, 4);
1115                         aname.KeyPair = new StrongNameKeyPair (keyPair);
1116
1117                         GenerateAssembly (aname, assemblyFile);
1118
1119                         aname = new AssemblyName ();
1120                         aname.CodeBase = assemblyFile;
1121                         aname.Name = "whateveryouwant";
1122                         aname.CultureInfo = new CultureInfo ("nl-BE");
1123                         aname.Version = new Version (1, 1);
1124                         aname.SetPublicKey (publicKey);
1125
1126                         // despite the fact that no assembly with the specified name
1127                         // exists, the assembly pointed to by the CodeBase of the
1128                         // AssemblyName will be loaded
1129                         //
1130                         // however the display name of the loaded assembly does not
1131                         // match the display name of the AssemblyName, and as a result
1132                         // a FileLoadException is thrown
1133                         try {
1134                                 AppDomain.CurrentDomain.Load (aname);
1135                                 Assert.Fail ("#C1");
1136                         } catch (FileLoadException) {
1137                         }
1138
1139                         // if we set CodeBase to some garbage, then we'll get a
1140                         // FileNotFoundException instead
1141                         aname.CodeBase = "whatever";
1142                         try {
1143                                 AppDomain.CurrentDomain.Load (aname);
1144                                 Assert.Fail ("#C2");
1145                         } catch (FileNotFoundException) {
1146                         }
1147
1148                         aname = new AssemblyName ();
1149                         aname.Name = "bug79522C";
1150                         aname.CodeBase = assemblyFile;
1151 #if NET_2_0
1152                         AppDomain.CurrentDomain.Load (aname);
1153 #else
1154                         try {
1155                                 AppDomain.CurrentDomain.Load (aname);
1156                                 Assert.Fail ("#C3");
1157                         } catch (FileLoadException) {
1158                         }
1159 #endif
1160
1161                         aname = new AssemblyName ();
1162                         aname.Name = "bug79522C";
1163                         aname.CodeBase = assemblyFile;
1164                         aname.Version = new Version (5, 5);
1165                         try {
1166                                 AppDomain.CurrentDomain.Load (aname);
1167                                 Assert.Fail ("#C3");
1168                         } catch (FileLoadException) {
1169                         }
1170
1171                         aname = new AssemblyName ();
1172                         aname.Name = "bug79522C";
1173                         aname.CodeBase = assemblyFile;
1174                         aname.Version = new Version (2, 4);
1175 #if NET_2_0
1176                         AppDomain.CurrentDomain.Load (aname);
1177 #else
1178                         // when the loaded assembly has a specific culture/publickey,
1179                         // then that culture/publickey must be set if you set the
1180                         // Version on the aname
1181                         try {
1182                                 AppDomain.CurrentDomain.Load (aname);
1183                                 Assert.Fail ("#C4");
1184                         } catch (FileLoadException) {
1185                         }
1186 #endif
1187
1188                         aname = new AssemblyName ();
1189                         aname.Name = "bug79522C";
1190                         aname.CodeBase = assemblyFile;
1191                         aname.CultureInfo = new CultureInfo ("nl-BE");
1192                         aname.Version = new Version (2, 4);
1193 #if NET_2_0
1194                         AppDomain.CurrentDomain.Load (aname);
1195 #else
1196                         // if loaded assembly is signed, then the public key must be set
1197                         try {
1198                                 AppDomain.CurrentDomain.Load (aname);
1199                                 Assert.Fail ("#C5");
1200                         } catch (FileLoadException) {
1201                         }
1202 #endif
1203
1204                         aname = new AssemblyName ();
1205                         aname.Name = "bug79522C";
1206                         aname.CodeBase = assemblyFile;
1207                         aname.CultureInfo = new CultureInfo ("nl-BE");
1208                         aname.SetPublicKey (publicKey);
1209 #if NET_2_0
1210                         AppDomain.CurrentDomain.Load (aname);
1211 #else
1212                         // if public key is set, then version must be set
1213                         try {
1214                                 AppDomain.CurrentDomain.Load (aname);
1215                                 Assert.Fail ("#C6");
1216                         } catch (FileLoadException) {
1217                         }
1218 #endif
1219
1220                         aname = new AssemblyName ();
1221                         aname.Name = "bug79522C";
1222                         aname.CodeBase = assemblyFile;
1223                         aname.CultureInfo = new CultureInfo ("nl-BE");
1224 #if NET_2_0
1225                         AppDomain.CurrentDomain.Load (aname);
1226 #else
1227                         try {
1228                                 AppDomain.CurrentDomain.Load (aname);
1229                                 Assert.Fail ("#C7");
1230                         } catch (FileLoadException) {
1231                         }
1232 #endif
1233
1234                         // if culture and version are set, then the version must match
1235                         aname = new AssemblyName ();
1236                         aname.Name = "bug79522C";
1237                         aname.CodeBase = assemblyFile;
1238                         aname.CultureInfo = new CultureInfo ("nl-BE");
1239                         aname.SetPublicKey (publicKey);
1240                         aname.Version = new Version (5, 6);
1241                         try {
1242                                 AppDomain.CurrentDomain.Load (aname);
1243                                 Assert.Fail ("#C8");
1244                         } catch (FileLoadException) {
1245                         }
1246
1247                         // publickey must match
1248                         aname = new AssemblyName ();
1249                         aname.Name = "bug79522C";
1250                         aname.CodeBase = assemblyFile;
1251                         aname.CultureInfo = new CultureInfo ("nl-BE");
1252                         aname.Version = new Version (2, 4);
1253                         aname.SetPublicKey (publicKey2);
1254                         try {
1255                                 AppDomain.CurrentDomain.Load (aname);
1256                                 Assert.Fail ("#C9");
1257 #if NET_2_0
1258                         } catch (SecurityException) {
1259                                 // Invalid assembly public key
1260                         }
1261 #else
1262                         } catch (FileLoadException) {
1263                         }
1264 #endif
1265
1266                         aname = new AssemblyName ();
1267                         aname.Name = "bug79522C";
1268                         aname.CodeBase = assemblyFile;
1269                         aname.SetPublicKey (publicKey);
1270                         aname.CultureInfo = new CultureInfo ("nl-BE");
1271                         aname.Version = new Version (2, 4);
1272                         AppDomain.CurrentDomain.Load (aname);
1273                 }
1274
1275                 [Test] // bug #79715
1276                 public void Load_PartialVersion ()
1277                 {
1278                         AppDomain ad = CreateTestDomain (tempDir, true);
1279                         try {
1280                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
1281
1282                                 AssemblyName aname = new AssemblyName ();
1283                                 aname.Name = "bug79715";
1284                                 aname.Version = new Version (1, 2, 3, 4);
1285                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "bug79715.dll"));
1286
1287                                 aname = new AssemblyName ();
1288                                 aname.Name = "bug79715";
1289                                 aname.Version = new Version (1, 2);
1290                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A1");
1291                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#A2");
1292
1293                                 aname = new AssemblyName ();
1294                                 aname.Name = "bug79715";
1295                                 aname.Version = new Version (1, 2, 3);
1296                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B1");
1297                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#B2");
1298
1299                                 aname = new AssemblyName ();
1300                                 aname.Name = "bug79715";
1301                                 aname.Version = new Version (1, 2, 3, 4);
1302                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C1");
1303                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#C2");
1304                         } finally {
1305                                 AppDomain.Unload (ad);
1306                         }
1307                 }
1308
1309                 [Test]
1310                 public void SetAppDomainPolicy ()
1311                 {
1312                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
1313                         ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
1314                         // not much to see
1315                 }
1316
1317                 [Test]
1318                 [ExpectedException (typeof (ArgumentNullException))]
1319                 public void SetAppDomainPolicy_Null ()
1320                 {
1321                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
1322                         ad.SetAppDomainPolicy (null);
1323                 }
1324
1325                 [Test]
1326                 [ExpectedException (typeof (PolicyException))]
1327                 public void SetAppDomainPolicy_Dual ()
1328                 {
1329                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Dual");
1330                         PolicyLevel pl = PolicyLevel.CreateAppDomainLevel ();
1331                         PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
1332                         pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
1333                         ad.SetAppDomainPolicy (pl);
1334
1335                         // only one time!
1336                         pl = PolicyLevel.CreateAppDomainLevel ();
1337                         ps = new PermissionSet (PermissionState.None);
1338                         pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
1339                         ad.SetAppDomainPolicy (pl);
1340                 }
1341
1342                 [Test]
1343                 [ExpectedException (typeof (AppDomainUnloadedException))]
1344                 public void SetAppDomainPolicy_Unloaded ()
1345                 {
1346                         ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Unloaded");
1347                         AppDomain.Unload (ad);
1348                         ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
1349                 }
1350
1351                 [Test]
1352                 [ExpectedException (typeof (ArgumentNullException))]
1353                 public void GetData_Null ()
1354                 {
1355                         AppDomain.CurrentDomain.GetData (null);
1356                 }
1357
1358                 [Test]
1359                 public void SetData ()
1360                 {
1361                         AppDomain.CurrentDomain.SetData ("data", "data");
1362                         Assert.AreEqual ("data", AppDomain.CurrentDomain.GetData ("data"), "GetData");
1363                         AppDomain.CurrentDomain.SetData ("data", null);
1364                         Assert.IsNull (AppDomain.CurrentDomain.GetData ("data"), "GetData-Null");
1365                 }
1366
1367                 [Test]
1368                 [ExpectedException (typeof (ArgumentNullException))]
1369                 public void SetData_Null ()
1370                 {
1371                         AppDomain.CurrentDomain.SetData (null, "data");
1372                 }
1373
1374 #if NET_2_0
1375                 [Test]
1376                 public void ApplyPolicy ()
1377                 {
1378                         ad = AppDomain.CreateDomain ("ApplyPolicy");
1379                         string fullname = Assembly.GetExecutingAssembly ().FullName;
1380                         string result = ad.ApplyPolicy (fullname);
1381                         Assert.AreEqual (fullname, result, "ApplyPolicy");
1382                         // doesn't even requires an assembly name
1383                         Assert.AreEqual ("123", ad.ApplyPolicy ("123"), "Invalid FullName");
1384                 }
1385
1386                 [Test]
1387                 [ExpectedException (typeof (ArgumentException))]
1388                 public void ApplyPolicy_Empty ()
1389                 {
1390                         ad = AppDomain.CreateDomain ("ApplyPolicy_Empty");
1391                         ad.ApplyPolicy (String.Empty);
1392                 }
1393
1394                 [Test]
1395                 [ExpectedException (typeof (ArgumentNullException))]
1396                 public void ApplyPolicy_Null ()
1397                 {
1398                         ad = AppDomain.CreateDomain ("ApplyPolicy_Null");
1399                         ad.ApplyPolicy (null);
1400                 }
1401
1402                 [Test]
1403                 public void DomainManager ()
1404                 {
1405                         Assert.IsNull (AppDomain.CurrentDomain.DomainManager, "CurrentDomain.DomainManager");
1406                         ad = AppDomain.CreateDomain ("DomainManager");
1407                         Assert.IsNull (ad.DomainManager, "ad.DomainManager");
1408                 }
1409
1410                 [Test]
1411                 public void IsDefaultAppDomain ()
1412                 {
1413                         ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
1414                         Assert.IsFalse (ad.IsDefaultAppDomain (), "IsDefaultAppDomain");
1415                         // we have no public way to get the default appdomain
1416                 }
1417
1418                 [Test]
1419                 public void ReflectionOnlyGetAssemblies ()
1420                 {
1421                         ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
1422                         Assembly [] a = ad.ReflectionOnlyGetAssemblies ();
1423                         Assert.IsNotNull (a, "ReflectionOnlyGetAssemblies");
1424                         Assert.AreEqual (0, a.Length, "Count");
1425                 }
1426 #endif
1427
1428                 private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
1429                 {
1430                         AppDomainSetup setup = new AppDomainSetup ();
1431                         setup.ApplicationBase = baseDirectory;
1432                         setup.ApplicationName = "testdomain";
1433                         return CreateTestDomain (setup, assemblyResolver);
1434                 }
1435
1436                 private static AppDomain CreateTestDomain (AppDomainSetup setup, bool assemblyResolver)
1437                 {
1438                         AppDomain ad = AppDomain.CreateDomain ("testdomain",
1439                                 AppDomain.CurrentDomain.Evidence, setup);
1440
1441                         if (assemblyResolver) {
1442                                 Assembly ea = Assembly.GetExecutingAssembly ();
1443                                 ad.CreateInstanceFrom (ea.CodeBase,
1444                                         typeof (AssemblyResolveHandler).FullName,
1445                                         false,
1446                                         BindingFlags.Public | BindingFlags.Instance,
1447                                         null,
1448                                         new object [] { ea.Location, ea.FullName },
1449                                         CultureInfo.InvariantCulture,
1450                                         null,
1451                                         null);
1452                         }
1453
1454                         return ad;
1455                 }
1456
1457
1458                 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
1459                 {
1460                         Type testerType = typeof (CrossDomainTester);
1461                         return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
1462                                 testerType.Assembly.FullName, testerType.FullName, false,
1463                                 BindingFlags.Public | BindingFlags.Instance, null, new object [0],
1464                                 CultureInfo.InvariantCulture, new object [0], null);
1465                 }
1466
1467                 private static void GenerateAssembly (AssemblyName aname, string path)
1468                 {
1469                         AppDomain ad = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory,
1470                                 false);
1471                         try {
1472                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
1473                                 cdt.GenerateAssembly (aname, path);
1474                         } finally {
1475                                 AppDomain.Unload (ad);
1476                         }
1477                 }
1478
1479                 private bool RunningOnUnix {
1480                         get {
1481                                 // check for Unix platforms - see FAQ for more details
1482                                 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
1483                                 int platform = (int) Environment.OSVersion.Platform;
1484                                 return ((platform == 4) || (platform == 128));
1485                         }
1486                 }
1487
1488                 private class CrossDomainTester : MarshalByRefObject
1489                 {
1490                         public void GenerateAssembly (AssemblyName aname, string path)
1491                         {
1492                                 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1493                                         aname, AssemblyBuilderAccess.Save, Path.GetDirectoryName (path));
1494                                 ab.Save (Path.GetFileName (path));
1495                         }
1496
1497                         public int AssemblyCount {
1498                                 get {
1499                                         return AppDomain.CurrentDomain.GetAssemblies ().Length;
1500                                 }
1501                         }
1502
1503                         public string GetApplicationBase ()
1504                         {
1505                                 return AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
1506                         }
1507
1508                         public string GetConfigurationFile ()
1509                         {
1510                                 return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
1511                         }
1512
1513                         public void Load (AssemblyName assemblyRef)
1514                         {
1515                                 AppDomain.CurrentDomain.Load (assemblyRef);
1516                         }
1517
1518                         public void LoadFrom (string assemblyFile)
1519                         {
1520                                 Assembly.LoadFrom (assemblyFile);
1521                         }
1522
1523                         public bool AssertLoad (AssemblyName assemblyRef)
1524                         {
1525                                 try {
1526                                         AppDomain.CurrentDomain.Load (assemblyRef);
1527                                         return true;
1528                                 } catch {
1529                                         return false;
1530                                 }
1531                         }
1532
1533                         public bool AssertLoad (string assemblyString)
1534                         {
1535                                 try {
1536                                         AppDomain.CurrentDomain.Load (assemblyString);
1537                                         return true;
1538                                 } catch {
1539                                         return false;
1540                                 }
1541                         }
1542
1543                         public bool AssertFileLoadException (AssemblyName assemblyRef)
1544                         {
1545                                 try {
1546                                         AppDomain.CurrentDomain.Load (assemblyRef);
1547                                         return false;
1548                                 } catch (FileLoadException) {
1549                                         return true;
1550                                 }
1551                         }
1552
1553                         public bool AssertFileNotFoundException (AssemblyName assemblyRef)
1554                         {
1555                                 try {
1556                                         AppDomain.CurrentDomain.Load (assemblyRef);
1557                                         return false;
1558                                 } catch (FileNotFoundException) {
1559                                         return true;
1560                                 }
1561                         }
1562                 }
1563
1564                 [Serializable ()]
1565                 private class AssemblyResolveHandler
1566                 {
1567                         public AssemblyResolveHandler (string assemblyFile, string assemblyName)
1568                         {
1569                                 _assemblyFile = assemblyFile;
1570                                 _assemblyName = assemblyName;
1571
1572                                 AppDomain.CurrentDomain.AssemblyResolve +=
1573                                         new ResolveEventHandler (ResolveAssembly);
1574                         }
1575
1576                         private Assembly ResolveAssembly (Object sender, ResolveEventArgs args)
1577                         {
1578                                 if (args.Name == _assemblyName)
1579                                         return Assembly.LoadFrom (_assemblyFile);
1580
1581                                 return null;
1582                         }
1583
1584                         private readonly string _assemblyFile;
1585                         private readonly string _assemblyName;
1586                 }
1587
1588                 static byte [] keyPair = {
1589                         0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
1590                         0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3D, 0xBD,
1591                         0x72, 0x08, 0xC6, 0x2B, 0x0E, 0xA8, 0xC1, 0xC0, 0x58, 0x07, 0x2B,
1592                         0x63, 0x5F, 0x7C, 0x9A, 0xBD, 0xCB, 0x22, 0xDB, 0x20, 0xB2, 0xA9,
1593                         0xDA, 0xDA, 0xEF, 0xE8, 0x00, 0x64, 0x2F, 0x5D, 0x8D, 0xEB, 0x78,
1594                         0x02, 0xF7, 0xA5, 0x36, 0x77, 0x28, 0xD7, 0x55, 0x8D, 0x14, 0x68,
1595                         0xDB, 0xEB, 0x24, 0x09, 0xD0, 0x2B, 0x13, 0x1B, 0x92, 0x6E, 0x2E,
1596                         0x59, 0x54, 0x4A, 0xAC, 0x18, 0xCF, 0xC9, 0x09, 0x02, 0x3F, 0x4F,
1597                         0xA8, 0x3E, 0x94, 0x00, 0x1F, 0xC2, 0xF1, 0x1A, 0x27, 0x47, 0x7D,
1598                         0x10, 0x84, 0xF5, 0x14, 0xB8, 0x61, 0x62, 0x1A, 0x0C, 0x66, 0xAB,
1599                         0xD2, 0x4C, 0x4B, 0x9F, 0xC9, 0x0F, 0x3C, 0xD8, 0x92, 0x0F, 0xF5,
1600                         0xFF, 0xCE, 0xD7, 0x6E, 0x5C, 0x6F, 0xB1, 0xF5, 0x7D, 0xD3, 0x56,
1601                         0xF9, 0x67, 0x27, 0xA4, 0xA5, 0x48, 0x5B, 0x07, 0x93, 0x44, 0x00,
1602                         0x4A, 0xF8, 0xFF, 0xA4, 0xCB, 0x73, 0xC0, 0x6A, 0x62, 0xB4, 0xB7,
1603                         0xC8, 0x92, 0x58, 0x87, 0xCD, 0x07, 0x0C, 0x7D, 0x6C, 0xC1, 0x4A,
1604                         0xFC, 0x82, 0x57, 0x0E, 0x43, 0x85, 0x09, 0x75, 0x98, 0x51, 0xBB,
1605                         0x35, 0xF5, 0x64, 0x83, 0xC7, 0x79, 0x89, 0x5C, 0x55, 0x36, 0x66,
1606                         0xAB, 0x27, 0xA4, 0xD9, 0xD4, 0x7E, 0x6B, 0x67, 0x64, 0xC1, 0x54,
1607                         0x4E, 0x37, 0xF1, 0x4E, 0xCA, 0xB3, 0xE5, 0x63, 0x91, 0x57, 0x12,
1608                         0x14, 0xA6, 0xEA, 0x8F, 0x8F, 0x2B, 0xFE, 0xF3, 0xE9, 0x16, 0x08,
1609                         0x2B, 0x86, 0xBC, 0x26, 0x0D, 0xD0, 0xC6, 0xC4, 0x1A, 0x72, 0x43,
1610                         0x76, 0xDC, 0xFF, 0x28, 0x52, 0xA1, 0xDE, 0x8D, 0xFA, 0xD5, 0x1F,
1611                         0x0B, 0xB5, 0x4F, 0xAF, 0x06, 0x79, 0x11, 0xEE, 0xA8, 0xEC, 0xD3,
1612                         0x74, 0x55, 0xA2, 0x80, 0xFC, 0xF8, 0xD9, 0x50, 0x69, 0x48, 0x01,
1613                         0xC2, 0x5A, 0x04, 0x56, 0xB4, 0x3E, 0x24, 0x32, 0x20, 0xB5, 0x2C,
1614                         0xDE, 0xBB, 0xBD, 0x13, 0xFD, 0x13, 0xF7, 0x03, 0x3E, 0xE3, 0x37,
1615                         0x84, 0x74, 0xE7, 0xD0, 0x5E, 0x9E, 0xB6, 0x26, 0xAE, 0x6E, 0xB0,
1616                         0x55, 0x6A, 0x52, 0x63, 0x6F, 0x5A, 0x9D, 0xF2, 0x67, 0xD6, 0x61,
1617                         0x4F, 0x7A, 0x45, 0xEE, 0x5C, 0x3D, 0x2B, 0x7C, 0xB2, 0x40, 0x79,
1618                         0x54, 0x84, 0xD1, 0xBE, 0x61, 0x3E, 0x5E, 0xD6, 0x18, 0x8E, 0x14,
1619                         0x98, 0xFC, 0x35, 0xBF, 0x5F, 0x1A, 0x20, 0x2E, 0x1A, 0xD8, 0xFF,
1620                         0xC4, 0x6B, 0xC0, 0xC9, 0x7D, 0x06, 0xEF, 0x09, 0xF9, 0xF3, 0x69,
1621                         0xFC, 0xBC, 0xA2, 0xE6, 0x80, 0x22, 0xB9, 0x79, 0x7E, 0xEF, 0x57,
1622                         0x9F, 0x49, 0xE1, 0xBC, 0x0D, 0xB6, 0xA1, 0xFE, 0x8D, 0xBC, 0xBB,
1623                         0xA3, 0x05, 0x02, 0x6B, 0x04, 0x45, 0xF7, 0x5D, 0xEE, 0x43, 0x06,
1624                         0xD6, 0x9C, 0x94, 0x48, 0x1A, 0x0B, 0x9C, 0xBC, 0xB4, 0x4E, 0x93,
1625                         0x60, 0x87, 0xCD, 0x58, 0xD6, 0x9A, 0x39, 0xA6, 0xC0, 0x7F, 0x8E,
1626                         0xFF, 0x25, 0xC1, 0xD7, 0x2C, 0xF6, 0xF4, 0x6F, 0x24, 0x52, 0x0B,
1627                         0x39, 0x42, 0x1B, 0x0D, 0x04, 0xC1, 0x93, 0x2A, 0x19, 0x1C, 0xF0,
1628                         0xB1, 0x9B, 0xC1, 0x24, 0x6D, 0x1B, 0x0B, 0xDA, 0x1C, 0x8B, 0x72,
1629                         0x48, 0xF0, 0x3E, 0x52, 0xBF, 0x0A, 0x84, 0x3A, 0x9B, 0xC8, 0x6D,
1630                         0x13, 0x1E, 0x72, 0xF4, 0x46, 0x93, 0x88, 0x1A, 0x5F, 0x4C, 0x3C,
1631                         0xE5, 0x9D, 0x6E, 0xBB, 0x4E, 0xDD, 0x5D, 0x1F, 0x11, 0x40, 0xF4,
1632                         0xD7, 0xAF, 0xB3, 0xAB, 0x9A, 0x99, 0x15, 0xF0, 0xDC, 0xAA, 0xFF,
1633                         0x9F, 0x2D, 0x9E, 0x56, 0x4F, 0x35, 0x5B, 0xBA, 0x06, 0x99, 0xEA,
1634                         0xC6, 0xB4, 0x48, 0x51, 0x17, 0x1E, 0xD1, 0x95, 0x84, 0x81, 0x18,
1635                         0xC0, 0xF1, 0x71, 0xDE, 0x44, 0x42, 0x02, 0x06, 0xAC, 0x0E, 0xA8,
1636                         0xE2, 0xF3, 0x1F, 0x96, 0x1F, 0xBE, 0xB6, 0x1F, 0xB5, 0x3E, 0xF6,
1637                         0x81, 0x05, 0x20, 0xFA, 0x2E, 0x40, 0x2E, 0x4D, 0xA0, 0x0E, 0xDA,
1638                         0x42, 0x9C, 0x05, 0xAA, 0x9E, 0xAF, 0x5C, 0xF7, 0x3A, 0x3F, 0xBB,
1639                         0x91, 0x73, 0x45, 0x27, 0xA8, 0xA2, 0x07, 0x4A, 0xEF, 0x59, 0x1E,
1640                         0x97, 0x9D, 0xE0, 0x30, 0x5A, 0x83, 0xCE, 0x1E, 0x57, 0x32, 0x89,
1641                         0x43, 0x41, 0x28, 0x7D, 0x14, 0x8D, 0x8B, 0x41, 0x1A, 0x56, 0x76,
1642                         0x43, 0xDB, 0x64, 0x86, 0x41, 0x64, 0x8D, 0x4C, 0x91, 0x83, 0x4E,
1643                         0xF5, 0x6C };
1644
1645                 static byte [] publicKey2 = {
1646                         0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
1647                         0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x7F, 0x7C,
1648                         0xEA, 0x4A, 0x28, 0x33, 0xD8, 0x3C, 0x86, 0x90, 0x86, 0x91, 0x11,
1649                         0xBB, 0x30, 0x0D, 0x3D, 0x69, 0x04, 0x4C, 0x48, 0xF5, 0x4F, 0xE7,
1650                         0x64, 0xA5, 0x82, 0x72, 0x5A, 0x92, 0xC4, 0x3D, 0xC5, 0x90, 0x93,
1651                         0x41, 0xC9, 0x1D, 0x34, 0x16, 0x72, 0x2B, 0x85, 0xC1, 0xF3, 0x99,
1652                         0x62, 0x07, 0x32, 0x98, 0xB7, 0xE4, 0xFA, 0x75, 0x81, 0x8D, 0x08,
1653                         0xB9, 0xFD, 0xDB, 0x00, 0x25, 0x30, 0xC4, 0x89, 0x13, 0xB6, 0x43,
1654                         0xE8, 0xCC, 0xBE, 0x03, 0x2E, 0x1A, 0x6A, 0x4D, 0x36, 0xB1, 0xEB,
1655                         0x49, 0x26, 0x6C, 0xAB, 0xC4, 0x29, 0xD7, 0x8F, 0x25, 0x11, 0xA4,
1656                         0x7C, 0x81, 0x61, 0x97, 0xCB, 0x44, 0x2D, 0x80, 0x49, 0x93, 0x48,
1657                         0xA7, 0xC9, 0xAB, 0xDB, 0xCF, 0xA3, 0x34, 0xCB, 0x6B, 0x86, 0xE0,
1658                         0x4D, 0x27, 0xFC, 0xA7, 0x4F, 0x36, 0xCA, 0x13, 0x42, 0xD3, 0x83,
1659                         0xC4, 0x06, 0x6E, 0x12, 0xE0, 0xA1, 0x3D, 0x9F, 0xA9, 0xEC, 0xD1,
1660                         0xC6, 0x08, 0x1B, 0x3D, 0xF5, 0xDB, 0x4C, 0xD4, 0xF0, 0x2C, 0xAA,
1661                         0xFC, 0xBA, 0x18, 0x6F, 0x48, 0x7E, 0xB9, 0x47, 0x68, 0x2E, 0xF6,
1662                         0x1E, 0x67, 0x1C, 0x7E, 0x0A, 0xCE, 0x10, 0x07, 0xC0, 0x0C, 0xAD,
1663                         0x5E, 0xC1, 0x53, 0x70, 0xD5, 0xE7, 0x25, 0xCA, 0x37, 0x5E, 0x49,
1664                         0x59, 0xD0, 0x67, 0x2A, 0xBE, 0x92, 0x36, 0x86, 0x8A, 0xBF, 0x3E,
1665                         0x17, 0x04, 0xFB, 0x1F, 0x46, 0xC8, 0x10, 0x5C, 0x93, 0x02, 0x43,
1666                         0x14, 0x96, 0x6A, 0xD9, 0x87, 0x17, 0x62, 0x7D, 0x3A, 0x45, 0xBE,
1667                         0x35, 0xDE, 0x75, 0x0B, 0x2A, 0xCE, 0x7D, 0xF3, 0x19, 0x85, 0x4B,
1668                         0x0D, 0x6F, 0x8D, 0x15, 0xA3, 0x60, 0x61, 0x28, 0x55, 0x46, 0xCE,
1669                         0x78, 0x31, 0x04, 0x18, 0x3C, 0x56, 0x4A, 0x3F, 0xA4, 0xC9, 0xB1,
1670                         0x41, 0xED, 0x22, 0x80, 0xA1, 0xB3, 0xE2, 0xC7, 0x1B, 0x62, 0x85,
1671                         0xE4, 0x81, 0x39, 0xCB, 0x1F, 0x95, 0xCC, 0x61, 0x61, 0xDF, 0xDE,
1672                         0xF3, 0x05, 0x68, 0xB9, 0x7D, 0x4F, 0xFF, 0xF3, 0xC0, 0x0A, 0x25,
1673                         0x62, 0xD9, 0x8A, 0x8A, 0x9E, 0x99, 0x0B, 0xFB, 0x85, 0x27, 0x8D,
1674                         0xF6, 0xD4, 0xE1, 0xB9, 0xDE, 0xB4, 0x16, 0xBD, 0xDF, 0x6A, 0x25,
1675                         0x9C, 0xAC, 0xCD, 0x91, 0xF7, 0xCB, 0xC1, 0x81, 0x22, 0x0D, 0xF4,
1676                         0x7E, 0xEC, 0x0C, 0x84, 0x13, 0x5A, 0x74, 0x59, 0x3F, 0x3E, 0x61,
1677                         0x00, 0xD6, 0xB5, 0x4A, 0xA1, 0x04, 0xB5, 0xA7, 0x1C, 0x29, 0xD0,
1678                         0xE1, 0x11, 0x19, 0xD7, 0x80, 0x5C, 0xEE, 0x08, 0x15, 0xEB, 0xC9,
1679                         0xA8, 0x98, 0xF5, 0xA0, 0xF0, 0x92, 0x2A, 0xB0, 0xD3, 0xC7, 0x8C,
1680                         0x8D, 0xBB, 0x88, 0x96, 0x4F, 0x18, 0xF0, 0x8A, 0xF9, 0x31, 0x9E,
1681                         0x44, 0x94, 0x75, 0x6F, 0x78, 0x04, 0x10, 0xEC, 0xF3, 0xB0, 0xCE,
1682                         0xA0, 0xBE, 0x7B, 0x25, 0xE1, 0xF7, 0x8A, 0xA8, 0xD4, 0x63, 0xC2,
1683                         0x65, 0x47, 0xCC, 0x5C, 0xED, 0x7D, 0x8B, 0x07, 0x4D, 0x76, 0x29,
1684                         0x53, 0xAC, 0x27, 0x8F, 0x5D, 0x78, 0x56, 0xFA, 0x99, 0x45, 0xA2,
1685                         0xCC, 0x65, 0xC4, 0x54, 0x13, 0x9F, 0x38, 0x41, 0x7A, 0x61, 0x0E,
1686                         0x0D, 0x34, 0xBC, 0x11, 0xAF, 0xE2, 0xF1, 0x8B, 0xFA, 0x2B, 0x54,
1687                         0x6C, 0xA3, 0x6C, 0x09, 0x1F, 0x0B, 0x43, 0x9B, 0x07, 0x95, 0x83,
1688                         0x3F, 0x97, 0x99, 0x89, 0xF5, 0x51, 0x41, 0xF6, 0x8E, 0x5D, 0xEF,
1689                         0x6D, 0x24, 0x71, 0x41, 0x7A, 0xAF, 0xBE, 0x81, 0x71, 0xAB, 0x76,
1690                         0x2F, 0x1A, 0x5A, 0xBA, 0xF3, 0xA6, 0x65, 0x7A, 0x80, 0x50, 0xCE,
1691                         0x23, 0xC3, 0xC7, 0x53, 0xB0, 0x7C, 0x97, 0x77, 0x27, 0x70, 0x98,
1692                         0xAE, 0xB5, 0x24, 0x66, 0xE1, 0x60, 0x39, 0x41, 0xDA, 0x54, 0x01,
1693                         0x64, 0xFB, 0x10, 0x33, 0xCE, 0x8B, 0xBE, 0x27, 0xD4, 0x21, 0x57,
1694                         0xCC, 0x0F, 0x1A, 0xC1, 0x3D, 0xF3, 0xCC, 0x39, 0xF0, 0x2F, 0xAE,
1695                         0xF1, 0xC0, 0xCD, 0x3B, 0x23, 0x87, 0x49, 0x7E, 0x40, 0x32, 0x6A,
1696                         0xD3, 0x96, 0x4A, 0xE5, 0x5E, 0x6E, 0x26, 0xFD, 0x8A, 0xCF, 0x7E,
1697                         0xFC, 0x37, 0xDE, 0x39, 0x0C, 0x53, 0x81, 0x75, 0x08, 0xAF, 0x6B,
1698                         0x39, 0x6C, 0xFB, 0xC9, 0x79, 0xC0, 0x9B, 0x5F, 0x34, 0x86, 0xB2,
1699                         0xDE, 0xC4, 0x19, 0x84, 0x5F, 0x0E, 0xED, 0x9B, 0xB8, 0xD3, 0x17,
1700                         0xDA, 0x78 };
1701
1702                 static byte [] publicKey = {
1703                         0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00,
1704                         0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53,
1705                         0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3d,
1706                         0xbd, 0x72, 0x08, 0xc6, 0x2b, 0x0e, 0xa8, 0xc1, 0xc0, 0x58, 0x07,
1707                         0x2b, 0x63, 0x5f, 0x7c, 0x9a, 0xbd, 0xcb, 0x22, 0xdb, 0x20, 0xb2,
1708                         0xa9, 0xda, 0xda, 0xef, 0xe8, 0x00, 0x64, 0x2f, 0x5d, 0x8d, 0xeb,
1709                         0x78, 0x02, 0xf7, 0xa5, 0x36, 0x77, 0x28, 0xd7, 0x55, 0x8d, 0x14,
1710                         0x68, 0xdb, 0xeb, 0x24, 0x09, 0xd0, 0x2b, 0x13, 0x1b, 0x92, 0x6e,
1711                         0x2e, 0x59, 0x54, 0x4a, 0xac, 0x18, 0xcf, 0xc9, 0x09, 0x02, 0x3f,
1712                         0x4f, 0xa8, 0x3e, 0x94, 0x00, 0x1f, 0xc2, 0xf1, 0x1a, 0x27, 0x47,
1713                         0x7d, 0x10, 0x84, 0xf5, 0x14, 0xb8, 0x61, 0x62, 0x1a, 0x0c, 0x66,
1714                         0xab, 0xd2, 0x4c, 0x4b, 0x9f, 0xc9, 0x0f, 0x3c, 0xd8, 0x92, 0x0f,
1715                         0xf5, 0xff, 0xce, 0xd7, 0x6e, 0x5c, 0x6f, 0xb1, 0xf5, 0x7d, 0xd3,
1716                         0x56, 0xf9, 0x67, 0x27, 0xa4, 0xa5, 0x48, 0x5b, 0x07, 0x93, 0x44,
1717                         0x00, 0x4a, 0xf8, 0xff, 0xa4, 0xcb };
1718         }
1719 }