2 // AppDomainTest.cs - NUnit Test Cases for AppDomain
5 // Sebastien Pouliot (sebastien@ximian.com)
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
8 // Copyright 2011 Xamarin Inc (http://www.xamarin.com).
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using NUnit.Framework;
34 using System.Collections;
35 using System.Collections.Generic;
36 using System.Configuration.Assemblies;
37 using System.Globalization;
39 using System.Reflection;
40 using System.Reflection.Emit;
41 using System.Runtime.InteropServices;
42 using System.Security;
43 using System.Security.Permissions;
44 using System.Security.Policy;
45 using System.Security.Principal;
47 namespace MonoTests.System
50 public class AppDomainTest
53 private ArrayList files = new ArrayList ();
54 private string tempDir;
59 tempDir = Path.Combine (Path.GetTempPath (), Environment.UserName);
60 tempDir = Path.Combine (tempDir, "MonoTests.System.AppDomainTest");
61 if (!Directory.Exists (tempDir)) {
62 Directory.CreateDirectory (tempDir);
67 public void TearDown ()
71 AppDomain.Unload (ad);
73 } catch { } // do not affect unit test results in TearDown
75 foreach (string fname in files) {
82 public void ConfigurationFile_Relative ()
85 // We use Environment.GetCommandLineArgs () to get the location of
86 // the entry assembly in the default domain (since the default domain
87 // is not exposed by any API)
89 // MS returns a lower-case path in Environment.GetCommandLineArgs ()
90 // and hence we need to perform a case-insensitive comparison
91 // if the Assert involves that path
93 string configFile = "test.config";
94 string appBase = null;
95 string expectedConfigFile = null;
96 string expectedAppBase = null;
98 // do not set ApplicationBase
99 appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
100 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
101 appBase : appBase + Path.DirectorySeparatorChar;
102 expectedConfigFile = Path.Combine (appBase, configFile);
103 AppDomainSetup setup = new AppDomainSetup();
104 setup.ConfigurationFile = configFile;
105 ad = CreateTestDomain (setup, true);
106 CrossDomainTester cdt = CreateCrossDomainTester (ad);
108 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
109 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
111 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
112 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
114 AppDomain.Unload (ad);
116 // set ApplicationBase
117 appBase = Path.GetTempPath ();
118 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
119 appBase : appBase + Path.DirectorySeparatorChar;
120 expectedConfigFile = Path.Combine (appBase, configFile);
121 setup = new AppDomainSetup ();
122 setup.ApplicationBase = appBase;
123 setup.ConfigurationFile = configFile;
124 ad = CreateTestDomain (setup, true);
125 cdt = CreateCrossDomainTester (ad);
126 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
127 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
128 AppDomain.Unload (ad);
132 public void ConfigurationFile_Absolute ()
135 // We use Environment.GetCommandLineArgs () to get the location of
136 // the entry assembly in the default domain (since the default domain
137 // is not exposed by any API)
139 // MS returns a lower-case path in Environment.GetCommandLineArgs ()
140 // and hence on Windows we need to perform a case-insensitive
141 // comparison if the Assert involves that path
143 string configFile = Path.Combine (tempDir, "test.config");
144 string appBase = null;
145 string expectedAppBase = null;
147 // do not set ApplicationBase
148 appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
149 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
150 appBase : appBase + Path.DirectorySeparatorChar;
151 AppDomainSetup setup = new AppDomainSetup ();
152 setup.ConfigurationFile = configFile;
153 ad = CreateTestDomain (setup, true);
154 CrossDomainTester cdt = CreateCrossDomainTester (ad);
155 Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#A1");
157 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
159 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
161 AppDomain.Unload (ad);
163 // set ApplicationBase
164 appBase = Path.GetTempPath ();
165 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
166 appBase : appBase + Path.DirectorySeparatorChar;
167 setup = new AppDomainSetup ();
168 setup.ApplicationBase = appBase;
169 setup.ConfigurationFile = configFile;
170 ad = CreateTestDomain (setup, true);
171 cdt = CreateCrossDomainTester (ad);
172 Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#B1");
173 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
174 AppDomain.Unload (ad);
178 public void ConfigurationFile_Null ()
181 // We use Environment.GetCommandLineArgs () to get the location of
182 // the entry assembly in the default domain (since the default domain
183 // is not exposed by any API)
185 // MS returns a lower-case path in Environment.GetCommandLineArgs ()
186 // and hence we need to perform a case-insensitive comparison
187 // if the Assert involves that path
189 string appBase = null;
190 string expectedAppBase = null;
191 string expectedConfigFile = null;
193 // do not set ApplicationBase
194 appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
195 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
196 appBase : appBase + Path.DirectorySeparatorChar;
197 expectedConfigFile = Environment.GetCommandLineArgs () [0] + ".config";
198 AppDomainSetup setup = new AppDomainSetup ();
199 setup.ConfigurationFile = null;
200 ad = CreateTestDomain (setup, true);
201 CrossDomainTester cdt = CreateCrossDomainTester (ad);
203 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
204 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
206 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
207 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
209 AppDomain.Unload (ad);
211 // set ApplicationBase
212 appBase = Path.GetTempPath ();
213 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
214 appBase : appBase + Path.DirectorySeparatorChar;
215 expectedConfigFile = Path.Combine (appBase, Path.GetFileName (Environment.GetCommandLineArgs () [0]) + ".config");
216 setup = new AppDomainSetup ();
217 setup.ApplicationBase = appBase;
218 setup.ConfigurationFile = null;
219 ad = CreateTestDomain (setup, true);
220 cdt = CreateCrossDomainTester (ad);
222 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
224 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#B1");
226 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
227 AppDomain.Unload (ad);
230 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
231 public void DefineDynamicAssembly1_Access_Invalid ()
233 AssemblyName name = new AssemblyName ();
234 name.Name = "DefineDynamicAssembly1";
237 AppDomain.CurrentDomain.DefineDynamicAssembly (
238 name, AssemblyBuilderAccess.Run |
239 (AssemblyBuilderAccess) 666);
241 } catch (ArgumentException ex) {
242 // Illegal enum value: 667
243 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
244 Assert.IsNull (ex.InnerException, "#3");
245 Assert.IsNotNull (ex.Message, "#4");
246 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
247 Assert.IsNotNull (ex.ParamName, "#6");
248 Assert.AreEqual ("access", ex.ParamName, "#7");
252 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
253 public void DefineDynamicAssembly1_Name_InvalidChars ()
255 string [] invalid_char_names = new string [] {
265 AssemblyName name = new AssemblyName ();
267 foreach (string invalid_name in invalid_char_names) {
268 name.Name = invalid_name;
270 AppDomain.CurrentDomain.DefineDynamicAssembly (
272 AssemblyBuilderAccess.Run);
273 Assert.Fail ("#1:" + invalid_name);
274 } catch (ArgumentException ex) {
275 // Assembly names may not begin with whitespace
276 // or contain the characters '/', '\' or ':'
277 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
278 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
279 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
280 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
281 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
282 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
283 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
288 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
289 public void DefineDynamicAssembly1_Name_Null ()
292 AppDomain.CurrentDomain.DefineDynamicAssembly (
294 AssemblyBuilderAccess.Run);
296 } catch (ArgumentNullException ex) {
297 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
298 Assert.IsNull (ex.InnerException, "#A3");
299 Assert.IsNotNull (ex.Message, "#A4");
300 Assert.IsNotNull (ex.ParamName, "#A5");
301 Assert.AreEqual ("name", ex.ParamName, "#A6");
304 AssemblyName name = new AssemblyName ();
307 AppDomain.CurrentDomain.DefineDynamicAssembly (
309 AssemblyBuilderAccess.Run);
311 } catch (ArgumentException ex) {
312 // AssemblyName.Name cannot be null or an empty string
313 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
314 Assert.IsNull (ex.InnerException, "#B3");
315 Assert.IsNotNull (ex.Message, "#B4");
316 Assert.IsNull (ex.ParamName, "#B5");
319 name.Name = string.Empty;
322 AppDomain.CurrentDomain.DefineDynamicAssembly (
324 AssemblyBuilderAccess.Run);
326 } catch (ArgumentException ex) {
327 // AssemblyName.Name cannot be null or an empty string
328 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
329 Assert.IsNull (ex.InnerException, "#C3");
330 Assert.IsNotNull (ex.Message, "#C4");
331 Assert.IsNull (ex.ParamName, "#C5");
335 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
336 public void DefineDynamicAssembly2_Access_Invalid ()
338 AssemblyName name = new AssemblyName ();
339 name.Name = "DefineDynamicAssembly2";
343 AppDomain.CurrentDomain.DefineDynamicAssembly (
344 name, AssemblyBuilderAccess.Run |
345 (AssemblyBuilderAccess) 666,
346 AppDomain.CurrentDomain.Evidence);
348 } catch (ArgumentException ex) {
349 // Illegal enum value: 667
350 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
351 Assert.IsNull (ex.InnerException, "#3");
352 Assert.IsNotNull (ex.Message, "#4");
353 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
354 Assert.IsNotNull (ex.ParamName, "#6");
355 Assert.AreEqual ("access", ex.ParamName, "#7");
358 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
359 name, AssemblyBuilderAccess.Run |
360 (AssemblyBuilderAccess) 666,
361 AppDomain.CurrentDomain.Evidence);
362 Assert.IsNotNull (ab, "#1");
366 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
367 public void DefineDynamicAssembly2_Name_InvalidChars ()
369 string [] invalid_char_names = new string [] {
379 AssemblyName name = new AssemblyName ();
381 foreach (string invalid_name in invalid_char_names) {
382 name.Name = invalid_name;
384 AppDomain.CurrentDomain.DefineDynamicAssembly (
386 AssemblyBuilderAccess.Run,
387 AppDomain.CurrentDomain.Evidence);
388 Assert.Fail ("#1:" + invalid_name);
389 } catch (ArgumentException ex) {
390 // Assembly names may not begin with whitespace
391 // or contain the characters '/', '\' or ':'
392 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
393 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
394 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
395 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
396 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
397 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
398 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
403 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
404 public void DefineDynamicAssembly2_Name_Null ()
407 AppDomain.CurrentDomain.DefineDynamicAssembly (
409 AssemblyBuilderAccess.Run,
410 AppDomain.CurrentDomain.Evidence);
412 } catch (ArgumentNullException ex) {
413 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
414 Assert.IsNull (ex.InnerException, "#A3");
415 Assert.IsNotNull (ex.Message, "#A4");
416 Assert.IsNotNull (ex.ParamName, "#A5");
417 Assert.AreEqual ("name", ex.ParamName, "#A6");
420 AssemblyName name = new AssemblyName ();
423 AppDomain.CurrentDomain.DefineDynamicAssembly (
425 AssemblyBuilderAccess.Run,
426 AppDomain.CurrentDomain.Evidence);
428 } catch (ArgumentException ex) {
429 // AssemblyName.Name cannot be null or an empty string
430 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
431 Assert.IsNull (ex.InnerException, "#B3");
432 Assert.IsNotNull (ex.Message, "#B4");
433 Assert.IsNull (ex.ParamName, "#B5");
436 name.Name = string.Empty;
439 AppDomain.CurrentDomain.DefineDynamicAssembly (
441 AssemblyBuilderAccess.Run,
442 AppDomain.CurrentDomain.Evidence);
444 } catch (ArgumentException ex) {
445 // AssemblyName.Name cannot be null or an empty string
446 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
447 Assert.IsNull (ex.InnerException, "#C3");
448 Assert.IsNotNull (ex.Message, "#C4");
449 Assert.IsNull (ex.ParamName, "#C5");
453 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
454 public void DefineDynamicAssembly3_Access_Invalid ()
456 AssemblyName name = new AssemblyName ();
457 name.Name = "DefineDynamicAssembly3";
461 AppDomain.CurrentDomain.DefineDynamicAssembly (
462 name, AssemblyBuilderAccess.Run |
463 (AssemblyBuilderAccess) 666,
464 Path.GetTempPath ());
466 } catch (ArgumentException ex) {
467 // Illegal enum value: 667
468 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
469 Assert.IsNull (ex.InnerException, "#3");
470 Assert.IsNotNull (ex.Message, "#4");
471 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
472 Assert.IsNotNull (ex.ParamName, "#6");
473 Assert.AreEqual ("access", ex.ParamName, "#7");
476 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
477 name, AssemblyBuilderAccess.Run |
478 (AssemblyBuilderAccess) 666,
479 Path.GetTempPath ());
480 Assert.IsNotNull (ab, "#1");
484 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
485 public void DefineDynamicAssembly3_Name_InvalidChars ()
487 string [] invalid_char_names = new string [] {
497 AssemblyName name = new AssemblyName ();
499 foreach (string invalid_name in invalid_char_names) {
500 name.Name = invalid_name;
502 AppDomain.CurrentDomain.DefineDynamicAssembly (
504 AssemblyBuilderAccess.Run,
505 Path.GetTempPath ());
506 Assert.Fail ("#1:" + invalid_name);
507 } catch (ArgumentException ex) {
508 // Assembly names may not begin with whitespace
509 // or contain the characters '/', '\' or ':'
510 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
511 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
512 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
513 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
514 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
515 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
516 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
521 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
522 public void DefineDynamicAssembly3_Name_Null ()
525 AppDomain.CurrentDomain.DefineDynamicAssembly (
527 AssemblyBuilderAccess.Run,
528 Path.GetTempPath ());
530 } catch (ArgumentNullException ex) {
531 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
532 Assert.IsNull (ex.InnerException, "#A3");
533 Assert.IsNotNull (ex.Message, "#A4");
534 Assert.IsNotNull (ex.ParamName, "#A5");
535 Assert.AreEqual ("name", ex.ParamName, "#A6");
538 AssemblyName name = new AssemblyName ();
541 AppDomain.CurrentDomain.DefineDynamicAssembly (
543 AssemblyBuilderAccess.Run,
544 Path.GetTempPath ());
546 } catch (ArgumentException ex) {
547 // AssemblyName.Name cannot be null or an empty string
548 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
549 Assert.IsNull (ex.InnerException, "#B3");
550 Assert.IsNotNull (ex.Message, "#B4");
551 Assert.IsNull (ex.ParamName, "#B5");
554 name.Name = string.Empty;
557 AppDomain.CurrentDomain.DefineDynamicAssembly (
559 AssemblyBuilderAccess.Run,
560 Path.GetTempPath ());
562 } catch (ArgumentException ex) {
563 // AssemblyName.Name cannot be null or an empty string
564 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
565 Assert.IsNull (ex.InnerException, "#C3");
566 Assert.IsNotNull (ex.Message, "#C4");
567 Assert.IsNull (ex.ParamName, "#C5");
571 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
572 public void DefineDynamicAssembly4_Access_Invalid ()
574 AssemblyName name = new AssemblyName ();
575 name.Name = "DefineDynamicAssembly4";
579 AppDomain.CurrentDomain.DefineDynamicAssembly (
580 name, AssemblyBuilderAccess.Run |
581 (AssemblyBuilderAccess) 666,
583 AppDomain.CurrentDomain.Evidence);
585 } catch (ArgumentException ex) {
586 // Illegal enum value: 667
587 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
588 Assert.IsNull (ex.InnerException, "#3");
589 Assert.IsNotNull (ex.Message, "#4");
590 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
591 Assert.IsNotNull (ex.ParamName, "#6");
592 Assert.AreEqual ("access", ex.ParamName, "#7");
595 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
596 name, AssemblyBuilderAccess.Run |
597 (AssemblyBuilderAccess) 666,
599 AppDomain.CurrentDomain.Evidence);
600 Assert.IsNotNull (ab, "#1");
604 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
605 public void DefineDynamicAssembly4_Name_InvalidChars ()
607 string [] invalid_char_names = new string [] {
617 AssemblyName name = new AssemblyName ();
619 foreach (string invalid_name in invalid_char_names) {
620 name.Name = invalid_name;
622 AppDomain.CurrentDomain.DefineDynamicAssembly (
624 AssemblyBuilderAccess.Run,
626 AppDomain.CurrentDomain.Evidence);
627 Assert.Fail ("#1:" + invalid_name);
628 } catch (ArgumentException ex) {
629 // Assembly names may not begin with whitespace
630 // or contain the characters '/', '\' or ':'
631 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
632 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
633 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
634 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
635 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
636 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
637 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
642 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
643 public void DefineDynamicAssembly4_Name_Null ()
646 AppDomain.CurrentDomain.DefineDynamicAssembly (
648 AssemblyBuilderAccess.Run,
650 AppDomain.CurrentDomain.Evidence);
652 } catch (ArgumentNullException ex) {
653 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
654 Assert.IsNull (ex.InnerException, "#A3");
655 Assert.IsNotNull (ex.Message, "#A4");
656 Assert.IsNotNull (ex.ParamName, "#A5");
657 Assert.AreEqual ("name", ex.ParamName, "#A6");
660 AssemblyName name = new AssemblyName ();
663 AppDomain.CurrentDomain.DefineDynamicAssembly (
665 AssemblyBuilderAccess.Run,
667 AppDomain.CurrentDomain.Evidence);
669 } catch (ArgumentException ex) {
670 // AssemblyName.Name cannot be null or an empty string
671 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
672 Assert.IsNull (ex.InnerException, "#B3");
673 Assert.IsNotNull (ex.Message, "#B4");
674 Assert.IsNull (ex.ParamName, "#B5");
677 name.Name = string.Empty;
680 AppDomain.CurrentDomain.DefineDynamicAssembly (
682 AssemblyBuilderAccess.Run,
684 AppDomain.CurrentDomain.Evidence);
686 } catch (ArgumentException ex) {
687 // AssemblyName.Name cannot be null or an empty string
688 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
689 Assert.IsNull (ex.InnerException, "#C3");
690 Assert.IsNotNull (ex.Message, "#C4");
691 Assert.IsNull (ex.ParamName, "#C5");
695 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
696 public void DefineDynamicAssembly5_Access_Invalid ()
698 AssemblyName name = new AssemblyName ();
699 name.Name = "DefineDynamicAssembly5";
703 AppDomain.CurrentDomain.DefineDynamicAssembly (
704 name, AssemblyBuilderAccess.Run |
705 (AssemblyBuilderAccess) 666,
706 (PermissionSet) null,
707 (PermissionSet) null,
708 (PermissionSet) null);
710 } catch (ArgumentException ex) {
711 // Illegal enum value: 667
712 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
713 Assert.IsNull (ex.InnerException, "#3");
714 Assert.IsNotNull (ex.Message, "#4");
715 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
716 Assert.IsNotNull (ex.ParamName, "#6");
717 Assert.AreEqual ("access", ex.ParamName, "#7");
720 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
721 name, AssemblyBuilderAccess.Run |
722 (AssemblyBuilderAccess) 666,
723 (PermissionSet) null,
724 (PermissionSet) null,
725 (PermissionSet) null);
726 Assert.IsNotNull (ab, "#1");
730 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
731 public void DefineDynamicAssembly5_Name_InvalidChars ()
733 string [] invalid_char_names = new string [] {
743 AssemblyName name = new AssemblyName ();
745 foreach (string invalid_name in invalid_char_names) {
746 name.Name = invalid_name;
748 AppDomain.CurrentDomain.DefineDynamicAssembly (
750 AssemblyBuilderAccess.Run,
751 (PermissionSet) null,
752 (PermissionSet) null,
753 (PermissionSet) null);
754 Assert.Fail ("#1:" + invalid_name);
755 } catch (ArgumentException ex) {
756 // Assembly names may not begin with whitespace
757 // or contain the characters '/', '\' or ':'
758 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
759 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
760 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
761 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
762 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
763 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
764 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
769 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
770 public void DefineDynamicAssembly5_Name_Null ()
773 AppDomain.CurrentDomain.DefineDynamicAssembly (
775 AssemblyBuilderAccess.Run,
776 (PermissionSet) null,
777 (PermissionSet) null,
778 (PermissionSet) null);
780 } catch (ArgumentNullException ex) {
781 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
782 Assert.IsNull (ex.InnerException, "#A3");
783 Assert.IsNotNull (ex.Message, "#A4");
784 Assert.IsNotNull (ex.ParamName, "#A5");
785 Assert.AreEqual ("name", ex.ParamName, "#A6");
788 AssemblyName name = new AssemblyName ();
791 AppDomain.CurrentDomain.DefineDynamicAssembly (
793 AssemblyBuilderAccess.Run,
794 (PermissionSet) null,
795 (PermissionSet) null,
796 (PermissionSet) null);
798 } catch (ArgumentException ex) {
799 // AssemblyName.Name cannot be null or an empty string
800 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
801 Assert.IsNull (ex.InnerException, "#B3");
802 Assert.IsNotNull (ex.Message, "#B4");
803 Assert.IsNull (ex.ParamName, "#B5");
806 name.Name = string.Empty;
809 AppDomain.CurrentDomain.DefineDynamicAssembly (
811 AssemblyBuilderAccess.Run,
812 (PermissionSet) null,
813 (PermissionSet) null,
814 (PermissionSet) null);
816 } catch (ArgumentException ex) {
817 // AssemblyName.Name cannot be null or an empty string
818 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
819 Assert.IsNull (ex.InnerException, "#C3");
820 Assert.IsNotNull (ex.Message, "#C4");
821 Assert.IsNull (ex.ParamName, "#C5");
825 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
826 public void DefineDynamicAssembly6_Access_Invalid ()
828 AssemblyName name = new AssemblyName ();
829 name.Name = "DefineDynamicAssembly6";
833 AppDomain.CurrentDomain.DefineDynamicAssembly (
834 name, AssemblyBuilderAccess.Run |
835 (AssemblyBuilderAccess) 666,
836 AppDomain.CurrentDomain.Evidence,
837 (PermissionSet) null,
838 (PermissionSet) null,
839 (PermissionSet) null);
841 } catch (ArgumentException ex) {
842 // Illegal enum value: 667
843 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
844 Assert.IsNull (ex.InnerException, "#3");
845 Assert.IsNotNull (ex.Message, "#4");
846 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
847 Assert.IsNotNull (ex.ParamName, "#6");
848 Assert.AreEqual ("access", ex.ParamName, "#7");
851 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
852 name, AssemblyBuilderAccess.Run |
853 (AssemblyBuilderAccess) 666,
854 AppDomain.CurrentDomain.Evidence,
855 (PermissionSet) null,
856 (PermissionSet) null,
857 (PermissionSet) null);
858 Assert.IsNotNull (ab, "#1");
862 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
863 public void DefineDynamicAssembly6_Name_InvalidChars ()
865 string [] invalid_char_names = new string [] {
875 AssemblyName name = new AssemblyName ();
877 foreach (string invalid_name in invalid_char_names) {
878 name.Name = invalid_name;
880 AppDomain.CurrentDomain.DefineDynamicAssembly (
882 AssemblyBuilderAccess.Run,
883 AppDomain.CurrentDomain.Evidence,
884 (PermissionSet) null,
885 (PermissionSet) null,
886 (PermissionSet) null);
887 Assert.Fail ("#1:" + invalid_name);
888 } catch (ArgumentException ex) {
889 // Assembly names may not begin with whitespace
890 // or contain the characters '/', '\' or ':'
891 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
892 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
893 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
894 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
895 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
896 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
897 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
902 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
903 public void DefineDynamicAssembly6_Name_Null ()
906 AppDomain.CurrentDomain.DefineDynamicAssembly (
908 AssemblyBuilderAccess.Run,
909 AppDomain.CurrentDomain.Evidence,
910 (PermissionSet) null,
911 (PermissionSet) null,
912 (PermissionSet) null);
914 } catch (ArgumentNullException ex) {
915 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
916 Assert.IsNull (ex.InnerException, "#A3");
917 Assert.IsNotNull (ex.Message, "#A4");
918 Assert.IsNotNull (ex.ParamName, "#A5");
919 Assert.AreEqual ("name", ex.ParamName, "#A6");
922 AssemblyName name = new AssemblyName ();
925 AppDomain.CurrentDomain.DefineDynamicAssembly (
927 AssemblyBuilderAccess.Run,
928 AppDomain.CurrentDomain.Evidence,
929 (PermissionSet) null,
930 (PermissionSet) null,
931 (PermissionSet) null);
933 } catch (ArgumentException ex) {
934 // AssemblyName.Name cannot be null or an empty string
935 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
936 Assert.IsNull (ex.InnerException, "#B3");
937 Assert.IsNotNull (ex.Message, "#B4");
938 Assert.IsNull (ex.ParamName, "#B5");
941 name.Name = string.Empty;
944 AppDomain.CurrentDomain.DefineDynamicAssembly (
946 AssemblyBuilderAccess.Run,
947 AppDomain.CurrentDomain.Evidence,
948 (PermissionSet) null,
949 (PermissionSet) null,
950 (PermissionSet) null);
952 } catch (ArgumentException ex) {
953 // AssemblyName.Name cannot be null or an empty string
954 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
955 Assert.IsNull (ex.InnerException, "#C3");
956 Assert.IsNotNull (ex.Message, "#C4");
957 Assert.IsNull (ex.ParamName, "#C5");
961 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
962 public void DefineDynamicAssembly7_Access_Invalid ()
964 AssemblyName name = new AssemblyName ();
965 name.Name = "DefineDynamicAssembly7";
969 AppDomain.CurrentDomain.DefineDynamicAssembly (
970 name, AssemblyBuilderAccess.Run |
971 (AssemblyBuilderAccess) 666,
973 (PermissionSet) null,
974 (PermissionSet) null,
975 (PermissionSet) null);
977 } catch (ArgumentException ex) {
978 // Illegal enum value: 667
979 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
980 Assert.IsNull (ex.InnerException, "#3");
981 Assert.IsNotNull (ex.Message, "#4");
982 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
983 Assert.IsNotNull (ex.ParamName, "#6");
984 Assert.AreEqual ("access", ex.ParamName, "#7");
987 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
988 name, AssemblyBuilderAccess.Run |
989 (AssemblyBuilderAccess) 666,
991 (PermissionSet) null,
992 (PermissionSet) null,
993 (PermissionSet) null);
994 Assert.IsNotNull (ab, "#1");
998 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
999 public void DefineDynamicAssembly7_Name_InvalidChars ()
1001 string [] invalid_char_names = new string [] {
1011 AssemblyName name = new AssemblyName ();
1013 foreach (string invalid_name in invalid_char_names) {
1014 name.Name = invalid_name;
1016 AppDomain.CurrentDomain.DefineDynamicAssembly (
1018 AssemblyBuilderAccess.Run,
1019 Path.GetTempPath (),
1020 (PermissionSet) null,
1021 (PermissionSet) null,
1022 (PermissionSet) null);
1023 Assert.Fail ("#1:" + invalid_name);
1024 } catch (ArgumentException ex) {
1025 // Assembly names may not begin with whitespace
1026 // or contain the characters '/', '\' or ':'
1027 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1028 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1029 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1030 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1031 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1032 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1033 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1038 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
1039 public void DefineDynamicAssembly7_Name_Null ()
1042 AppDomain.CurrentDomain.DefineDynamicAssembly (
1043 (AssemblyName) null,
1044 AssemblyBuilderAccess.Run,
1045 Path.GetTempPath (),
1046 (PermissionSet) null,
1047 (PermissionSet) null,
1048 (PermissionSet) null);
1049 Assert.Fail ("#A1");
1050 } catch (ArgumentNullException ex) {
1051 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1052 Assert.IsNull (ex.InnerException, "#A3");
1053 Assert.IsNotNull (ex.Message, "#A4");
1054 Assert.IsNotNull (ex.ParamName, "#A5");
1055 Assert.AreEqual ("name", ex.ParamName, "#A6");
1058 AssemblyName name = new AssemblyName ();
1061 AppDomain.CurrentDomain.DefineDynamicAssembly (
1063 AssemblyBuilderAccess.Run,
1064 Path.GetTempPath (),
1065 (PermissionSet) null,
1066 (PermissionSet) null,
1067 (PermissionSet) null);
1068 Assert.Fail ("#B1");
1069 } catch (ArgumentException ex) {
1070 // AssemblyName.Name cannot be null or an empty string
1071 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1072 Assert.IsNull (ex.InnerException, "#B3");
1073 Assert.IsNotNull (ex.Message, "#B4");
1074 Assert.IsNull (ex.ParamName, "#B5");
1077 name.Name = string.Empty;
1080 AppDomain.CurrentDomain.DefineDynamicAssembly (
1082 AssemblyBuilderAccess.Run,
1083 Path.GetTempPath (),
1084 (PermissionSet) null,
1085 (PermissionSet) null,
1086 (PermissionSet) null);
1087 Assert.Fail ("#C1");
1088 } catch (ArgumentException ex) {
1089 // AssemblyName.Name cannot be null or an empty string
1090 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1091 Assert.IsNull (ex.InnerException, "#C3");
1092 Assert.IsNotNull (ex.Message, "#C4");
1093 Assert.IsNull (ex.ParamName, "#C5");
1097 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
1098 public void DefineDynamicAssembly8_Access_Invalid ()
1100 AssemblyName name = new AssemblyName ();
1101 name.Name = "DefineDynamicAssembly8";
1105 AppDomain.CurrentDomain.DefineDynamicAssembly (
1106 name, AssemblyBuilderAccess.Run |
1107 (AssemblyBuilderAccess) 666,
1108 Path.GetTempPath (),
1109 AppDomain.CurrentDomain.Evidence,
1110 (PermissionSet) null,
1111 (PermissionSet) null,
1112 (PermissionSet) null);
1114 } catch (ArgumentException ex) {
1115 // Illegal enum value: 667
1116 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1117 Assert.IsNull (ex.InnerException, "#3");
1118 Assert.IsNotNull (ex.Message, "#4");
1119 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1120 Assert.IsNotNull (ex.ParamName, "#6");
1121 Assert.AreEqual ("access", ex.ParamName, "#7");
1124 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1125 name, AssemblyBuilderAccess.Run |
1126 (AssemblyBuilderAccess) 666,
1127 Path.GetTempPath (),
1128 AppDomain.CurrentDomain.Evidence,
1129 (PermissionSet) null,
1130 (PermissionSet) null,
1131 (PermissionSet) null);
1132 Assert.IsNotNull (ab, "#1");
1136 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
1137 public void DefineDynamicAssembly8_Name_InvalidChars ()
1139 string [] invalid_char_names = new string [] {
1149 AssemblyName name = new AssemblyName ();
1151 foreach (string invalid_name in invalid_char_names) {
1152 name.Name = invalid_name;
1154 AppDomain.CurrentDomain.DefineDynamicAssembly (
1156 AssemblyBuilderAccess.Run,
1157 Path.GetTempPath (),
1158 AppDomain.CurrentDomain.Evidence,
1159 (PermissionSet) null,
1160 (PermissionSet) null,
1161 (PermissionSet) null);
1162 Assert.Fail ("#1:" + invalid_name);
1163 } catch (ArgumentException ex) {
1164 // Assembly names may not begin with whitespace
1165 // or contain the characters '/', '\' or ':'
1166 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1167 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1168 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1169 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1170 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1171 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1172 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1177 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
1178 public void DefineDynamicAssembly8_Name_Null ()
1181 AppDomain.CurrentDomain.DefineDynamicAssembly (
1182 (AssemblyName) null,
1183 AssemblyBuilderAccess.Run,
1184 Path.GetTempPath (),
1185 AppDomain.CurrentDomain.Evidence,
1186 (PermissionSet) null,
1187 (PermissionSet) null,
1188 (PermissionSet) null);
1189 Assert.Fail ("#A1");
1190 } catch (ArgumentNullException ex) {
1191 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1192 Assert.IsNull (ex.InnerException, "#A3");
1193 Assert.IsNotNull (ex.Message, "#A4");
1194 Assert.IsNotNull (ex.ParamName, "#A5");
1195 Assert.AreEqual ("name", ex.ParamName, "#A6");
1198 AssemblyName name = new AssemblyName ();
1201 AppDomain.CurrentDomain.DefineDynamicAssembly (
1203 AssemblyBuilderAccess.Run,
1204 Path.GetTempPath (),
1205 AppDomain.CurrentDomain.Evidence,
1206 (PermissionSet) null,
1207 (PermissionSet) null,
1208 (PermissionSet) null);
1209 Assert.Fail ("#B1");
1210 } catch (ArgumentException ex) {
1211 // AssemblyName.Name cannot be null or an empty string
1212 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1213 Assert.IsNull (ex.InnerException, "#B3");
1214 Assert.IsNotNull (ex.Message, "#B4");
1215 Assert.IsNull (ex.ParamName, "#B5");
1218 name.Name = string.Empty;
1221 AppDomain.CurrentDomain.DefineDynamicAssembly (
1223 AssemblyBuilderAccess.Run,
1224 Path.GetTempPath (),
1225 AppDomain.CurrentDomain.Evidence,
1226 (PermissionSet) null,
1227 (PermissionSet) null,
1228 (PermissionSet) null);
1229 Assert.Fail ("#C1");
1230 } catch (ArgumentException ex) {
1231 // AssemblyName.Name cannot be null or an empty string
1232 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1233 Assert.IsNull (ex.InnerException, "#C3");
1234 Assert.IsNotNull (ex.Message, "#C4");
1235 Assert.IsNull (ex.ParamName, "#C5");
1239 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
1240 public void DefineDynamicAssembly9_Access_Invalid ()
1242 AssemblyName name = new AssemblyName ();
1243 name.Name = "DefineDynamicAssembly9";
1247 AppDomain.CurrentDomain.DefineDynamicAssembly (
1248 name, AssemblyBuilderAccess.Run |
1249 (AssemblyBuilderAccess) 666,
1250 Path.GetTempPath (),
1251 AppDomain.CurrentDomain.Evidence,
1252 (PermissionSet) null,
1253 (PermissionSet) null,
1254 (PermissionSet) null,
1257 } catch (ArgumentException ex) {
1258 // Illegal enum value: 667
1259 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1260 Assert.IsNull (ex.InnerException, "#3");
1261 Assert.IsNotNull (ex.Message, "#4");
1262 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1263 Assert.IsNotNull (ex.ParamName, "#6");
1264 Assert.AreEqual ("access", ex.ParamName, "#7");
1267 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1268 name, AssemblyBuilderAccess.Run |
1269 (AssemblyBuilderAccess) 666,
1270 Path.GetTempPath (),
1271 AppDomain.CurrentDomain.Evidence,
1272 (PermissionSet) null,
1273 (PermissionSet) null,
1274 (PermissionSet) null,
1276 Assert.IsNotNull (ab, "#1");
1280 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
1281 public void DefineDynamicAssembly9_Name_InvalidChars ()
1283 string [] invalid_char_names = new string [] {
1293 AssemblyName name = new AssemblyName ();
1295 foreach (string invalid_name in invalid_char_names) {
1296 name.Name = invalid_name;
1298 AppDomain.CurrentDomain.DefineDynamicAssembly (
1300 AssemblyBuilderAccess.Run,
1301 Path.GetTempPath (),
1302 AppDomain.CurrentDomain.Evidence,
1303 (PermissionSet) null,
1304 (PermissionSet) null,
1305 (PermissionSet) null,
1307 Assert.Fail ("#1:" + invalid_name);
1308 } catch (ArgumentException ex) {
1309 // Assembly names may not begin with whitespace
1310 // or contain the characters '/', '\' or ':'
1311 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1312 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1313 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1314 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1315 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1316 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1317 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1322 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
1323 public void DefineDynamicAssembly9_Name_Null ()
1326 AppDomain.CurrentDomain.DefineDynamicAssembly (
1327 (AssemblyName) null,
1328 AssemblyBuilderAccess.Run,
1329 Path.GetTempPath (),
1330 AppDomain.CurrentDomain.Evidence,
1331 (PermissionSet) null,
1332 (PermissionSet) null,
1333 (PermissionSet) null,
1335 Assert.Fail ("#A1");
1336 } catch (ArgumentNullException ex) {
1337 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1338 Assert.IsNull (ex.InnerException, "#A3");
1339 Assert.IsNotNull (ex.Message, "#A4");
1340 Assert.IsNotNull (ex.ParamName, "#A5");
1341 Assert.AreEqual ("name", ex.ParamName, "#A6");
1344 AssemblyName name = new AssemblyName ();
1347 AppDomain.CurrentDomain.DefineDynamicAssembly (
1349 AssemblyBuilderAccess.Run,
1350 Path.GetTempPath (),
1351 AppDomain.CurrentDomain.Evidence,
1352 (PermissionSet) null,
1353 (PermissionSet) null,
1354 (PermissionSet) null,
1356 Assert.Fail ("#B1");
1357 } catch (ArgumentException ex) {
1358 // AssemblyName.Name cannot be null or an empty string
1359 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1360 Assert.IsNull (ex.InnerException, "#B3");
1361 Assert.IsNotNull (ex.Message, "#B4");
1362 Assert.IsNull (ex.ParamName, "#B5");
1365 name.Name = string.Empty;
1368 AppDomain.CurrentDomain.DefineDynamicAssembly (
1370 AssemblyBuilderAccess.Run,
1371 Path.GetTempPath (),
1372 AppDomain.CurrentDomain.Evidence,
1373 (PermissionSet) null,
1374 (PermissionSet) null,
1375 (PermissionSet) null,
1377 Assert.Fail ("#C1");
1378 } catch (ArgumentException ex) {
1379 // AssemblyName.Name cannot be null or an empty string
1380 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1381 Assert.IsNull (ex.InnerException, "#C3");
1382 Assert.IsNotNull (ex.Message, "#C4");
1383 Assert.IsNull (ex.ParamName, "#C5");
1388 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1389 public void DefineDynamicAssembly10_Access_Invalid ()
1391 AssemblyName name = new AssemblyName ();
1392 name.Name = "DefineDynamicAssembly10";
1396 AppDomain.CurrentDomain.DefineDynamicAssembly (
1397 name, AssemblyBuilderAccess.Run |
1398 (AssemblyBuilderAccess) 666,
1399 Path.GetTempPath (),
1400 AppDomain.CurrentDomain.Evidence,
1401 (PermissionSet) null,
1402 (PermissionSet) null,
1403 (PermissionSet) null,
1405 new List<CustomAttributeBuilder> ());
1407 } catch (ArgumentException ex) {
1408 // Illegal enum value: 667
1409 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1410 Assert.IsNull (ex.InnerException, "#3");
1411 Assert.IsNotNull (ex.Message, "#4");
1412 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1413 Assert.IsNotNull (ex.ParamName, "#6");
1414 Assert.AreEqual ("access", ex.ParamName, "#7");
1417 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1418 name, AssemblyBuilderAccess.Run |
1419 (AssemblyBuilderAccess) 666,
1420 Path.GetTempPath (),
1421 AppDomain.CurrentDomain.Evidence,
1422 (PermissionSet) null,
1423 (PermissionSet) null,
1424 (PermissionSet) null,
1426 new List<CustomAttributeBuilder> ());
1427 Assert.IsNotNull (ab, "#1");
1431 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1432 public void DefineDynamicAssembly10_Name_InvalidChars ()
1434 string [] invalid_char_names = new string [] {
1444 AssemblyName name = new AssemblyName ();
1446 foreach (string invalid_name in invalid_char_names) {
1447 name.Name = invalid_name;
1449 AppDomain.CurrentDomain.DefineDynamicAssembly (
1451 AssemblyBuilderAccess.Run,
1452 Path.GetTempPath (),
1453 AppDomain.CurrentDomain.Evidence,
1454 (PermissionSet) null,
1455 (PermissionSet) null,
1456 (PermissionSet) null,
1458 new List<CustomAttributeBuilder> ());
1459 Assert.Fail ("#1:" + invalid_name);
1460 } catch (ArgumentException ex) {
1461 // Assembly names may not begin with whitespace
1462 // or contain the characters '/', '\' or ':'
1463 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1464 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1465 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1466 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1467 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1468 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1469 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1474 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1475 public void DefineDynamicAssembly10_Name_Null ()
1478 AppDomain.CurrentDomain.DefineDynamicAssembly (
1479 (AssemblyName) null,
1480 AssemblyBuilderAccess.Run,
1481 Path.GetTempPath (),
1482 AppDomain.CurrentDomain.Evidence,
1483 (PermissionSet) null,
1484 (PermissionSet) null,
1485 (PermissionSet) null,
1487 new List<CustomAttributeBuilder> ());
1488 Assert.Fail ("#A1");
1489 } catch (ArgumentNullException ex) {
1490 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1491 Assert.IsNull (ex.InnerException, "#A3");
1492 Assert.IsNotNull (ex.Message, "#A4");
1493 Assert.IsNotNull (ex.ParamName, "#A5");
1494 Assert.AreEqual ("name", ex.ParamName, "#A6");
1497 AssemblyName name = new AssemblyName ();
1500 AppDomain.CurrentDomain.DefineDynamicAssembly (
1502 AssemblyBuilderAccess.Run,
1503 Path.GetTempPath (),
1504 AppDomain.CurrentDomain.Evidence,
1505 (PermissionSet) null,
1506 (PermissionSet) null,
1507 (PermissionSet) null,
1509 new List<CustomAttributeBuilder> ());
1510 Assert.Fail ("#B1");
1511 } catch (ArgumentException ex) {
1512 // AssemblyName.Name cannot be null or an empty string
1513 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1514 Assert.IsNull (ex.InnerException, "#B3");
1515 Assert.IsNotNull (ex.Message, "#B4");
1516 Assert.IsNull (ex.ParamName, "#B5");
1519 name.Name = string.Empty;
1522 AppDomain.CurrentDomain.DefineDynamicAssembly (
1524 AssemblyBuilderAccess.Run,
1525 Path.GetTempPath (),
1526 AppDomain.CurrentDomain.Evidence,
1527 (PermissionSet) null,
1528 (PermissionSet) null,
1529 (PermissionSet) null,
1531 new List<CustomAttributeBuilder> ());
1532 Assert.Fail ("#C1");
1533 } catch (ArgumentException ex) {
1534 // AssemblyName.Name cannot be null or an empty string
1535 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1536 Assert.IsNull (ex.InnerException, "#C3");
1537 Assert.IsNotNull (ex.Message, "#C4");
1538 Assert.IsNull (ex.ParamName, "#C5");
1542 [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
1543 public void DefineDynamicAssembly11 ()
1545 List<CustomAttributeBuilder> cattrs;
1549 string assemblyFile;
1550 string current_dir = Directory.GetCurrentDirectory ();
1552 name = new AssemblyName ();
1553 name.Name = "DefineDynamicAssembly11A";
1555 cattrs = new List<CustomAttributeBuilder> ();
1556 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).
1557 GetConstructor (new Type [] { typeof (string) }),
1558 new object [] { "1.2.3.4"}));
1559 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).
1560 GetConstructor (new Type [] { typeof (string) }),
1561 new object [] { "nl-BE"}));
1562 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).
1563 GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }),
1564 new object [] { AssemblyHashAlgorithm.MD5 }));
1565 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).
1566 GetConstructor (new Type [] { typeof (uint) }),
1567 new object [] { (uint)0x0100 }));
1568 cattrs.Add (new CustomAttributeBuilder (typeof (CLSCompliantAttribute).
1569 GetConstructor (new Type [] { typeof (bool) }),
1570 new object [] { true }));
1572 ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1573 name, AssemblyBuilderAccess.Save, cattrs);
1575 ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (ComVisibleAttribute).
1576 GetConstructor (new Type [] { typeof (bool) }),
1577 new object [] { true }));
1579 ab.Save ("DefineDynamicAssembly11A.dll");
1581 assemblyFile = Path.Combine (current_dir, "DefineDynamicAssembly11A.dll");
1584 AssemblyName an = AssemblyName.GetAssemblyName (assemblyFile);
1585 Assert.AreEqual (CultureInfo.InvariantCulture, an.CultureInfo, "#A1");
1586 Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#A2");
1587 Assert.AreEqual ("DefineDynamicAssembly11A, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", an.FullName, "#A3");
1588 Assert.IsNull (an.GetPublicKey (), "#A4");
1589 Assert.AreEqual (new byte [0], an.GetPublicKeyToken (), "#A5");
1590 Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "#A6");
1591 Assert.IsNull (an.KeyPair, "#A7");
1592 Assert.AreEqual ("DefineDynamicAssembly11A", an.Name, "#A8");
1593 //Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "#A9");
1594 Assert.AreEqual (an.FullName, an.ToString (), "#A10");
1595 Assert.AreEqual (new Version (0, 0, 0, 0), an.Version, "#A11");
1596 Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, an.VersionCompatibility, "#A12");
1600 using (FileStream fs = File.OpenRead (assemblyFile)) {
1601 byte [] buffer = new byte [fs.Length];
1602 fs.Read (buffer, 0, buffer.Length);
1603 a = Assembly.Load (buffer);
1606 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyVersionAttribute));
1607 Assert.IsNotNull (attr, "#A13a");
1608 Assert.AreEqual ("1.2.3.4", ((AssemblyVersionAttribute) attr).Version, "#A13b");
1609 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyCultureAttribute));
1610 Assert.IsNotNull (attr, "#A14a");
1611 Assert.AreEqual ("nl-BE", ((AssemblyCultureAttribute) attr).Culture, "#A14b");
1612 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyAlgorithmIdAttribute));
1613 Assert.IsNotNull (attr, "#A15a");
1614 Assert.AreEqual ((uint) AssemblyHashAlgorithm.MD5, ((AssemblyAlgorithmIdAttribute) attr).AlgorithmId, "#A15b");
1615 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyFlagsAttribute));
1616 Assert.IsNotNull (attr, "#A16a");
1617 Assert.AreEqual ((uint) 0x0100, ((AssemblyFlagsAttribute) attr).Flags, "#A16b");
1618 attr = Attribute.GetCustomAttribute (a, typeof (CLSCompliantAttribute));
1619 Assert.IsNotNull (attr, "#A17a");
1620 Assert.IsTrue (((CLSCompliantAttribute) attr).IsCompliant, "#A17b");
1621 attr = Attribute.GetCustomAttribute (a, typeof (ComVisibleAttribute));
1622 Assert.IsNotNull (attr, "#A18a");
1623 Assert.IsTrue (((ComVisibleAttribute) attr).Value, "#A18b");
1625 File.Delete (assemblyFile);
1628 name = new AssemblyName ();
1629 name.CultureInfo = new CultureInfo ("fr-BE");
1630 name.KeyPair = new StrongNameKeyPair (keyPair);
1631 name.Name = "DefineDynamicAssembly11B";
1632 name.Version = new Version (3, 2, 4, 1);
1634 cattrs = new List<CustomAttributeBuilder> ();
1635 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).
1636 GetConstructor (new Type [] { typeof (string) }),
1637 new object [] { "1.2.3.4"}));
1638 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).
1639 GetConstructor (new Type [] { typeof (string) }),
1640 new object [] { "nl-BE"}));
1641 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).
1642 GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }),
1643 new object [] { AssemblyHashAlgorithm.MD5 }));
1644 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).
1645 GetConstructor (new Type [] { typeof (uint) }),
1646 new object [] { (uint)0x0100 }));
1647 cattrs.Add (new CustomAttributeBuilder (typeof (CLSCompliantAttribute).
1648 GetConstructor (new Type [] { typeof (bool) }),
1649 new object [] { true }));
1651 ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1652 name, AssemblyBuilderAccess.Save, cattrs);
1654 ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (ComVisibleAttribute).
1655 GetConstructor (new Type [] { typeof (bool) }),
1656 new object [] { true }));
1658 ab.Save ("DefineDynamicAssembly11B.dll");
1660 assemblyFile = Path.Combine (current_dir, "DefineDynamicAssembly11B.dll");
1663 AssemblyName an = AssemblyName.GetAssemblyName (assemblyFile);
1664 Assert.AreEqual ("fr-BE", an.CultureInfo.Name, "#B1");
1665 Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#B2");
1666 Assert.AreEqual ("DefineDynamicAssembly11B, Version=3.2.4.1, Culture=fr-BE, PublicKeyToken=ce5276d8687ec6dc", an.FullName, "#B3");
1667 Assert.AreEqual (publicKey, an.GetPublicKey (), "#B4");
1668 Assert.AreEqual (pk_token, an.GetPublicKeyToken (), "#B5");
1669 Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "#B6");
1670 Assert.IsNull (an.KeyPair, "#B7");
1671 Assert.AreEqual ("DefineDynamicAssembly11B", an.Name, "#B8");
1672 //Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "#B9");
1673 Assert.AreEqual (an.FullName, an.ToString (), "#B10");
1674 Assert.AreEqual (new Version (3, 2, 4, 1), an.Version, "#B11");
1675 Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, an.VersionCompatibility, "#B12");
1679 using (FileStream fs = File.OpenRead (assemblyFile)) {
1680 byte [] buffer = new byte [fs.Length];
1681 fs.Read (buffer, 0, buffer.Length);
1682 a = Assembly.Load (buffer);
1685 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyVersionAttribute));
1686 Assert.IsNotNull (attr, "#B13a");
1687 Assert.AreEqual ("1.2.3.4", ((AssemblyVersionAttribute) attr).Version, "#B13b");
1688 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyCultureAttribute));
1689 Assert.IsNotNull (attr, "#B14a");
1690 Assert.AreEqual ("nl-BE", ((AssemblyCultureAttribute) attr).Culture, "#B14b");
1691 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyAlgorithmIdAttribute));
1692 Assert.IsNotNull (attr, "#B15a");
1693 Assert.AreEqual ((uint) AssemblyHashAlgorithm.MD5, ((AssemblyAlgorithmIdAttribute) attr).AlgorithmId, "#B15b");
1694 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyFlagsAttribute));
1695 Assert.IsNotNull (attr, "#B16a");
1696 Assert.AreEqual ((uint) 0x0100, ((AssemblyFlagsAttribute) attr).Flags, "#B16b");
1697 attr = Attribute.GetCustomAttribute (a, typeof (CLSCompliantAttribute));
1698 Assert.IsNotNull (attr, "#B17a");
1699 Assert.IsTrue (((CLSCompliantAttribute) attr).IsCompliant, "#B17b");
1700 attr = Attribute.GetCustomAttribute (a, typeof (ComVisibleAttribute));
1701 Assert.IsNotNull (attr, "#B18a");
1702 Assert.IsTrue (((ComVisibleAttribute) attr).Value, "#B18b");
1704 File.Delete (assemblyFile);
1708 [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
1709 public void DefineDynamicAssembly11_Access_Invalid ()
1711 AssemblyName name = new AssemblyName ();
1712 name.Name = "DefineDynamicAssembly11";
1716 AppDomain.CurrentDomain.DefineDynamicAssembly (
1717 name, AssemblyBuilderAccess.Run |
1718 (AssemblyBuilderAccess) 666,
1719 new List<CustomAttributeBuilder> ());
1721 } catch (ArgumentException ex) {
1722 // Illegal enum value: 667
1723 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1724 Assert.IsNull (ex.InnerException, "#3");
1725 Assert.IsNotNull (ex.Message, "#4");
1726 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1727 Assert.IsNotNull (ex.ParamName, "#6");
1728 Assert.AreEqual ("access", ex.ParamName, "#7");
1731 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1732 name, AssemblyBuilderAccess.Run |
1733 (AssemblyBuilderAccess) 666,
1734 new List<CustomAttributeBuilder> ());
1735 Assert.IsNotNull (ab, "#1");
1739 [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
1740 public void DefineDynamicAssembly11_Name_InvalidChars ()
1742 string [] invalid_char_names = new string [] {
1752 AssemblyName name = new AssemblyName ();
1754 foreach (string invalid_name in invalid_char_names) {
1755 name.Name = invalid_name;
1757 AppDomain.CurrentDomain.DefineDynamicAssembly (
1759 AssemblyBuilderAccess.Run,
1760 new List<CustomAttributeBuilder> ());
1761 Assert.Fail ("#1:" + invalid_name);
1762 } catch (ArgumentException ex) {
1763 // Assembly names may not begin with whitespace
1764 // or contain the characters '/', '\' or ':'
1765 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1766 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1767 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1768 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1769 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1770 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1771 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1776 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1777 public void DefineDynamicAssembly11_Name_Null ()
1780 AppDomain.CurrentDomain.DefineDynamicAssembly (
1781 (AssemblyName) null,
1782 AssemblyBuilderAccess.Run,
1783 new List<CustomAttributeBuilder> ());
1784 Assert.Fail ("#A1");
1785 } catch (ArgumentNullException ex) {
1786 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1787 Assert.IsNull (ex.InnerException, "#A3");
1788 Assert.IsNotNull (ex.Message, "#A4");
1789 Assert.IsNotNull (ex.ParamName, "#A5");
1790 Assert.AreEqual ("name", ex.ParamName, "#A6");
1793 AssemblyName name = new AssemblyName ();
1796 AppDomain.CurrentDomain.DefineDynamicAssembly (
1798 AssemblyBuilderAccess.Run,
1799 new List<CustomAttributeBuilder> ());
1800 Assert.Fail ("#B1");
1801 } catch (ArgumentException ex) {
1802 // AssemblyName.Name cannot be null or an empty string
1803 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1804 Assert.IsNull (ex.InnerException, "#B3");
1805 Assert.IsNotNull (ex.Message, "#B4");
1806 Assert.IsNull (ex.ParamName, "#B5");
1809 name.Name = string.Empty;
1812 AppDomain.CurrentDomain.DefineDynamicAssembly (
1814 AssemblyBuilderAccess.Run,
1815 new List<CustomAttributeBuilder> ());
1816 Assert.Fail ("#C1");
1817 } catch (ArgumentException ex) {
1818 // AssemblyName.Name cannot be null or an empty string
1819 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1820 Assert.IsNull (ex.InnerException, "#C3");
1821 Assert.IsNotNull (ex.Message, "#C4");
1822 Assert.IsNull (ex.ParamName, "#C5");
1826 [Test] // ExecuteAssemblyByName (String)
1827 public void ExecuteAssemblyByName1_NoEntryPoint ()
1830 AppDomain.CurrentDomain.ExecuteAssemblyByName ("mscorlib");
1832 } catch (MissingMethodException ex) {
1833 // Entry point not found in assembly '...'
1834 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1835 Assert.IsNull (ex.InnerException, "#3");
1836 Assert.IsNotNull (ex.Message, "#4");
1837 Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
1841 [Test] // ExecuteAssemblyByName (String, Evidence)
1842 public void ExecuteAssemblyByName2_NoEntryPoint ()
1845 AppDomain.CurrentDomain.ExecuteAssemblyByName (
1846 "mscorlib", (Evidence) null);
1848 } catch (MissingMethodException ex) {
1849 // Entry point not found in assembly '...'
1850 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1851 Assert.IsNull (ex.InnerException, "#3");
1852 Assert.IsNotNull (ex.Message, "#4");
1853 Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
1857 [Test] // ExecuteAssemblyByName (String, Evidence, String [])
1858 public void ExecuteAssemblyByName3_NoEntryPoint ()
1861 AppDomain.CurrentDomain.ExecuteAssemblyByName (
1862 "mscorlib", (Evidence) null,
1865 } catch (MissingMethodException ex) {
1866 // Entry point not found in assembly '...'
1867 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1868 Assert.IsNull (ex.InnerException, "#3");
1869 Assert.IsNotNull (ex.Message, "#4");
1870 Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
1874 [Test] // ExecuteAssemblyByName (AssemblyName, Evidence, String [])
1875 public void ExecuteAssemblyByName4_NoEntryPoint ()
1877 AssemblyName aname = new AssemblyName ("mscorlib");
1880 AppDomain.CurrentDomain.ExecuteAssemblyByName (
1881 aname, (Evidence) null, new string [0]);
1883 } catch (MissingMethodException ex) {
1884 // Entry point not found in assembly '...'
1885 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1886 Assert.IsNull (ex.InnerException, "#3");
1887 Assert.IsNotNull (ex.Message, "#4");
1888 Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
1894 public void SetThreadPrincipal ()
1896 IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
1897 IPrincipal p = new GenericPrincipal (i, null);
1898 ad = AppDomain.CreateDomain ("SetThreadPrincipal");
1899 ad.SetThreadPrincipal (p);
1903 [ExpectedException (typeof (ArgumentNullException))]
1904 public void SetThreadPrincipalNull ()
1906 AppDomain.CurrentDomain.SetThreadPrincipal (null);
1910 [ExpectedException (typeof (PolicyException))]
1911 public void SetThreadPrincipalTwice ()
1913 IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
1914 IPrincipal p = new GenericPrincipal (i, null);
1915 ad = AppDomain.CreateDomain ("SetThreadPrincipalTwice");
1916 ad.SetThreadPrincipal (p);
1917 // you only live twice (or so James told me ;-)
1918 ad.SetThreadPrincipal (p);
1922 [ExpectedException (typeof (AppDomainUnloadedException))]
1923 public void SetThreadPrincipalUnloaded ()
1925 ad = AppDomain.CreateDomain ("Ximian");
1926 AppDomain.Unload (ad);
1927 IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
1928 IPrincipal p = new GenericPrincipal (i, null);
1929 ad.SetThreadPrincipal (p);
1933 public void SetPrincipalPolicy_NoPrincipal ()
1935 AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
1939 public void SetPrincipalPolicy_UnauthenticatedPrincipal ()
1941 AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.UnauthenticatedPrincipal);
1945 public void SetPrincipalPolicy_WindowsPrincipal ()
1947 AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.WindowsPrincipal);
1951 [ExpectedException (typeof (AppDomainUnloadedException))]
1952 public void SetPrincipalPolicyUnloaded ()
1954 ad = AppDomain.CreateDomain ("Ximian");
1955 AppDomain.Unload (ad);
1956 ad.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
1960 public void CreateDomain_String ()
1962 ad = AppDomain.CreateDomain ("CreateDomain_String");
1963 Assert.IsNotNull (ad.Evidence, "Evidence");
1964 // Evidence are copied (or referenced?) from default app domain
1965 // we can't get default so we use the current (which should have copied the default)
1966 Assert.AreEqual (AppDomain.CurrentDomain.Evidence.Count, ad.Evidence.Count, "Evidence.Count");
1970 [ExpectedException (typeof (ArgumentNullException))]
1971 public void CreateDomain_String_Null ()
1973 ad = AppDomain.CreateDomain (null);
1977 [Category ("NotDotNet")]
1978 public void CreateDomain_StringEvidence ()
1980 Evidence e = new Evidence ();
1981 ad = AppDomain.CreateDomain ("CreateDomain_StringEvidence", e);
1982 Assert.IsNotNull (ad.Evidence, "Evidence");
1983 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
1985 e.AddHost (new Zone (SecurityZone.MyComputer));
1986 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
1987 // evidence isn't copied but referenced
1991 [ExpectedException (typeof (ArgumentNullException))]
1992 public void CreateDomain_StringNullEvidence ()
1994 ad = AppDomain.CreateDomain (null, new Evidence ());
1998 public void CreateDomain_StringEvidenceNull ()
2000 ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceNull", null);
2001 Assert.IsNotNull (ad.Evidence, "Evidence");
2002 // Evidence are copied (or referenced?) from default app domain
2003 // we can't get default so we use the current (which should have copied the default)
2004 Evidence e = AppDomain.CurrentDomain.Evidence;
2005 Assert.AreEqual (e.Count, ad.Evidence.Count, "Evidence.Count-1");
2006 e.AddHost (new Zone (SecurityZone.MyComputer));
2007 Assert.AreEqual (e.Count - 1, ad.Evidence.Count, "Evidence.Count-2");
2008 // evidence are copied
2012 [Category ("NotDotNet")]
2013 public void CreateDomain_StringEvidenceAppDomainSetup ()
2015 Evidence e = new Evidence ();
2016 AppDomainSetup info = new AppDomainSetup ();
2017 info.ApplicationName = "ApplicationName";
2019 ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceAppDomainSetup", e, info);
2020 Assert.IsNotNull (ad.Evidence, "Evidence");
2021 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
2022 Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
2023 Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName);
2025 e.AddHost (new Zone (SecurityZone.MyComputer));
2026 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
2027 // evidence isn't copied but referenced
2031 [ExpectedException (typeof (ArgumentNullException))]
2032 public void CreateDomain_StringNullEvidenceAppDomainSetup ()
2034 AppDomainSetup info = new AppDomainSetup ();
2035 ad = AppDomain.CreateDomain (null, new Evidence (), info);
2039 public void CreateDomain_StringEvidenceNullAppDomainSetup ()
2041 AppDomainSetup info = new AppDomainSetup ();
2042 info.ApplicationName = "ApplicationName";
2043 ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceNullAppDomainSetup", null, info);
2044 Assert.IsNotNull (ad.Evidence, "Evidence");
2045 // Evidence are copied (or referenced?) from default app domain
2046 // we can't get default so we use the current (which should have copied the default)
2047 Assert.AreEqual (AppDomain.CurrentDomain.Evidence.Count, ad.Evidence.Count, "Evidence.Count");
2048 Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName, "ApplicationName-1");
2049 info.ApplicationName = "Test";
2050 Assert.AreEqual ("Test", info.ApplicationName, "ApplicationName-2");
2051 Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName, "ApplicationName-3");
2056 [Category ("NotDotNet")]
2057 public void CreateDomain_StringEvidenceAppDomainSetupNull ()
2059 Evidence e = new Evidence ();
2060 ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceAppDomainSetupNull", e, null);
2061 Assert.IsNotNull (ad.Evidence, "Evidence");
2062 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
2063 // SetupInformation is copied from default app domain
2064 Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
2067 [Test] // ExecuteAssembly (String)
2068 public void ExecuteAssembly1_NoEntryPoint ()
2070 Assembly assembly = typeof (AppDomainTest).Assembly;
2073 AppDomain.CurrentDomain.ExecuteAssembly (
2076 } catch (MissingMethodException ex) {
2077 // Entry point not found in assembly '...'
2078 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2079 Assert.IsNull (ex.InnerException, "#3");
2080 Assert.IsNotNull (ex.Message, "#4");
2081 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2085 [Test] // ExecuteAssembly (String, Evidence)
2086 public void ExecuteAssembly2_NoEntryPoint ()
2088 Assembly assembly = typeof (AppDomainTest).Assembly;
2091 AppDomain.CurrentDomain.ExecuteAssembly (
2095 } catch (MissingMethodException ex) {
2096 // Entry point not found in assembly '...'
2097 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2098 Assert.IsNull (ex.InnerException, "#3");
2099 Assert.IsNotNull (ex.Message, "#4");
2100 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2104 [Test] // ExecuteAssembly (String, Evidence, String [])
2105 public void ExecuteAssembly3_NoEntryPoint ()
2107 Assembly assembly = typeof (AppDomainTest).Assembly;
2110 AppDomain.CurrentDomain.ExecuteAssembly (
2115 } catch (MissingMethodException ex) {
2116 // Entry point not found in assembly '...'
2117 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2118 Assert.IsNull (ex.InnerException, "#3");
2119 Assert.IsNotNull (ex.Message, "#4");
2120 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2124 [Test] // ExecuteAssembly (String, Evidence, String [], Byte [], AssemblyHashAlgorithm)
2125 [Category ("NotWorking")] // Not implemented
2126 public void ExecuteAssembly4_NoEntryPoint ()
2128 Assembly assembly = typeof (AppDomainTest).Assembly;
2131 AppDomain.CurrentDomain.ExecuteAssembly (
2136 AssemblyHashAlgorithm.SHA1);
2138 } catch (MissingMethodException ex) {
2139 // Entry point not found in assembly '...'
2140 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2141 Assert.IsNull (ex.InnerException, "#3");
2142 Assert.IsNotNull (ex.Message, "#4");
2143 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2147 [Test] // bug #79720
2148 [Category ("NotWorking")]
2149 public void Load_Loaded_Ignore ()
2151 int assemblyStartCount = AppDomain.CurrentDomain.GetAssemblies ().Length;
2155 string assemblyFile = Path.Combine (tempDir, "bug79720A.dll");
2156 AssemblyName aname = new AssemblyName ();
2157 aname.Name = "bug79720A";
2158 aname.Version = new Version (2, 4);
2160 GenerateAssembly (aname, assemblyFile);
2162 Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A1");
2164 aname = new AssemblyName ();
2165 aname.Name = "bug79720A";
2167 AppDomain.CurrentDomain.Load (aname);
2168 Assert.Fail ("#A2");
2169 } catch (FileNotFoundException) {
2172 aname = new AssemblyName ();
2173 aname.Name = "bug79720A";
2174 aname.Version = new Version (0, 0, 0, 0);
2176 AppDomain.CurrentDomain.Load (aname);
2177 Assert.Fail ("#A3");
2178 } catch (FileNotFoundException) {
2181 aname = new AssemblyName ();
2182 aname.Name = "bug79720A";
2183 aname.Version = new Version (2, 4);
2185 AppDomain.CurrentDomain.Load (aname);
2186 Assert.Fail ("#A4");
2187 } catch (FileNotFoundException) {
2190 Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A5");
2192 Assembly.LoadFrom (assemblyFile);
2194 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A6");
2196 aname = new AssemblyName ();
2197 aname.Name = "bug79720A";
2199 AppDomain.CurrentDomain.Load (aname);
2200 Assert.Fail ("#A7");
2201 } catch (FileNotFoundException) {
2204 aname = new AssemblyName ();
2205 aname.Name = "bug79720A";
2206 aname.Version = new Version (0, 0, 0, 0);
2208 AppDomain.CurrentDomain.Load (aname);
2209 Assert.Fail ("#A8");
2210 } catch (FileNotFoundException) {
2213 aname = new AssemblyName ();
2214 aname.Name = "bug79720A";
2215 aname.Version = new Version (2, 4);
2217 AppDomain.CurrentDomain.Load (aname);
2218 Assert.Fail ("#A9");
2219 } catch (FileNotFoundException) {
2222 aname = new AssemblyName ();
2223 aname.Name = "bug79720A";
2224 aname.Version = new Version (2, 4);
2225 aname.CultureInfo = CultureInfo.InvariantCulture;
2227 AppDomain.CurrentDomain.Load (aname);
2228 Assert.Fail ("#A10");
2229 } catch (FileNotFoundException) {
2232 aname = new AssemblyName ();
2233 aname.Name = "bug79720A";
2234 aname.Version = new Version (2, 4, 0, 0);
2235 aname.CultureInfo = CultureInfo.InvariantCulture;
2237 AppDomain.CurrentDomain.Load (aname);
2238 Assert.Fail ("#A11");
2239 } catch (FileNotFoundException) {
2242 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A12");
2246 assemblyFile = Path.Combine (tempDir, "bug79720B.dll");
2247 aname = new AssemblyName ();
2248 aname.Name = "bug79720B";
2249 aname.Version = new Version (2, 4, 1);
2250 aname.CultureInfo = new CultureInfo ("nl-BE");
2252 GenerateAssembly (aname, assemblyFile);
2254 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B1");
2256 aname = new AssemblyName ();
2257 aname.Name = "bug79720B";
2259 AppDomain.CurrentDomain.Load (aname);
2260 Assert.Fail ("#B2");
2261 } catch (FileNotFoundException) {
2264 aname = new AssemblyName ();
2265 aname.Name = "bug79720B";
2266 aname.Version = new Version (0, 0, 0, 0);
2268 AppDomain.CurrentDomain.Load (aname);
2269 Assert.Fail ("#B3");
2270 } catch (FileNotFoundException) {
2273 aname = new AssemblyName ();
2274 aname.Name = "bug79720B";
2275 aname.Version = new Version (2, 4, 1);
2277 AppDomain.CurrentDomain.Load (aname);
2278 Assert.Fail ("#B4");
2279 } catch (FileNotFoundException) {
2282 aname = new AssemblyName ();
2283 aname.Name = "bug79720B";
2284 aname.Version = new Version (2, 4, 1);
2285 aname.CultureInfo = new CultureInfo ("nl-BE");
2287 AppDomain.CurrentDomain.Load (aname);
2288 Assert.Fail ("#B5");
2289 } catch (FileNotFoundException) {
2292 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B6");
2294 Assembly.LoadFrom (assemblyFile);
2296 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B7");
2298 aname = new AssemblyName ();
2299 aname.Name = "bug79720B";
2301 AppDomain.CurrentDomain.Load (aname);
2302 Assert.Fail ("#B8");
2303 } catch (FileNotFoundException) {
2306 aname = new AssemblyName ();
2307 aname.Name = "bug79720B";
2308 aname.Version = new Version (0, 0, 0, 0);
2310 AppDomain.CurrentDomain.Load (aname);
2311 Assert.Fail ("#B9");
2312 } catch (FileNotFoundException) {
2315 aname = new AssemblyName ();
2316 aname.Name = "bug79720B";
2317 aname.Version = new Version (2, 4, 1);
2319 AppDomain.CurrentDomain.Load (aname);
2320 Assert.Fail ("#B10");
2321 } catch (FileNotFoundException) {
2324 aname = new AssemblyName ();
2325 aname.Name = "bug79720B";
2326 aname.Version = new Version (2, 4, 1);
2327 aname.CultureInfo = new CultureInfo ("nl-BE");
2329 AppDomain.CurrentDomain.Load (aname);
2330 Assert.Fail ("#B11");
2331 } catch (FileNotFoundException) {
2334 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B12");
2338 assemblyFile = Path.Combine (tempDir, "bug79720C.dll");
2339 aname = new AssemblyName ();
2340 aname.Name = "bug79720C";
2341 aname.CultureInfo = new CultureInfo ("nl-BE");
2342 aname.Version = new Version (2, 4);
2343 aname.KeyPair = new StrongNameKeyPair (keyPair);
2345 GenerateAssembly (aname, assemblyFile);
2347 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C1");
2349 aname = new AssemblyName ();
2350 aname.Name = "bug79720C";
2352 AppDomain.CurrentDomain.Load (aname);
2353 Assert.Fail ("#C2");
2354 } catch (FileNotFoundException) {
2357 aname = new AssemblyName ();
2358 aname.Name = "bug79720C";
2359 aname.Version = new Version (0, 0, 0, 0);
2361 AppDomain.CurrentDomain.Load (aname);
2362 Assert.Fail ("#C3");
2363 } catch (FileNotFoundException) {
2366 aname = new AssemblyName ();
2367 aname.Name = "bug79720C";
2368 aname.Version = new Version (2, 4, 1);
2370 AppDomain.CurrentDomain.Load (aname);
2371 Assert.Fail ("#C4");
2372 } catch (FileNotFoundException) {
2375 aname = new AssemblyName ();
2376 aname.Name = "bug79720C";
2377 aname.Version = new Version (2, 4, 1);
2378 aname.CultureInfo = new CultureInfo ("nl-BE");
2380 AppDomain.CurrentDomain.Load (aname);
2381 Assert.Fail ("#C5");
2382 } catch (FileNotFoundException) {
2385 aname = new AssemblyName ();
2386 aname.Name = "bug79720C";
2387 aname.Version = new Version (2, 4, 1);
2388 aname.CultureInfo = new CultureInfo ("nl-BE");
2389 aname.SetPublicKey (publicKey);
2391 AppDomain.CurrentDomain.Load (aname);
2392 Assert.Fail ("#C6");
2393 } catch (FileNotFoundException) {
2396 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C7");
2398 Assembly.LoadFrom (assemblyFile);
2400 Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C8");
2402 aname = new AssemblyName ();
2403 aname.Name = "bug79720C";
2405 AppDomain.CurrentDomain.Load (aname);
2406 Assert.Fail ("#C9");
2407 } catch (FileNotFoundException) {
2410 aname = new AssemblyName ();
2411 aname.Name = "bug79720C";
2412 aname.Version = new Version (0, 0, 0, 0);
2414 AppDomain.CurrentDomain.Load (aname);
2415 Assert.Fail ("#C10");
2416 } catch (FileNotFoundException) {
2419 aname = new AssemblyName ();
2420 aname.Name = "bug79720C";
2421 aname.Version = new Version (2, 4);
2423 AppDomain.CurrentDomain.Load (aname);
2424 Assert.Fail ("#C11");
2425 } catch (FileNotFoundException) {
2428 aname = new AssemblyName ();
2429 aname.Name = "bug79720C";
2430 aname.Version = new Version (2, 4);
2431 aname.CultureInfo = new CultureInfo ("nl-BE");
2433 AppDomain.CurrentDomain.Load (aname);
2434 Assert.Fail ("#C12");
2435 } catch (FileNotFoundException) {
2438 aname = new AssemblyName ();
2439 aname.Name = "bug79720C";
2440 aname.Version = new Version (2, 4);
2441 aname.CultureInfo = new CultureInfo ("nl-BE");
2442 aname.SetPublicKey (publicKey);
2444 AppDomain.CurrentDomain.Load (aname);
2445 Assert.Fail ("#C13");
2446 } catch (FileNotFoundException) {
2449 Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C14");
2453 [Category ("NotWorking")]
2454 public void Load_Loaded_Multiple ()
2456 string cultureDir = Path.Combine (tempDir, "nl-BE");
2457 if (!Directory.Exists (cultureDir))
2458 Directory.CreateDirectory (cultureDir);
2460 AppDomain ad = CreateTestDomain (tempDir, true);
2462 CrossDomainTester cdt = CreateCrossDomainTester (ad);
2464 int assemblyCount = cdt.AssemblyCount;
2468 AssemblyName aname = new AssemblyName ();
2469 aname.Name = "multipleA";
2470 aname.Version = new Version (1, 2, 3, 4);
2471 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "multipleA.dll"));
2473 Assert.AreEqual (assemblyCount + 1, cdt.AssemblyCount, "#A1");
2475 aname = new AssemblyName ();
2476 aname.Name = "multipleA";
2477 Assert.IsTrue (cdt.AssertLoad (aname), "#A2");
2479 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A3");
2481 aname = new AssemblyName ();
2482 aname.Name = "multipleA";
2483 Assert.IsTrue (cdt.AssertLoad (aname), "#A4");
2485 aname = new AssemblyName ();
2486 aname.Name = "multipleA";
2487 aname.CultureInfo = CultureInfo.InvariantCulture;
2488 Assert.IsTrue (cdt.AssertLoad (aname), "#A5");
2490 aname = new AssemblyName ();
2491 aname.Name = "multipleA";
2492 aname.CultureInfo = CultureInfo.InvariantCulture;
2493 Assert.IsTrue (cdt.AssertLoad (aname), "#A6");
2495 aname = new AssemblyName ();
2496 aname.Name = "multipleA";
2497 aname.CultureInfo = CultureInfo.InvariantCulture;
2498 aname.Version = new Version (1, 2, 3, 4);
2499 Assert.IsTrue (cdt.AssertLoad (aname), "#A7");
2501 aname = new AssemblyName ();
2502 aname.Name = "multipleA";
2503 aname.CultureInfo = CultureInfo.InvariantCulture;
2504 aname.Version = new Version (1, 2, 3, 4);
2505 Assert.IsTrue (cdt.AssertLoad (aname), "#A8");
2507 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A9");
2511 aname = new AssemblyName ();
2512 aname.Name = "multipleB";
2513 aname.CultureInfo = new CultureInfo ("nl-BE");
2514 aname.Version = new Version (2, 4, 1, 0);
2515 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleB.dll"));
2517 Assert.AreEqual (assemblyCount + 3, cdt.AssemblyCount, "#B1");
2519 aname = new AssemblyName ();
2520 aname.Name = "multipleB";
2521 Assert.IsTrue (cdt.AssertLoad (aname), "#B2");
2523 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B3");
2525 aname = new AssemblyName ();
2526 aname.Name = "multipleB";
2527 Assert.IsTrue (cdt.AssertLoad (aname), "#B4");
2529 aname = new AssemblyName ();
2530 aname.Name = "multipleB";
2531 aname.CultureInfo = new CultureInfo ("nl-BE");
2532 Assert.IsTrue (cdt.AssertLoad (aname), "#B5");
2534 aname = new AssemblyName ();
2535 aname.Name = "multipleB";
2536 aname.CultureInfo = new CultureInfo ("nl-BE");
2537 Assert.IsTrue (cdt.AssertLoad (aname), "#B6");
2539 aname = new AssemblyName ();
2540 aname.Name = "multipleB";
2541 aname.CultureInfo = new CultureInfo ("nl-BE");
2542 aname.Version = new Version (2, 4, 1, 0);
2543 Assert.IsTrue (cdt.AssertLoad (aname), "#B7");
2545 aname = new AssemblyName ();
2546 aname.Name = "multipleB";
2547 aname.CultureInfo = new CultureInfo ("nl-BE");
2548 aname.Version = new Version (2, 4, 1, 0);
2549 Assert.IsTrue (cdt.AssertLoad (aname), "#B8");
2551 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B9");
2555 aname = new AssemblyName ();
2556 aname.Name = "multipleC";
2557 aname.CultureInfo = new CultureInfo ("nl-BE");
2558 aname.Version = new Version (2, 4, 0, 0);
2559 aname.KeyPair = new StrongNameKeyPair (keyPair);
2560 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleC.dll"));
2562 Assert.AreEqual (assemblyCount + 5, cdt.AssemblyCount, "#C1");
2564 aname = new AssemblyName ();
2565 aname.Name = "multipleC";
2566 aname.CultureInfo = new CultureInfo ("nl-BE");
2567 aname.Version = new Version (2, 4, 0, 0);
2568 aname.SetPublicKey (publicKey);
2569 Assert.IsTrue (cdt.AssertLoad (aname), "#C2");
2571 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C3");
2573 aname = new AssemblyName ();
2574 aname.Name = "multipleC";
2575 aname.CultureInfo = new CultureInfo ("nl-BE");
2576 aname.Version = new Version (2, 4, 0, 0);
2577 aname.SetPublicKey (publicKey);
2578 Assert.IsTrue (cdt.AssertLoad (aname), "#C4");
2580 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C5");
2582 AppDomain.Unload (ad);
2586 [Test] // bug #79522
2587 [Category ("NotWorking")]
2588 public void Load_Manifest_Mismatch ()
2590 string assemblyFile = Path.Combine (tempDir, "bug79522A.dll");
2591 AssemblyName aname = new AssemblyName ();
2592 aname.Name = "bug79522A";
2593 aname.Version = new Version (2, 4);
2595 GenerateAssembly (aname, assemblyFile);
2597 aname = new AssemblyName ();
2598 aname.CodeBase = assemblyFile;
2599 aname.Name = "whateveryouwant";
2600 aname.Version = new Version (1, 1);
2602 // despite the fact that no assembly with the specified name
2603 // exists, the assembly pointed to by the CodeBase of the
2604 // AssemblyName will be loaded
2606 // however the display name of the loaded assembly does not
2607 // match the display name of the AssemblyName, and as a result
2608 // a FileLoadException is thrown
2610 AppDomain.CurrentDomain.Load (aname);
2611 Assert.Fail ("#A1");
2612 } catch (FileLoadException) {
2615 // if we set CodeBase to some garbage, then we'll get a
2616 // FileNotFoundException instead
2617 aname.CodeBase = "whatever";
2619 AppDomain.CurrentDomain.Load (aname);
2620 Assert.Fail ("#A2");
2621 } catch (FileNotFoundException) {
2624 aname = new AssemblyName ();
2625 aname.Name = "bug79522A";
2626 aname.CodeBase = assemblyFile;
2628 AppDomain.CurrentDomain.Load (aname);
2631 AppDomain.CurrentDomain.Load (aname);
2632 Assert.Fail ("#A3");
2633 } catch (FileLoadException) {
2637 aname = new AssemblyName ();
2638 aname.Name = "bug79522A";
2639 aname.CodeBase = assemblyFile;
2640 aname.Version = new Version (2, 5);
2642 // the version number is not considered when comparing the manifest
2643 // of the assembly found using codebase
2644 AppDomain.CurrentDomain.Load (aname);
2647 AppDomain.CurrentDomain.Load (aname);
2648 Assert.Fail ("#A4");
2649 } catch (FileLoadException) {
2653 aname = new AssemblyName ();
2654 aname.Name = "bug79522A";
2655 aname.CodeBase = assemblyFile;
2656 aname.Version = new Version (2, 4, 1);
2658 // the version number is not considered when comparing the manifest
2659 // of the assembly found using codebase
2660 AppDomain.CurrentDomain.Load (aname);
2663 AppDomain.CurrentDomain.Load (aname);
2664 Assert.Fail ("#A5");
2665 } catch (FileLoadException) {
2669 // if version is set, then culture must also be set
2670 aname = new AssemblyName ();
2671 aname.Name = "bug79522A";
2672 aname.CodeBase = assemblyFile;
2673 aname.Version = new Version (2, 4);
2675 AppDomain.CurrentDomain.Load (aname);
2678 AppDomain.CurrentDomain.Load (aname);
2679 Assert.Fail ("#A6");
2680 } catch (FileLoadException) {
2684 // version number does not need to be set
2685 aname = new AssemblyName ();
2686 aname.Name = "bug79522A";
2687 aname.CodeBase = assemblyFile;
2688 aname.CultureInfo = CultureInfo.InvariantCulture;
2689 AppDomain.CurrentDomain.Load (aname);
2691 // if set, the version number must match exactly
2692 aname = new AssemblyName ();
2693 aname.Name = "bug79522A";
2694 aname.CodeBase = assemblyFile;
2695 aname.CultureInfo = CultureInfo.InvariantCulture;
2696 aname.Version = new Version (2, 4);
2697 AppDomain.CurrentDomain.Load (aname);
2699 // if both culture and version are set, then the version diff
2701 aname = new AssemblyName ();
2702 aname.Name = "bug79522A";
2703 aname.CodeBase = assemblyFile;
2704 aname.CultureInfo = CultureInfo.InvariantCulture;
2705 aname.Version = new Version (2, 5);
2706 AppDomain.CurrentDomain.Load (aname);
2708 // loaded assembly is not signed
2709 aname = new AssemblyName ();
2710 aname.Name = "bug79522A";
2711 aname.CodeBase = assemblyFile;
2712 aname.CultureInfo = CultureInfo.InvariantCulture;
2713 aname.Version = new Version (2, 4);
2714 aname.SetPublicKey (publicKey);
2716 AppDomain.CurrentDomain.Load (aname);
2717 Assert.Fail ("#A7");
2718 } catch (FileLoadException) {
2721 // if set, the culture must match
2722 aname = new AssemblyName ();
2723 aname.Name = "bug79522A";
2724 aname.CodeBase = assemblyFile;
2725 aname.Version = new Version (2, 4);
2726 aname.CultureInfo = new CultureInfo ("en-US");
2728 AppDomain.CurrentDomain.Load (aname);
2729 Assert.Fail ("#A8");
2730 } catch (FileLoadException) {
2735 assemblyFile = Path.Combine (tempDir, "bug79522B.dll");
2736 aname = new AssemblyName ();
2737 aname.Name = "bug79522B";
2738 aname.CultureInfo = new CultureInfo ("nl-BE");
2739 aname.Version = new Version (2, 4, 1);
2741 GenerateAssembly (aname, assemblyFile);
2743 aname = new AssemblyName ();
2744 aname.CodeBase = assemblyFile;
2745 aname.Name = "whateveryouwant";
2746 aname.CultureInfo = new CultureInfo ("nl-BE");
2747 aname.Version = new Version (1, 1);
2749 // despite the fact that no assembly with the specified name
2750 // exists, the assembly pointed to by the CodeBase of the
2751 // AssemblyName will be loaded
2753 // however the display name of the loaded assembly does not
2754 // match the display name of the AssemblyName, and as a result
2755 // a FileLoadException is thrown
2757 AppDomain.CurrentDomain.Load (aname);
2758 Assert.Fail ("#B1");
2759 } catch (FileLoadException) {
2762 // if we set CodeBase to some garbage, then we'll get a
2763 // FileNotFoundException instead
2764 aname.CodeBase = "whatever";
2766 AppDomain.CurrentDomain.Load (aname);
2767 Assert.Fail ("#B2");
2768 } catch (FileNotFoundException) {
2771 aname = new AssemblyName ();
2772 aname.Name = "bug79522B";
2773 aname.CodeBase = assemblyFile;
2775 // the version number is not considered when comparing the manifest
2776 // of the assembly found using codebase
2777 AppDomain.CurrentDomain.Load (aname);
2780 AppDomain.CurrentDomain.Load (aname);
2781 Assert.Fail ("#B3");
2782 } catch (FileLoadException) {
2786 aname = new AssemblyName ();
2787 aname.Name = "bug79522B";
2788 aname.CodeBase = assemblyFile;
2789 aname.Version = new Version (5, 5);
2791 // the version number is not considered when comparing the manifest
2792 // of the assembly found using codebase
2793 AppDomain.CurrentDomain.Load (aname);
2796 AppDomain.CurrentDomain.Load (aname);
2797 Assert.Fail ("#B3");
2798 } catch (FileLoadException) {
2802 aname = new AssemblyName ();
2803 aname.Name = "bug79522B";
2804 aname.CodeBase = assemblyFile;
2805 aname.Version = new Version (2, 4, 1);
2807 AppDomain.CurrentDomain.Load (aname);
2809 // when the loaded assembly has a specific culture, then that
2810 // culture must be set if you set the Version on the aname
2812 AppDomain.CurrentDomain.Load (aname);
2813 Assert.Fail ("#B4");
2814 } catch (FileLoadException) {
2818 // version does not need to be set
2819 aname = new AssemblyName ();
2820 aname.Name = "bug79522B";
2821 aname.CodeBase = assemblyFile;
2822 aname.CultureInfo = new CultureInfo ("nl-BE");
2823 AppDomain.CurrentDomain.Load (aname);
2825 // if both culture and version are set, then the version diff
2827 aname = new AssemblyName ();
2828 aname.Name = "bug79522B";
2829 aname.CodeBase = assemblyFile;
2830 aname.CultureInfo = new CultureInfo ("nl-BE");
2831 aname.Version = new Version (6, 5);
2832 AppDomain.CurrentDomain.Load (aname);
2834 // loaded assembly is not signed
2835 aname = new AssemblyName ();
2836 aname.Name = "bug79522B";
2837 aname.CodeBase = assemblyFile;
2838 aname.CultureInfo = new CultureInfo ("nl-BE");
2839 aname.SetPublicKey (publicKey);
2841 AppDomain.CurrentDomain.Load (aname);
2842 Assert.Fail ("#B5");
2843 } catch (FileLoadException) {
2846 // if set, the culture must match
2847 aname = new AssemblyName ();
2848 aname.Name = "bug79522B";
2849 aname.CodeBase = assemblyFile;
2850 aname.Version = new Version (2, 4, 1);
2851 aname.CultureInfo = new CultureInfo ("en-US");
2853 AppDomain.CurrentDomain.Load (aname);
2854 Assert.Fail ("#B6");
2855 } catch (FileLoadException) {
2860 assemblyFile = Path.Combine (tempDir, "bug79522C.dll");
2861 aname = new AssemblyName ();
2862 aname.Name = "bug79522C";
2863 aname.CultureInfo = new CultureInfo ("nl-BE");
2864 aname.Version = new Version (2, 4);
2865 aname.KeyPair = new StrongNameKeyPair (keyPair);
2867 GenerateAssembly (aname, assemblyFile);
2869 aname = new AssemblyName ();
2870 aname.CodeBase = assemblyFile;
2871 aname.Name = "whateveryouwant";
2872 aname.CultureInfo = new CultureInfo ("nl-BE");
2873 aname.Version = new Version (1, 1);
2874 aname.SetPublicKey (publicKey);
2876 // despite the fact that no assembly with the specified name
2877 // exists, the assembly pointed to by the CodeBase of the
2878 // AssemblyName will be loaded
2880 // however the display name of the loaded assembly does not
2881 // match the display name of the AssemblyName, and as a result
2882 // a FileLoadException is thrown
2884 AppDomain.CurrentDomain.Load (aname);
2885 Assert.Fail ("#C1");
2886 } catch (FileLoadException) {
2889 // if we set CodeBase to some garbage, then we'll get a
2890 // FileNotFoundException instead
2891 aname.CodeBase = "whatever";
2893 AppDomain.CurrentDomain.Load (aname);
2894 Assert.Fail ("#C2");
2895 } catch (FileNotFoundException) {
2898 aname = new AssemblyName ();
2899 aname.Name = "bug79522C";
2900 aname.CodeBase = assemblyFile;
2902 AppDomain.CurrentDomain.Load (aname);
2905 AppDomain.CurrentDomain.Load (aname);
2906 Assert.Fail ("#C3");
2907 } catch (FileLoadException) {
2911 aname = new AssemblyName ();
2912 aname.Name = "bug79522C";
2913 aname.CodeBase = assemblyFile;
2914 aname.Version = new Version (5, 5);
2916 AppDomain.CurrentDomain.Load (aname);
2917 Assert.Fail ("#C3");
2918 } catch (FileLoadException) {
2921 aname = new AssemblyName ();
2922 aname.Name = "bug79522C";
2923 aname.CodeBase = assemblyFile;
2924 aname.Version = new Version (2, 4);
2926 AppDomain.CurrentDomain.Load (aname);
2928 // when the loaded assembly has a specific culture/publickey,
2929 // then that culture/publickey must be set if you set the
2930 // Version on the aname
2932 AppDomain.CurrentDomain.Load (aname);
2933 Assert.Fail ("#C4");
2934 } catch (FileLoadException) {
2938 aname = new AssemblyName ();
2939 aname.Name = "bug79522C";
2940 aname.CodeBase = assemblyFile;
2941 aname.CultureInfo = new CultureInfo ("nl-BE");
2942 aname.Version = new Version (2, 4);
2944 AppDomain.CurrentDomain.Load (aname);
2946 // if loaded assembly is signed, then the public key must be set
2948 AppDomain.CurrentDomain.Load (aname);
2949 Assert.Fail ("#C5");
2950 } catch (FileLoadException) {
2954 aname = new AssemblyName ();
2955 aname.Name = "bug79522C";
2956 aname.CodeBase = assemblyFile;
2957 aname.CultureInfo = new CultureInfo ("nl-BE");
2958 aname.SetPublicKey (publicKey);
2960 AppDomain.CurrentDomain.Load (aname);
2962 // if public key is set, then version must be set
2964 AppDomain.CurrentDomain.Load (aname);
2965 Assert.Fail ("#C6");
2966 } catch (FileLoadException) {
2970 aname = new AssemblyName ();
2971 aname.Name = "bug79522C";
2972 aname.CodeBase = assemblyFile;
2973 aname.CultureInfo = new CultureInfo ("nl-BE");
2975 AppDomain.CurrentDomain.Load (aname);
2978 AppDomain.CurrentDomain.Load (aname);
2979 Assert.Fail ("#C7");
2980 } catch (FileLoadException) {
2984 // if culture and version are set, then the version must match
2985 aname = new AssemblyName ();
2986 aname.Name = "bug79522C";
2987 aname.CodeBase = assemblyFile;
2988 aname.CultureInfo = new CultureInfo ("nl-BE");
2989 aname.SetPublicKey (publicKey);
2990 aname.Version = new Version (5, 6);
2992 AppDomain.CurrentDomain.Load (aname);
2993 Assert.Fail ("#C8");
2994 } catch (FileLoadException) {
2997 // publickey must match
2998 aname = new AssemblyName ();
2999 aname.Name = "bug79522C";
3000 aname.CodeBase = assemblyFile;
3001 aname.CultureInfo = new CultureInfo ("nl-BE");
3002 aname.Version = new Version (2, 4);
3003 aname.SetPublicKey (publicKey2);
3005 AppDomain.CurrentDomain.Load (aname);
3006 Assert.Fail ("#C9");
3007 } catch (SecurityException) {
3008 // Invalid assembly public key
3011 aname = new AssemblyName ();
3012 aname.Name = "bug79522C";
3013 aname.CodeBase = assemblyFile;
3014 aname.SetPublicKey (publicKey);
3015 aname.CultureInfo = new CultureInfo ("nl-BE");
3016 aname.Version = new Version (2, 4);
3017 AppDomain.CurrentDomain.Load (aname);
3020 [Test] // bug #79715
3021 public void Load_PartialVersion ()
3023 AppDomain ad = CreateTestDomain (tempDir, true);
3025 CrossDomainTester cdt = CreateCrossDomainTester (ad);
3027 AssemblyName aname = new AssemblyName ();
3028 aname.Name = "bug79715";
3029 aname.Version = new Version (1, 2, 3, 4);
3030 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "bug79715.dll"));
3032 aname = new AssemblyName ();
3033 aname.Name = "bug79715";
3034 aname.Version = new Version (1, 2);
3035 Assert.IsTrue (cdt.AssertLoad (aname), "#A1");
3036 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#A2");
3038 aname = new AssemblyName ();
3039 aname.Name = "bug79715";
3040 aname.Version = new Version (1, 2, 3);
3041 Assert.IsTrue (cdt.AssertLoad (aname), "#B1");
3042 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#B2");
3044 aname = new AssemblyName ();
3045 aname.Name = "bug79715";
3046 aname.Version = new Version (1, 2, 3, 4);
3047 Assert.IsTrue (cdt.AssertLoad (aname), "#C1");
3048 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#C2");
3050 AppDomain.Unload (ad);
3055 [ExpectedException (typeof (ArgumentException))]
3056 public void Load_EmptyString ()
3058 AppDomain.CurrentDomain.Load ("");
3062 public void SetAppDomainPolicy ()
3064 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
3065 ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
3070 [ExpectedException (typeof (ArgumentNullException))]
3071 public void SetAppDomainPolicy_Null ()
3073 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
3074 ad.SetAppDomainPolicy (null);
3078 [ExpectedException (typeof (PolicyException))]
3079 public void SetAppDomainPolicy_Dual ()
3081 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Dual");
3082 PolicyLevel pl = PolicyLevel.CreateAppDomainLevel ();
3083 PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
3084 pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
3085 ad.SetAppDomainPolicy (pl);
3088 pl = PolicyLevel.CreateAppDomainLevel ();
3089 ps = new PermissionSet (PermissionState.None);
3090 pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
3091 ad.SetAppDomainPolicy (pl);
3095 [ExpectedException (typeof (AppDomainUnloadedException))]
3096 public void SetAppDomainPolicy_Unloaded ()
3098 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Unloaded");
3099 AppDomain.Unload (ad);
3100 ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
3104 [ExpectedException (typeof (ArgumentNullException))]
3105 public void GetData_Null ()
3107 AppDomain.CurrentDomain.GetData (null);
3111 public void SetData ()
3113 AppDomain.CurrentDomain.SetData ("data", "data");
3114 Assert.AreEqual ("data", AppDomain.CurrentDomain.GetData ("data"), "GetData");
3115 AppDomain.CurrentDomain.SetData ("data", null);
3116 Assert.IsNull (AppDomain.CurrentDomain.GetData ("data"), "GetData-Null");
3120 [ExpectedException (typeof (ArgumentNullException))]
3121 public void SetData_Null ()
3123 AppDomain.CurrentDomain.SetData (null, "data");
3128 public void ApplyPolicy ()
3130 ad = AppDomain.CreateDomain ("ApplyPolicy");
3131 string fullname = Assembly.GetExecutingAssembly ().FullName;
3132 string result = ad.ApplyPolicy (fullname);
3133 Assert.AreEqual (fullname, result, "ApplyPolicy");
3134 // doesn't even requires an assembly name
3135 Assert.AreEqual ("123", ad.ApplyPolicy ("123"), "Invalid FullName");
3139 [ExpectedException (typeof (ArgumentException))]
3140 public void ApplyPolicy_Empty ()
3142 ad = AppDomain.CreateDomain ("ApplyPolicy_Empty");
3143 ad.ApplyPolicy (String.Empty);
3147 [ExpectedException (typeof (ArgumentNullException))]
3148 public void ApplyPolicy_Null ()
3150 ad = AppDomain.CreateDomain ("ApplyPolicy_Null");
3151 ad.ApplyPolicy (null);
3155 public void DomainManager ()
3157 Assert.IsNull (AppDomain.CurrentDomain.DomainManager, "CurrentDomain.DomainManager");
3158 ad = AppDomain.CreateDomain ("DomainManager");
3159 Assert.IsNull (ad.DomainManager, "ad.DomainManager");
3163 public void IsDefaultAppDomain ()
3165 ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
3166 Assert.IsFalse (ad.IsDefaultAppDomain (), "IsDefaultAppDomain");
3167 // we have no public way to get the default appdomain
3170 static bool resolve_called;
3173 public void AssemblyResolveParseError ()
3175 AppDomain currentDomain = AppDomain.CurrentDomain;
3176 ResolveEventHandler d = ParseErrorResolve;
3177 currentDomain.AssemblyResolve += d;
3179 resolve_called = false;
3180 var a = Assembly.Load ("MyDynamicType, 1.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
3182 } catch (FileNotFoundException) {
3183 Assert.IsTrue (resolve_called);
3185 currentDomain.AssemblyResolve -= d;
3188 static Assembly ParseErrorResolve (object sender, ResolveEventArgs args)
3190 resolve_called = true;
3195 public void ReflectionOnlyGetAssemblies ()
3197 ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
3198 Assembly [] a = ad.ReflectionOnlyGetAssemblies ();
3199 Assert.IsNotNull (a, "ReflectionOnlyGetAssemblies");
3200 Assert.AreEqual (0, a.Length, "Count");
3202 string assemblyFile = Path.Combine (tempDir, "bug499013.dll");
3203 AssemblyName aname = new AssemblyName ();
3204 aname.Name = "bug499013";
3205 aname.Version = new Version (2, 4);
3207 GenerateAssembly (aname, assemblyFile);
3209 Assembly.ReflectionOnlyLoadFrom (assemblyFile);
3210 foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies ())
3211 Assert.IsTrue (assembly.GetName ().Name != "bug499013");
3215 public void ReflectionOnlyAssemblyResolve ()
3217 AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
3218 Assembly asm = Assembly.ReflectionOnlyLoad(Assembly.LoadWithPartialName("System").FullName);
3223 public void ResourceResolve ()
3225 bool called = false;
3227 ResolveEventHandler del = delegate (object sender, ResolveEventArgs args) {
3231 AppDomain.CurrentDomain.ResourceResolve += del;
3232 Stream st = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("NOT_EXISTING");
3233 Assert.IsTrue (called);
3234 AppDomain.CurrentDomain.ResourceResolve -= del;
3237 private static Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
3239 return Assembly.ReflectionOnlyLoad(args.Name);
3243 public class StuffToPick
3245 public StuffToPick () {}
3246 public void Method () {}
3247 public int Property { get; set; }
3248 public event Action Event;
3250 public void GenericMethod<T> () {}
3253 public class StuffToPick<T>
3255 public StuffToPick () {}
3256 public void Method () {}
3257 public int Property { get; set; }
3258 public event Action Event;
3260 public void GenericMethod<T> () {}
3263 static void TestSerialization (CrossDomainTester tester, object o)
3265 Assert.AreSame (o, tester.ReturnArg0 (o), "serializing_type_" + o.GetType ());
3269 public void ReflectionObjectsAreSerializableTest ()
3271 ad = CreateTestDomain (tempDir, true);
3272 CrossDomainTester tester = CreateCrossDomainTester (ad);
3274 TestSerialization (tester, typeof (StuffToPick));
3275 TestSerialization (tester, typeof (StuffToPick).GetConstructor(new Type [0]));
3276 TestSerialization (tester, typeof (StuffToPick).GetMethod ("Method"));
3277 TestSerialization (tester, typeof (StuffToPick).GetProperty ("Property"));
3278 TestSerialization (tester, typeof (StuffToPick).GetEvent ("Event"));
3279 TestSerialization (tester, typeof (StuffToPick).GetField ("Field"));
3280 TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod"));
3282 TestSerialization (tester, typeof (StuffToPick<>));
3283 TestSerialization (tester, typeof (StuffToPick<>).GetConstructor(new Type [0]));
3284 TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("Method"));
3285 TestSerialization (tester, typeof (StuffToPick<>).GetProperty ("Property"));
3286 TestSerialization (tester, typeof (StuffToPick<>).GetEvent ("Event"));
3287 TestSerialization (tester, typeof (StuffToPick<>).GetField ("Field"));
3288 TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("GenericMethod"));
3290 TestSerialization (tester, typeof (StuffToPick<int>));
3291 TestSerialization (tester, typeof (StuffToPick<int>).GetConstructor(new Type [0]));
3292 TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("Method"));
3293 TestSerialization (tester, typeof (StuffToPick<int>).GetProperty ("Property"));
3294 TestSerialization (tester, typeof (StuffToPick<int>).GetEvent ("Event"));
3295 TestSerialization (tester, typeof (StuffToPick<int>).GetField ("Field"));
3296 TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("GenericMethod"));
3300 [Category ("NotWorking")] // Serialization can't handle generic methods
3301 public void GenericReflectionObjectsAreSerializableTest ()
3303 ad = CreateTestDomain (tempDir, true);
3304 CrossDomainTester tester = CreateCrossDomainTester (ad);
3306 TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)));
3307 TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)));
3308 TestSerialization (tester, typeof (StuffToPick<int>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)));
3312 public void ShadowCopyTypeGetTypeMissingAssemblyTest ()
3314 ad = CreateShadowCopyAppDomain (tempDir, true);
3315 CrossDomainTester tester = CreateCrossDomainTester (ad);
3316 tester.AssertLoadMissingAssemblyType ();
3319 private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
3321 AppDomainSetup setup = new AppDomainSetup ();
3322 setup.ApplicationBase = baseDirectory;
3323 setup.ApplicationName = "testdomain";
3324 return CreateTestDomain (setup, assemblyResolver);
3327 private static AppDomain CreateShadowCopyAppDomain (string baseDirectory, bool assemblyResolver)
3329 AppDomainSetup setup = new AppDomainSetup ();
3330 setup.ApplicationBase = baseDirectory;
3331 setup.ApplicationName = "testdomain";
3332 setup.ShadowCopyFiles = "true";
3333 return CreateTestDomain (setup, assemblyResolver);
3336 private static AppDomain CreateTestDomain (AppDomainSetup setup, bool assemblyResolver)
3338 AppDomain ad = AppDomain.CreateDomain ("testdomain",
3339 AppDomain.CurrentDomain.Evidence, setup);
3341 if (assemblyResolver) {
3342 Assembly ea = Assembly.GetExecutingAssembly ();
3343 ad.CreateInstanceFrom (ea.CodeBase,
3344 typeof (AssemblyResolveHandler).FullName,
3346 BindingFlags.Public | BindingFlags.Instance,
3348 new object [] { ea.Location, ea.FullName },
3349 CultureInfo.InvariantCulture,
3358 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
3360 Type testerType = typeof (CrossDomainTester);
3361 return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
3362 testerType.Assembly.FullName, testerType.FullName, false,
3363 BindingFlags.Public | BindingFlags.Instance, null, new object [0],
3364 CultureInfo.InvariantCulture, new object [0], null);
3367 private static void GenerateAssembly (AssemblyName aname, string path)
3369 AppDomain ad = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory,
3372 CrossDomainTester cdt = CreateCrossDomainTester (ad);
3373 cdt.GenerateAssembly (aname, path);
3375 AppDomain.Unload (ad);
3379 private bool RunningOnUnix {
3381 // check for Unix platforms - see FAQ for more details
3382 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
3383 int platform = (int) Environment.OSVersion.Platform;
3384 return ((platform == 4) || (platform == 128) || (platform == 6));
3388 private class CrossDomainTester : MarshalByRefObject
3390 public void GenerateAssembly (AssemblyName aname, string path)
3392 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
3393 aname, AssemblyBuilderAccess.Save, Path.GetDirectoryName (path));
3394 ab.Save (Path.GetFileName (path));
3397 public int AssemblyCount {
3399 return AppDomain.CurrentDomain.GetAssemblies ().Length;
3403 public string GetApplicationBase ()
3405 return AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
3408 public string GetConfigurationFile ()
3410 return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
3413 public void Load (AssemblyName assemblyRef)
3415 AppDomain.CurrentDomain.Load (assemblyRef);
3418 public void LoadFrom (string assemblyFile)
3420 Assembly.LoadFrom (assemblyFile);
3423 public bool AssertLoad (AssemblyName assemblyRef)
3426 AppDomain.CurrentDomain.Load (assemblyRef);
3433 public bool AssertLoad (string assemblyString)
3436 AppDomain.CurrentDomain.Load (assemblyString);
3443 public void AssertLoadMissingAssemblyType ()
3445 Assert.IsNull (Type.GetType ("A.B.C, MissingAssembly"));
3448 public bool AssertFileLoadException (AssemblyName assemblyRef)
3451 AppDomain.CurrentDomain.Load (assemblyRef);
3453 } catch (FileLoadException) {
3458 public object ReturnArg0 (object obj)
3465 private class AssemblyResolveHandler
3467 public AssemblyResolveHandler (string assemblyFile, string assemblyName)
3469 _assemblyFile = assemblyFile;
3470 _assemblyName = assemblyName;
3472 AppDomain.CurrentDomain.AssemblyResolve +=
3473 new ResolveEventHandler (ResolveAssembly);
3476 private Assembly ResolveAssembly (object sender, ResolveEventArgs args)
3478 if (args.Name == _assemblyName)
3479 return Assembly.LoadFrom (_assemblyFile);
3484 private readonly string _assemblyFile;
3485 private readonly string _assemblyName;
3488 static byte [] keyPair = {
3489 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
3490 0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3D, 0xBD,
3491 0x72, 0x08, 0xC6, 0x2B, 0x0E, 0xA8, 0xC1, 0xC0, 0x58, 0x07, 0x2B,
3492 0x63, 0x5F, 0x7C, 0x9A, 0xBD, 0xCB, 0x22, 0xDB, 0x20, 0xB2, 0xA9,
3493 0xDA, 0xDA, 0xEF, 0xE8, 0x00, 0x64, 0x2F, 0x5D, 0x8D, 0xEB, 0x78,
3494 0x02, 0xF7, 0xA5, 0x36, 0x77, 0x28, 0xD7, 0x55, 0x8D, 0x14, 0x68,
3495 0xDB, 0xEB, 0x24, 0x09, 0xD0, 0x2B, 0x13, 0x1B, 0x92, 0x6E, 0x2E,
3496 0x59, 0x54, 0x4A, 0xAC, 0x18, 0xCF, 0xC9, 0x09, 0x02, 0x3F, 0x4F,
3497 0xA8, 0x3E, 0x94, 0x00, 0x1F, 0xC2, 0xF1, 0x1A, 0x27, 0x47, 0x7D,
3498 0x10, 0x84, 0xF5, 0x14, 0xB8, 0x61, 0x62, 0x1A, 0x0C, 0x66, 0xAB,
3499 0xD2, 0x4C, 0x4B, 0x9F, 0xC9, 0x0F, 0x3C, 0xD8, 0x92, 0x0F, 0xF5,
3500 0xFF, 0xCE, 0xD7, 0x6E, 0x5C, 0x6F, 0xB1, 0xF5, 0x7D, 0xD3, 0x56,
3501 0xF9, 0x67, 0x27, 0xA4, 0xA5, 0x48, 0x5B, 0x07, 0x93, 0x44, 0x00,
3502 0x4A, 0xF8, 0xFF, 0xA4, 0xCB, 0x73, 0xC0, 0x6A, 0x62, 0xB4, 0xB7,
3503 0xC8, 0x92, 0x58, 0x87, 0xCD, 0x07, 0x0C, 0x7D, 0x6C, 0xC1, 0x4A,
3504 0xFC, 0x82, 0x57, 0x0E, 0x43, 0x85, 0x09, 0x75, 0x98, 0x51, 0xBB,
3505 0x35, 0xF5, 0x64, 0x83, 0xC7, 0x79, 0x89, 0x5C, 0x55, 0x36, 0x66,
3506 0xAB, 0x27, 0xA4, 0xD9, 0xD4, 0x7E, 0x6B, 0x67, 0x64, 0xC1, 0x54,
3507 0x4E, 0x37, 0xF1, 0x4E, 0xCA, 0xB3, 0xE5, 0x63, 0x91, 0x57, 0x12,
3508 0x14, 0xA6, 0xEA, 0x8F, 0x8F, 0x2B, 0xFE, 0xF3, 0xE9, 0x16, 0x08,
3509 0x2B, 0x86, 0xBC, 0x26, 0x0D, 0xD0, 0xC6, 0xC4, 0x1A, 0x72, 0x43,
3510 0x76, 0xDC, 0xFF, 0x28, 0x52, 0xA1, 0xDE, 0x8D, 0xFA, 0xD5, 0x1F,
3511 0x0B, 0xB5, 0x4F, 0xAF, 0x06, 0x79, 0x11, 0xEE, 0xA8, 0xEC, 0xD3,
3512 0x74, 0x55, 0xA2, 0x80, 0xFC, 0xF8, 0xD9, 0x50, 0x69, 0x48, 0x01,
3513 0xC2, 0x5A, 0x04, 0x56, 0xB4, 0x3E, 0x24, 0x32, 0x20, 0xB5, 0x2C,
3514 0xDE, 0xBB, 0xBD, 0x13, 0xFD, 0x13, 0xF7, 0x03, 0x3E, 0xE3, 0x37,
3515 0x84, 0x74, 0xE7, 0xD0, 0x5E, 0x9E, 0xB6, 0x26, 0xAE, 0x6E, 0xB0,
3516 0x55, 0x6A, 0x52, 0x63, 0x6F, 0x5A, 0x9D, 0xF2, 0x67, 0xD6, 0x61,
3517 0x4F, 0x7A, 0x45, 0xEE, 0x5C, 0x3D, 0x2B, 0x7C, 0xB2, 0x40, 0x79,
3518 0x54, 0x84, 0xD1, 0xBE, 0x61, 0x3E, 0x5E, 0xD6, 0x18, 0x8E, 0x14,
3519 0x98, 0xFC, 0x35, 0xBF, 0x5F, 0x1A, 0x20, 0x2E, 0x1A, 0xD8, 0xFF,
3520 0xC4, 0x6B, 0xC0, 0xC9, 0x7D, 0x06, 0xEF, 0x09, 0xF9, 0xF3, 0x69,
3521 0xFC, 0xBC, 0xA2, 0xE6, 0x80, 0x22, 0xB9, 0x79, 0x7E, 0xEF, 0x57,
3522 0x9F, 0x49, 0xE1, 0xBC, 0x0D, 0xB6, 0xA1, 0xFE, 0x8D, 0xBC, 0xBB,
3523 0xA3, 0x05, 0x02, 0x6B, 0x04, 0x45, 0xF7, 0x5D, 0xEE, 0x43, 0x06,
3524 0xD6, 0x9C, 0x94, 0x48, 0x1A, 0x0B, 0x9C, 0xBC, 0xB4, 0x4E, 0x93,
3525 0x60, 0x87, 0xCD, 0x58, 0xD6, 0x9A, 0x39, 0xA6, 0xC0, 0x7F, 0x8E,
3526 0xFF, 0x25, 0xC1, 0xD7, 0x2C, 0xF6, 0xF4, 0x6F, 0x24, 0x52, 0x0B,
3527 0x39, 0x42, 0x1B, 0x0D, 0x04, 0xC1, 0x93, 0x2A, 0x19, 0x1C, 0xF0,
3528 0xB1, 0x9B, 0xC1, 0x24, 0x6D, 0x1B, 0x0B, 0xDA, 0x1C, 0x8B, 0x72,
3529 0x48, 0xF0, 0x3E, 0x52, 0xBF, 0x0A, 0x84, 0x3A, 0x9B, 0xC8, 0x6D,
3530 0x13, 0x1E, 0x72, 0xF4, 0x46, 0x93, 0x88, 0x1A, 0x5F, 0x4C, 0x3C,
3531 0xE5, 0x9D, 0x6E, 0xBB, 0x4E, 0xDD, 0x5D, 0x1F, 0x11, 0x40, 0xF4,
3532 0xD7, 0xAF, 0xB3, 0xAB, 0x9A, 0x99, 0x15, 0xF0, 0xDC, 0xAA, 0xFF,
3533 0x9F, 0x2D, 0x9E, 0x56, 0x4F, 0x35, 0x5B, 0xBA, 0x06, 0x99, 0xEA,
3534 0xC6, 0xB4, 0x48, 0x51, 0x17, 0x1E, 0xD1, 0x95, 0x84, 0x81, 0x18,
3535 0xC0, 0xF1, 0x71, 0xDE, 0x44, 0x42, 0x02, 0x06, 0xAC, 0x0E, 0xA8,
3536 0xE2, 0xF3, 0x1F, 0x96, 0x1F, 0xBE, 0xB6, 0x1F, 0xB5, 0x3E, 0xF6,
3537 0x81, 0x05, 0x20, 0xFA, 0x2E, 0x40, 0x2E, 0x4D, 0xA0, 0x0E, 0xDA,
3538 0x42, 0x9C, 0x05, 0xAA, 0x9E, 0xAF, 0x5C, 0xF7, 0x3A, 0x3F, 0xBB,
3539 0x91, 0x73, 0x45, 0x27, 0xA8, 0xA2, 0x07, 0x4A, 0xEF, 0x59, 0x1E,
3540 0x97, 0x9D, 0xE0, 0x30, 0x5A, 0x83, 0xCE, 0x1E, 0x57, 0x32, 0x89,
3541 0x43, 0x41, 0x28, 0x7D, 0x14, 0x8D, 0x8B, 0x41, 0x1A, 0x56, 0x76,
3542 0x43, 0xDB, 0x64, 0x86, 0x41, 0x64, 0x8D, 0x4C, 0x91, 0x83, 0x4E,
3545 static byte [] publicKey2 = {
3546 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
3547 0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x7F, 0x7C,
3548 0xEA, 0x4A, 0x28, 0x33, 0xD8, 0x3C, 0x86, 0x90, 0x86, 0x91, 0x11,
3549 0xBB, 0x30, 0x0D, 0x3D, 0x69, 0x04, 0x4C, 0x48, 0xF5, 0x4F, 0xE7,
3550 0x64, 0xA5, 0x82, 0x72, 0x5A, 0x92, 0xC4, 0x3D, 0xC5, 0x90, 0x93,
3551 0x41, 0xC9, 0x1D, 0x34, 0x16, 0x72, 0x2B, 0x85, 0xC1, 0xF3, 0x99,
3552 0x62, 0x07, 0x32, 0x98, 0xB7, 0xE4, 0xFA, 0x75, 0x81, 0x8D, 0x08,
3553 0xB9, 0xFD, 0xDB, 0x00, 0x25, 0x30, 0xC4, 0x89, 0x13, 0xB6, 0x43,
3554 0xE8, 0xCC, 0xBE, 0x03, 0x2E, 0x1A, 0x6A, 0x4D, 0x36, 0xB1, 0xEB,
3555 0x49, 0x26, 0x6C, 0xAB, 0xC4, 0x29, 0xD7, 0x8F, 0x25, 0x11, 0xA4,
3556 0x7C, 0x81, 0x61, 0x97, 0xCB, 0x44, 0x2D, 0x80, 0x49, 0x93, 0x48,
3557 0xA7, 0xC9, 0xAB, 0xDB, 0xCF, 0xA3, 0x34, 0xCB, 0x6B, 0x86, 0xE0,
3558 0x4D, 0x27, 0xFC, 0xA7, 0x4F, 0x36, 0xCA, 0x13, 0x42, 0xD3, 0x83,
3559 0xC4, 0x06, 0x6E, 0x12, 0xE0, 0xA1, 0x3D, 0x9F, 0xA9, 0xEC, 0xD1,
3560 0xC6, 0x08, 0x1B, 0x3D, 0xF5, 0xDB, 0x4C, 0xD4, 0xF0, 0x2C, 0xAA,
3561 0xFC, 0xBA, 0x18, 0x6F, 0x48, 0x7E, 0xB9, 0x47, 0x68, 0x2E, 0xF6,
3562 0x1E, 0x67, 0x1C, 0x7E, 0x0A, 0xCE, 0x10, 0x07, 0xC0, 0x0C, 0xAD,
3563 0x5E, 0xC1, 0x53, 0x70, 0xD5, 0xE7, 0x25, 0xCA, 0x37, 0x5E, 0x49,
3564 0x59, 0xD0, 0x67, 0x2A, 0xBE, 0x92, 0x36, 0x86, 0x8A, 0xBF, 0x3E,
3565 0x17, 0x04, 0xFB, 0x1F, 0x46, 0xC8, 0x10, 0x5C, 0x93, 0x02, 0x43,
3566 0x14, 0x96, 0x6A, 0xD9, 0x87, 0x17, 0x62, 0x7D, 0x3A, 0x45, 0xBE,
3567 0x35, 0xDE, 0x75, 0x0B, 0x2A, 0xCE, 0x7D, 0xF3, 0x19, 0x85, 0x4B,
3568 0x0D, 0x6F, 0x8D, 0x15, 0xA3, 0x60, 0x61, 0x28, 0x55, 0x46, 0xCE,
3569 0x78, 0x31, 0x04, 0x18, 0x3C, 0x56, 0x4A, 0x3F, 0xA4, 0xC9, 0xB1,
3570 0x41, 0xED, 0x22, 0x80, 0xA1, 0xB3, 0xE2, 0xC7, 0x1B, 0x62, 0x85,
3571 0xE4, 0x81, 0x39, 0xCB, 0x1F, 0x95, 0xCC, 0x61, 0x61, 0xDF, 0xDE,
3572 0xF3, 0x05, 0x68, 0xB9, 0x7D, 0x4F, 0xFF, 0xF3, 0xC0, 0x0A, 0x25,
3573 0x62, 0xD9, 0x8A, 0x8A, 0x9E, 0x99, 0x0B, 0xFB, 0x85, 0x27, 0x8D,
3574 0xF6, 0xD4, 0xE1, 0xB9, 0xDE, 0xB4, 0x16, 0xBD, 0xDF, 0x6A, 0x25,
3575 0x9C, 0xAC, 0xCD, 0x91, 0xF7, 0xCB, 0xC1, 0x81, 0x22, 0x0D, 0xF4,
3576 0x7E, 0xEC, 0x0C, 0x84, 0x13, 0x5A, 0x74, 0x59, 0x3F, 0x3E, 0x61,
3577 0x00, 0xD6, 0xB5, 0x4A, 0xA1, 0x04, 0xB5, 0xA7, 0x1C, 0x29, 0xD0,
3578 0xE1, 0x11, 0x19, 0xD7, 0x80, 0x5C, 0xEE, 0x08, 0x15, 0xEB, 0xC9,
3579 0xA8, 0x98, 0xF5, 0xA0, 0xF0, 0x92, 0x2A, 0xB0, 0xD3, 0xC7, 0x8C,
3580 0x8D, 0xBB, 0x88, 0x96, 0x4F, 0x18, 0xF0, 0x8A, 0xF9, 0x31, 0x9E,
3581 0x44, 0x94, 0x75, 0x6F, 0x78, 0x04, 0x10, 0xEC, 0xF3, 0xB0, 0xCE,
3582 0xA0, 0xBE, 0x7B, 0x25, 0xE1, 0xF7, 0x8A, 0xA8, 0xD4, 0x63, 0xC2,
3583 0x65, 0x47, 0xCC, 0x5C, 0xED, 0x7D, 0x8B, 0x07, 0x4D, 0x76, 0x29,
3584 0x53, 0xAC, 0x27, 0x8F, 0x5D, 0x78, 0x56, 0xFA, 0x99, 0x45, 0xA2,
3585 0xCC, 0x65, 0xC4, 0x54, 0x13, 0x9F, 0x38, 0x41, 0x7A, 0x61, 0x0E,
3586 0x0D, 0x34, 0xBC, 0x11, 0xAF, 0xE2, 0xF1, 0x8B, 0xFA, 0x2B, 0x54,
3587 0x6C, 0xA3, 0x6C, 0x09, 0x1F, 0x0B, 0x43, 0x9B, 0x07, 0x95, 0x83,
3588 0x3F, 0x97, 0x99, 0x89, 0xF5, 0x51, 0x41, 0xF6, 0x8E, 0x5D, 0xEF,
3589 0x6D, 0x24, 0x71, 0x41, 0x7A, 0xAF, 0xBE, 0x81, 0x71, 0xAB, 0x76,
3590 0x2F, 0x1A, 0x5A, 0xBA, 0xF3, 0xA6, 0x65, 0x7A, 0x80, 0x50, 0xCE,
3591 0x23, 0xC3, 0xC7, 0x53, 0xB0, 0x7C, 0x97, 0x77, 0x27, 0x70, 0x98,
3592 0xAE, 0xB5, 0x24, 0x66, 0xE1, 0x60, 0x39, 0x41, 0xDA, 0x54, 0x01,
3593 0x64, 0xFB, 0x10, 0x33, 0xCE, 0x8B, 0xBE, 0x27, 0xD4, 0x21, 0x57,
3594 0xCC, 0x0F, 0x1A, 0xC1, 0x3D, 0xF3, 0xCC, 0x39, 0xF0, 0x2F, 0xAE,
3595 0xF1, 0xC0, 0xCD, 0x3B, 0x23, 0x87, 0x49, 0x7E, 0x40, 0x32, 0x6A,
3596 0xD3, 0x96, 0x4A, 0xE5, 0x5E, 0x6E, 0x26, 0xFD, 0x8A, 0xCF, 0x7E,
3597 0xFC, 0x37, 0xDE, 0x39, 0x0C, 0x53, 0x81, 0x75, 0x08, 0xAF, 0x6B,
3598 0x39, 0x6C, 0xFB, 0xC9, 0x79, 0xC0, 0x9B, 0x5F, 0x34, 0x86, 0xB2,
3599 0xDE, 0xC4, 0x19, 0x84, 0x5F, 0x0E, 0xED, 0x9B, 0xB8, 0xD3, 0x17,
3602 static byte [] publicKey = {
3603 0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00,
3604 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53,
3605 0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3d,
3606 0xbd, 0x72, 0x08, 0xc6, 0x2b, 0x0e, 0xa8, 0xc1, 0xc0, 0x58, 0x07,
3607 0x2b, 0x63, 0x5f, 0x7c, 0x9a, 0xbd, 0xcb, 0x22, 0xdb, 0x20, 0xb2,
3608 0xa9, 0xda, 0xda, 0xef, 0xe8, 0x00, 0x64, 0x2f, 0x5d, 0x8d, 0xeb,
3609 0x78, 0x02, 0xf7, 0xa5, 0x36, 0x77, 0x28, 0xd7, 0x55, 0x8d, 0x14,
3610 0x68, 0xdb, 0xeb, 0x24, 0x09, 0xd0, 0x2b, 0x13, 0x1b, 0x92, 0x6e,
3611 0x2e, 0x59, 0x54, 0x4a, 0xac, 0x18, 0xcf, 0xc9, 0x09, 0x02, 0x3f,
3612 0x4f, 0xa8, 0x3e, 0x94, 0x00, 0x1f, 0xc2, 0xf1, 0x1a, 0x27, 0x47,
3613 0x7d, 0x10, 0x84, 0xf5, 0x14, 0xb8, 0x61, 0x62, 0x1a, 0x0c, 0x66,
3614 0xab, 0xd2, 0x4c, 0x4b, 0x9f, 0xc9, 0x0f, 0x3c, 0xd8, 0x92, 0x0f,
3615 0xf5, 0xff, 0xce, 0xd7, 0x6e, 0x5c, 0x6f, 0xb1, 0xf5, 0x7d, 0xd3,
3616 0x56, 0xf9, 0x67, 0x27, 0xa4, 0xa5, 0x48, 0x5b, 0x07, 0x93, 0x44,
3617 0x00, 0x4a, 0xf8, 0xff, 0xa4, 0xcb };
3619 static byte [] pk_token = { 0xce, 0x52, 0x76, 0xd8, 0x68, 0x7e, 0Xc6, 0xdc };