2 // AppDomainTest.cs - NUnit Test Cases for AppDomain
5 // Sebastien Pouliot (sebastien@ximian.com)
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using NUnit.Framework;
31 using System.Collections;
32 using System.Globalization;
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;
41 namespace MonoTests.System
44 public class AppDomainTest
47 private ArrayList files = new ArrayList ();
48 private string tempDir = Path.Combine (Path.GetTempPath (), "MonoTests.System.AppDomainTest");
53 if (!Directory.Exists (tempDir)) {
54 Directory.CreateDirectory (tempDir);
59 public void TearDown ()
63 AppDomain.Unload (ad);
65 } catch { } // do not affect unit test results in TearDown
67 foreach (string fname in files) {
74 public void ConfigurationFile_Relative ()
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)
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
85 string configFile = "test.config";
86 string appBase = null;
87 string expectedConfigFile = null;
88 string expectedAppBase = null;
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);
100 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
101 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
103 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
104 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
106 AppDomain.Unload (ad);
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);
124 public void ConfigurationFile_Absolute ()
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)
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
135 string configFile = Path.Combine (tempDir, "test.config");
136 string appBase = null;
137 string expectedAppBase = null;
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");
149 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
151 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
153 AppDomain.Unload (ad);
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);
170 //[Category ("NotWorking")]
171 public void ConfigurationFile_Null ()
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)
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
182 string appBase = null;
183 string expectedAppBase = null;
184 string expectedConfigFile = null;
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);
196 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
197 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
199 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
200 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
202 AppDomain.Unload (ad);
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);
215 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
217 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#B1");
219 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
220 AppDomain.Unload (ad);
224 public void SetThreadPrincipal ()
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);
233 [ExpectedException (typeof (ArgumentNullException))]
234 public void SetThreadPrincipalNull ()
236 AppDomain.CurrentDomain.SetThreadPrincipal (null);
240 [ExpectedException (typeof (PolicyException))]
241 public void SetThreadPrincipalTwice ()
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);
252 [ExpectedException (typeof (AppDomainUnloadedException))]
253 public void SetThreadPrincipalUnloaded ()
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);
263 public void SetPrincipalPolicy_NoPrincipal ()
265 AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
269 public void SetPrincipalPolicy_UnauthenticatedPrincipal ()
271 AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.UnauthenticatedPrincipal);
275 public void SetPrincipalPolicy_WindowsPrincipal ()
277 AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.WindowsPrincipal);
281 [ExpectedException (typeof (AppDomainUnloadedException))]
282 public void SetPrincipalPolicyUnloaded ()
284 ad = AppDomain.CreateDomain ("Ximian");
285 AppDomain.Unload (ad);
286 ad.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
290 public void CreateDomain_String ()
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");
300 [ExpectedException (typeof (ArgumentNullException))]
301 public void CreateDomain_String_Null ()
303 ad = AppDomain.CreateDomain (null);
307 [Category ("NotDotNet")]
308 public void CreateDomain_StringEvidence ()
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");
315 e.AddHost (new Zone (SecurityZone.MyComputer));
316 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
317 // evidence isn't copied but referenced
321 [ExpectedException (typeof (ArgumentNullException))]
322 public void CreateDomain_StringNullEvidence ()
324 ad = AppDomain.CreateDomain (null, new Evidence ());
328 public void CreateDomain_StringEvidenceNull ()
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
342 [Category ("NotDotNet")]
343 public void CreateDomain_StringEvidenceAppDomainSetup ()
345 Evidence e = new Evidence ();
346 AppDomainSetup info = new AppDomainSetup ();
347 info.ApplicationName = "ApplicationName";
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);
355 e.AddHost (new Zone (SecurityZone.MyComputer));
356 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
357 // evidence isn't copied but referenced
361 [ExpectedException (typeof (ArgumentNullException))]
362 public void CreateDomain_StringNullEvidenceAppDomainSetup ()
364 AppDomainSetup info = new AppDomainSetup ();
365 ad = AppDomain.CreateDomain (null, new Evidence (), info);
369 public void CreateDomain_StringEvidenceNullAppDomainSetup ()
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");
386 [Category ("NotDotNet")]
387 public void CreateDomain_StringEvidenceAppDomainSetupNull ()
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");
398 [Category ("NotWorking")]
399 public void Load_Loaded_Ignore ()
401 int assemblyStartCount = AppDomain.CurrentDomain.GetAssemblies ().Length;
405 string assemblyFile = Path.Combine (tempDir, "bug79720A.dll");
406 AssemblyName aname = new AssemblyName ();
407 aname.Name = "bug79720A";
408 aname.Version = new Version (2, 4);
410 GenerateAssembly (aname, assemblyFile);
412 Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A1");
414 aname = new AssemblyName ();
415 aname.Name = "bug79720A";
417 AppDomain.CurrentDomain.Load (aname);
419 } catch (FileNotFoundException) {
422 aname = new AssemblyName ();
423 aname.Name = "bug79720A";
424 aname.Version = new Version (0, 0, 0, 0);
426 AppDomain.CurrentDomain.Load (aname);
428 } catch (FileNotFoundException) {
431 aname = new AssemblyName ();
432 aname.Name = "bug79720A";
433 aname.Version = new Version (2, 4);
435 AppDomain.CurrentDomain.Load (aname);
437 } catch (FileNotFoundException) {
440 Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A5");
442 Assembly.LoadFrom (assemblyFile);
444 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A6");
446 aname = new AssemblyName ();
447 aname.Name = "bug79720A";
449 AppDomain.CurrentDomain.Load (aname);
451 } catch (FileNotFoundException) {
454 aname = new AssemblyName ();
455 aname.Name = "bug79720A";
456 aname.Version = new Version (0, 0, 0, 0);
458 AppDomain.CurrentDomain.Load (aname);
460 } catch (FileNotFoundException) {
463 aname = new AssemblyName ();
464 aname.Name = "bug79720A";
465 aname.Version = new Version (2, 4);
467 AppDomain.CurrentDomain.Load (aname);
469 } catch (FileNotFoundException) {
472 aname = new AssemblyName ();
473 aname.Name = "bug79720A";
474 aname.Version = new Version (2, 4);
475 aname.CultureInfo = CultureInfo.InvariantCulture;
477 AppDomain.CurrentDomain.Load (aname);
478 Assert.Fail ("#A10");
479 } catch (FileNotFoundException) {
482 aname = new AssemblyName ();
483 aname.Name = "bug79720A";
484 aname.Version = new Version (2, 4, 0, 0);
485 aname.CultureInfo = CultureInfo.InvariantCulture;
487 AppDomain.CurrentDomain.Load (aname);
488 Assert.Fail ("#A11");
489 } catch (FileNotFoundException) {
492 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A12");
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");
502 GenerateAssembly (aname, assemblyFile);
504 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B1");
506 aname = new AssemblyName ();
507 aname.Name = "bug79720B";
509 AppDomain.CurrentDomain.Load (aname);
511 } catch (FileNotFoundException) {
514 aname = new AssemblyName ();
515 aname.Name = "bug79720B";
516 aname.Version = new Version (0, 0, 0, 0);
518 AppDomain.CurrentDomain.Load (aname);
520 } catch (FileNotFoundException) {
523 aname = new AssemblyName ();
524 aname.Name = "bug79720B";
525 aname.Version = new Version (2, 4, 1);
527 AppDomain.CurrentDomain.Load (aname);
529 } catch (FileNotFoundException) {
532 aname = new AssemblyName ();
533 aname.Name = "bug79720B";
534 aname.Version = new Version (2, 4, 1);
535 aname.CultureInfo = new CultureInfo ("nl-BE");
537 AppDomain.CurrentDomain.Load (aname);
539 } catch (FileNotFoundException) {
542 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B6");
544 Assembly.LoadFrom (assemblyFile);
546 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B7");
548 aname = new AssemblyName ();
549 aname.Name = "bug79720B";
551 AppDomain.CurrentDomain.Load (aname);
553 } catch (FileNotFoundException) {
556 aname = new AssemblyName ();
557 aname.Name = "bug79720B";
558 aname.Version = new Version (0, 0, 0, 0);
560 AppDomain.CurrentDomain.Load (aname);
562 } catch (FileNotFoundException) {
565 aname = new AssemblyName ();
566 aname.Name = "bug79720B";
567 aname.Version = new Version (2, 4, 1);
569 AppDomain.CurrentDomain.Load (aname);
570 Assert.Fail ("#B10");
571 } catch (FileNotFoundException) {
574 aname = new AssemblyName ();
575 aname.Name = "bug79720B";
576 aname.Version = new Version (2, 4, 1);
577 aname.CultureInfo = new CultureInfo ("nl-BE");
579 AppDomain.CurrentDomain.Load (aname);
580 Assert.Fail ("#B11");
581 } catch (FileNotFoundException) {
584 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B12");
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);
595 GenerateAssembly (aname, assemblyFile);
597 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C1");
599 aname = new AssemblyName ();
600 aname.Name = "bug79720C";
602 AppDomain.CurrentDomain.Load (aname);
604 } catch (FileNotFoundException) {
607 aname = new AssemblyName ();
608 aname.Name = "bug79720C";
609 aname.Version = new Version (0, 0, 0, 0);
611 AppDomain.CurrentDomain.Load (aname);
613 } catch (FileNotFoundException) {
616 aname = new AssemblyName ();
617 aname.Name = "bug79720C";
618 aname.Version = new Version (2, 4, 1);
620 AppDomain.CurrentDomain.Load (aname);
622 } catch (FileNotFoundException) {
625 aname = new AssemblyName ();
626 aname.Name = "bug79720C";
627 aname.Version = new Version (2, 4, 1);
628 aname.CultureInfo = new CultureInfo ("nl-BE");
630 AppDomain.CurrentDomain.Load (aname);
632 } catch (FileNotFoundException) {
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);
641 AppDomain.CurrentDomain.Load (aname);
643 } catch (FileNotFoundException) {
646 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C7");
648 Assembly.LoadFrom (assemblyFile);
650 Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C8");
652 aname = new AssemblyName ();
653 aname.Name = "bug79720C";
655 AppDomain.CurrentDomain.Load (aname);
657 } catch (FileNotFoundException) {
660 aname = new AssemblyName ();
661 aname.Name = "bug79720C";
662 aname.Version = new Version (0, 0, 0, 0);
664 AppDomain.CurrentDomain.Load (aname);
665 Assert.Fail ("#C10");
666 } catch (FileNotFoundException) {
669 aname = new AssemblyName ();
670 aname.Name = "bug79720C";
671 aname.Version = new Version (2, 4);
673 AppDomain.CurrentDomain.Load (aname);
674 Assert.Fail ("#C11");
675 } catch (FileNotFoundException) {
678 aname = new AssemblyName ();
679 aname.Name = "bug79720C";
680 aname.Version = new Version (2, 4);
681 aname.CultureInfo = new CultureInfo ("nl-BE");
683 AppDomain.CurrentDomain.Load (aname);
684 Assert.Fail ("#C12");
685 } catch (FileNotFoundException) {
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);
694 AppDomain.CurrentDomain.Load (aname);
695 Assert.Fail ("#C13");
696 } catch (FileNotFoundException) {
699 Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C14");
703 [Category ("NotWorking")]
704 public void Load_Loaded_Multiple ()
706 string cultureDir = Path.Combine (tempDir, "nl-BE");
707 if (!Directory.Exists (cultureDir))
708 Directory.CreateDirectory (cultureDir);
710 AppDomain ad = CreateTestDomain (tempDir, true);
712 CrossDomainTester cdt = CreateCrossDomainTester (ad);
714 int assemblyCount = cdt.AssemblyCount;
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"));
723 Assert.AreEqual (assemblyCount + 1, cdt.AssemblyCount, "#A1");
725 aname = new AssemblyName ();
726 aname.Name = "multipleA";
727 Assert.IsTrue (cdt.AssertLoad (aname), "#A2");
729 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A3");
731 aname = new AssemblyName ();
732 aname.Name = "multipleA";
733 Assert.IsTrue (cdt.AssertLoad (aname), "#A4");
735 aname = new AssemblyName ();
736 aname.Name = "multipleA";
737 aname.CultureInfo = CultureInfo.InvariantCulture;
738 Assert.IsTrue (cdt.AssertLoad (aname), "#A5");
740 aname = new AssemblyName ();
741 aname.Name = "multipleA";
742 aname.CultureInfo = CultureInfo.InvariantCulture;
743 Assert.IsTrue (cdt.AssertLoad (aname), "#A6");
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");
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");
757 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A9");
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"));
767 Assert.AreEqual (assemblyCount + 3, cdt.AssemblyCount, "#B1");
769 aname = new AssemblyName ();
770 aname.Name = "multipleB";
771 Assert.IsTrue (cdt.AssertLoad (aname), "#B2");
773 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B3");
775 aname = new AssemblyName ();
776 aname.Name = "multipleB";
777 Assert.IsTrue (cdt.AssertLoad (aname), "#B4");
779 aname = new AssemblyName ();
780 aname.Name = "multipleB";
781 aname.CultureInfo = new CultureInfo ("nl-BE");
782 Assert.IsTrue (cdt.AssertLoad (aname), "#B5");
784 aname = new AssemblyName ();
785 aname.Name = "multipleB";
786 aname.CultureInfo = new CultureInfo ("nl-BE");
787 Assert.IsTrue (cdt.AssertLoad (aname), "#B6");
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");
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");
801 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B9");
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"));
812 Assert.AreEqual (assemblyCount + 5, cdt.AssemblyCount, "#C1");
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");
821 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C3");
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");
830 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C5");
832 AppDomain.Unload (ad);
837 [Category ("NotWorking")]
838 public void Load_Manifest_Mismatch ()
840 string assemblyFile = Path.Combine (tempDir, "bug79522A.dll");
841 AssemblyName aname = new AssemblyName ();
842 aname.Name = "bug79522A";
843 aname.Version = new Version (2, 4);
845 GenerateAssembly (aname, assemblyFile);
847 aname = new AssemblyName ();
848 aname.CodeBase = assemblyFile;
849 aname.Name = "whateveryouwant";
850 aname.Version = new Version (1, 1);
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
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
860 AppDomain.CurrentDomain.Load (aname);
862 } catch (FileLoadException) {
865 // if we set CodeBase to some garbage, then we'll get a
866 // FileNotFoundException instead
867 aname.CodeBase = "whatever";
869 AppDomain.CurrentDomain.Load (aname);
871 } catch (FileNotFoundException) {
874 aname = new AssemblyName ();
875 aname.Name = "bug79522A";
876 aname.CodeBase = assemblyFile;
878 AppDomain.CurrentDomain.Load (aname);
881 AppDomain.CurrentDomain.Load (aname);
883 } catch (FileLoadException) {
887 aname = new AssemblyName ();
888 aname.Name = "bug79522A";
889 aname.CodeBase = assemblyFile;
890 aname.Version = new Version (2, 5);
892 // the version number is not considered when comparing the manifest
893 // of the assembly found using codebase
894 AppDomain.CurrentDomain.Load (aname);
897 AppDomain.CurrentDomain.Load (aname);
899 } catch (FileLoadException) {
903 aname = new AssemblyName ();
904 aname.Name = "bug79522A";
905 aname.CodeBase = assemblyFile;
906 aname.Version = new Version (2, 4, 1);
908 // the version number is not considered when comparing the manifest
909 // of the assembly found using codebase
910 AppDomain.CurrentDomain.Load (aname);
913 AppDomain.CurrentDomain.Load (aname);
915 } catch (FileLoadException) {
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);
925 AppDomain.CurrentDomain.Load (aname);
928 AppDomain.CurrentDomain.Load (aname);
930 } catch (FileLoadException) {
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);
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);
949 // if both culture and version are set, then the version diff
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);
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);
966 AppDomain.CurrentDomain.Load (aname);
968 } catch (FileLoadException) {
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");
978 AppDomain.CurrentDomain.Load (aname);
980 } catch (FileLoadException) {
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);
991 GenerateAssembly (aname, assemblyFile);
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);
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
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
1007 AppDomain.CurrentDomain.Load (aname);
1008 Assert.Fail ("#B1");
1009 } catch (FileLoadException) {
1012 // if we set CodeBase to some garbage, then we'll get a
1013 // FileNotFoundException instead
1014 aname.CodeBase = "whatever";
1016 AppDomain.CurrentDomain.Load (aname);
1017 Assert.Fail ("#B2");
1018 } catch (FileNotFoundException) {
1021 aname = new AssemblyName ();
1022 aname.Name = "bug79522B";
1023 aname.CodeBase = assemblyFile;
1025 // the version number is not considered when comparing the manifest
1026 // of the assembly found using codebase
1027 AppDomain.CurrentDomain.Load (aname);
1030 AppDomain.CurrentDomain.Load (aname);
1031 Assert.Fail ("#B3");
1032 } catch (FileLoadException) {
1036 aname = new AssemblyName ();
1037 aname.Name = "bug79522B";
1038 aname.CodeBase = assemblyFile;
1039 aname.Version = new Version (5, 5);
1041 // the version number is not considered when comparing the manifest
1042 // of the assembly found using codebase
1043 AppDomain.CurrentDomain.Load (aname);
1046 AppDomain.CurrentDomain.Load (aname);
1047 Assert.Fail ("#B3");
1048 } catch (FileLoadException) {
1052 aname = new AssemblyName ();
1053 aname.Name = "bug79522B";
1054 aname.CodeBase = assemblyFile;
1055 aname.Version = new Version (2, 4, 1);
1057 AppDomain.CurrentDomain.Load (aname);
1059 // when the loaded assembly has a specific culture, then that
1060 // culture must be set if you set the Version on the aname
1062 AppDomain.CurrentDomain.Load (aname);
1063 Assert.Fail ("#B4");
1064 } catch (FileLoadException) {
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);
1075 // if both culture and version are set, then the version diff
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);
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);
1091 AppDomain.CurrentDomain.Load (aname);
1092 Assert.Fail ("#B5");
1093 } catch (FileLoadException) {
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");
1103 AppDomain.CurrentDomain.Load (aname);
1104 Assert.Fail ("#B6");
1105 } catch (FileLoadException) {
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);
1117 GenerateAssembly (aname, assemblyFile);
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);
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
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
1134 AppDomain.CurrentDomain.Load (aname);
1135 Assert.Fail ("#C1");
1136 } catch (FileLoadException) {
1139 // if we set CodeBase to some garbage, then we'll get a
1140 // FileNotFoundException instead
1141 aname.CodeBase = "whatever";
1143 AppDomain.CurrentDomain.Load (aname);
1144 Assert.Fail ("#C2");
1145 } catch (FileNotFoundException) {
1148 aname = new AssemblyName ();
1149 aname.Name = "bug79522C";
1150 aname.CodeBase = assemblyFile;
1152 AppDomain.CurrentDomain.Load (aname);
1155 AppDomain.CurrentDomain.Load (aname);
1156 Assert.Fail ("#C3");
1157 } catch (FileLoadException) {
1161 aname = new AssemblyName ();
1162 aname.Name = "bug79522C";
1163 aname.CodeBase = assemblyFile;
1164 aname.Version = new Version (5, 5);
1166 AppDomain.CurrentDomain.Load (aname);
1167 Assert.Fail ("#C3");
1168 } catch (FileLoadException) {
1171 aname = new AssemblyName ();
1172 aname.Name = "bug79522C";
1173 aname.CodeBase = assemblyFile;
1174 aname.Version = new Version (2, 4);
1176 AppDomain.CurrentDomain.Load (aname);
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
1182 AppDomain.CurrentDomain.Load (aname);
1183 Assert.Fail ("#C4");
1184 } catch (FileLoadException) {
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);
1194 AppDomain.CurrentDomain.Load (aname);
1196 // if loaded assembly is signed, then the public key must be set
1198 AppDomain.CurrentDomain.Load (aname);
1199 Assert.Fail ("#C5");
1200 } catch (FileLoadException) {
1204 aname = new AssemblyName ();
1205 aname.Name = "bug79522C";
1206 aname.CodeBase = assemblyFile;
1207 aname.CultureInfo = new CultureInfo ("nl-BE");
1208 aname.SetPublicKey (publicKey);
1210 AppDomain.CurrentDomain.Load (aname);
1212 // if public key is set, then version must be set
1214 AppDomain.CurrentDomain.Load (aname);
1215 Assert.Fail ("#C6");
1216 } catch (FileLoadException) {
1220 aname = new AssemblyName ();
1221 aname.Name = "bug79522C";
1222 aname.CodeBase = assemblyFile;
1223 aname.CultureInfo = new CultureInfo ("nl-BE");
1225 AppDomain.CurrentDomain.Load (aname);
1228 AppDomain.CurrentDomain.Load (aname);
1229 Assert.Fail ("#C7");
1230 } catch (FileLoadException) {
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);
1242 AppDomain.CurrentDomain.Load (aname);
1243 Assert.Fail ("#C8");
1244 } catch (FileLoadException) {
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);
1255 AppDomain.CurrentDomain.Load (aname);
1256 Assert.Fail ("#C9");
1258 } catch (SecurityException) {
1259 // Invalid assembly public key
1262 } catch (FileLoadException) {
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);
1275 [Test] // bug #79715
1276 public void Load_PartialVersion ()
1278 AppDomain ad = CreateTestDomain (tempDir, true);
1280 CrossDomainTester cdt = CreateCrossDomainTester (ad);
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"));
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");
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");
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");
1305 AppDomain.Unload (ad);
1310 public void SetAppDomainPolicy ()
1312 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
1313 ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
1318 [ExpectedException (typeof (ArgumentNullException))]
1319 public void SetAppDomainPolicy_Null ()
1321 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
1322 ad.SetAppDomainPolicy (null);
1326 [ExpectedException (typeof (PolicyException))]
1327 public void SetAppDomainPolicy_Dual ()
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);
1336 pl = PolicyLevel.CreateAppDomainLevel ();
1337 ps = new PermissionSet (PermissionState.None);
1338 pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
1339 ad.SetAppDomainPolicy (pl);
1343 [ExpectedException (typeof (AppDomainUnloadedException))]
1344 public void SetAppDomainPolicy_Unloaded ()
1346 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Unloaded");
1347 AppDomain.Unload (ad);
1348 ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
1352 [ExpectedException (typeof (ArgumentNullException))]
1353 public void GetData_Null ()
1355 AppDomain.CurrentDomain.GetData (null);
1359 public void SetData ()
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");
1368 [ExpectedException (typeof (ArgumentNullException))]
1369 public void SetData_Null ()
1371 AppDomain.CurrentDomain.SetData (null, "data");
1376 public void ApplyPolicy ()
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");
1387 [ExpectedException (typeof (ArgumentException))]
1388 public void ApplyPolicy_Empty ()
1390 ad = AppDomain.CreateDomain ("ApplyPolicy_Empty");
1391 ad.ApplyPolicy (String.Empty);
1395 [ExpectedException (typeof (ArgumentNullException))]
1396 public void ApplyPolicy_Null ()
1398 ad = AppDomain.CreateDomain ("ApplyPolicy_Null");
1399 ad.ApplyPolicy (null);
1403 public void DomainManager ()
1405 Assert.IsNull (AppDomain.CurrentDomain.DomainManager, "CurrentDomain.DomainManager");
1406 ad = AppDomain.CreateDomain ("DomainManager");
1407 Assert.IsNull (ad.DomainManager, "ad.DomainManager");
1411 public void IsDefaultAppDomain ()
1413 ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
1414 Assert.IsFalse (ad.IsDefaultAppDomain (), "IsDefaultAppDomain");
1415 // we have no public way to get the default appdomain
1419 public void ReflectionOnlyGetAssemblies ()
1421 ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
1422 Assembly [] a = ad.ReflectionOnlyGetAssemblies ();
1423 Assert.IsNotNull (a, "ReflectionOnlyGetAssemblies");
1424 Assert.AreEqual (0, a.Length, "Count");
1428 private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
1430 AppDomainSetup setup = new AppDomainSetup ();
1431 setup.ApplicationBase = baseDirectory;
1432 setup.ApplicationName = "testdomain";
1433 return CreateTestDomain (setup, assemblyResolver);
1436 private static AppDomain CreateTestDomain (AppDomainSetup setup, bool assemblyResolver)
1438 AppDomain ad = AppDomain.CreateDomain ("testdomain",
1439 AppDomain.CurrentDomain.Evidence, setup);
1441 if (assemblyResolver) {
1442 Assembly ea = Assembly.GetExecutingAssembly ();
1443 ad.CreateInstanceFrom (ea.CodeBase,
1444 typeof (AssemblyResolveHandler).FullName,
1446 BindingFlags.Public | BindingFlags.Instance,
1448 new object [] { ea.Location, ea.FullName },
1449 CultureInfo.InvariantCulture,
1458 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
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);
1467 private static void GenerateAssembly (AssemblyName aname, string path)
1469 AppDomain ad = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory,
1472 CrossDomainTester cdt = CreateCrossDomainTester (ad);
1473 cdt.GenerateAssembly (aname, path);
1475 AppDomain.Unload (ad);
1479 private bool RunningOnUnix {
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));
1488 private class CrossDomainTester : MarshalByRefObject
1490 public void GenerateAssembly (AssemblyName aname, string path)
1492 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1493 aname, AssemblyBuilderAccess.Save, Path.GetDirectoryName (path));
1494 ab.Save (Path.GetFileName (path));
1497 public int AssemblyCount {
1499 return AppDomain.CurrentDomain.GetAssemblies ().Length;
1503 public string GetApplicationBase ()
1505 return AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
1508 public string GetConfigurationFile ()
1510 return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
1513 public void Load (AssemblyName assemblyRef)
1515 AppDomain.CurrentDomain.Load (assemblyRef);
1518 public void LoadFrom (string assemblyFile)
1520 Assembly.LoadFrom (assemblyFile);
1523 public bool AssertLoad (AssemblyName assemblyRef)
1526 AppDomain.CurrentDomain.Load (assemblyRef);
1533 public bool AssertLoad (string assemblyString)
1536 AppDomain.CurrentDomain.Load (assemblyString);
1543 public bool AssertFileLoadException (AssemblyName assemblyRef)
1546 AppDomain.CurrentDomain.Load (assemblyRef);
1548 } catch (FileLoadException) {
1553 public bool AssertFileNotFoundException (AssemblyName assemblyRef)
1556 AppDomain.CurrentDomain.Load (assemblyRef);
1558 } catch (FileNotFoundException) {
1565 private class AssemblyResolveHandler
1567 public AssemblyResolveHandler (string assemblyFile, string assemblyName)
1569 _assemblyFile = assemblyFile;
1570 _assemblyName = assemblyName;
1572 AppDomain.CurrentDomain.AssemblyResolve +=
1573 new ResolveEventHandler (ResolveAssembly);
1576 private Assembly ResolveAssembly (Object sender, ResolveEventArgs args)
1578 if (args.Name == _assemblyName)
1579 return Assembly.LoadFrom (_assemblyFile);
1584 private readonly string _assemblyFile;
1585 private readonly string _assemblyName;
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, 0xD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A0, 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,
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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F5, 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,
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 };