2 // AppDomainTest.cs - NUnit Test Cases for AppDomain
5 // Sebastien Pouliot (sebastien@ximian.com)
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using NUnit.Framework;
31 using System.Collections;
33 using System.Collections.Generic;
35 using System.Configuration.Assemblies;
36 using System.Globalization;
38 using System.Reflection;
39 using System.Reflection.Emit;
40 using System.Runtime.InteropServices;
41 using System.Security;
42 using System.Security.Permissions;
43 using System.Security.Policy;
44 using System.Security.Principal;
46 namespace MonoTests.System
49 public class AppDomainTest
52 private ArrayList files = new ArrayList ();
53 private string tempDir;
58 tempDir = Path.Combine (Path.GetTempPath (), Environment.UserName);
59 tempDir = Path.Combine (tempDir, "MonoTests.System.AppDomainTest");
60 if (!Directory.Exists (tempDir)) {
61 Directory.CreateDirectory (tempDir);
66 public void TearDown ()
70 AppDomain.Unload (ad);
72 } catch { } // do not affect unit test results in TearDown
74 foreach (string fname in files) {
81 public void ConfigurationFile_Relative ()
84 // We use Environment.GetCommandLineArgs () to get the location of
85 // the entry assembly in the default domain (since the default domain
86 // is not exposed by any API)
88 // MS returns a lower-case path in Environment.GetCommandLineArgs ()
89 // and hence we need to perform a case-insensitive comparison
90 // if the Assert involves that path
92 string configFile = "test.config";
93 string appBase = null;
94 string expectedConfigFile = null;
95 string expectedAppBase = null;
97 // do not set ApplicationBase
98 appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
99 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
100 appBase : appBase + Path.DirectorySeparatorChar;
101 expectedConfigFile = Path.Combine (appBase, configFile);
102 AppDomainSetup setup = new AppDomainSetup();
103 setup.ConfigurationFile = configFile;
104 ad = CreateTestDomain (setup, true);
105 CrossDomainTester cdt = CreateCrossDomainTester (ad);
107 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
108 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
110 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
111 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
113 AppDomain.Unload (ad);
115 // set ApplicationBase
116 appBase = Path.GetTempPath ();
117 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
118 appBase : appBase + Path.DirectorySeparatorChar;
119 expectedConfigFile = Path.Combine (appBase, configFile);
120 setup = new AppDomainSetup ();
121 setup.ApplicationBase = appBase;
122 setup.ConfigurationFile = configFile;
123 ad = CreateTestDomain (setup, true);
124 cdt = CreateCrossDomainTester (ad);
125 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
126 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
127 AppDomain.Unload (ad);
131 public void ConfigurationFile_Absolute ()
134 // We use Environment.GetCommandLineArgs () to get the location of
135 // the entry assembly in the default domain (since the default domain
136 // is not exposed by any API)
138 // MS returns a lower-case path in Environment.GetCommandLineArgs ()
139 // and hence on Windows we need to perform a case-insensitive
140 // comparison if the Assert involves that path
142 string configFile = Path.Combine (tempDir, "test.config");
143 string appBase = null;
144 string expectedAppBase = null;
146 // do not set ApplicationBase
147 appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
148 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
149 appBase : appBase + Path.DirectorySeparatorChar;
150 AppDomainSetup setup = new AppDomainSetup ();
151 setup.ConfigurationFile = configFile;
152 ad = CreateTestDomain (setup, true);
153 CrossDomainTester cdt = CreateCrossDomainTester (ad);
154 Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#A1");
156 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
158 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
160 AppDomain.Unload (ad);
162 // set ApplicationBase
163 appBase = Path.GetTempPath ();
164 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
165 appBase : appBase + Path.DirectorySeparatorChar;
166 setup = new AppDomainSetup ();
167 setup.ApplicationBase = appBase;
168 setup.ConfigurationFile = configFile;
169 ad = CreateTestDomain (setup, true);
170 cdt = CreateCrossDomainTester (ad);
171 Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#B1");
172 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
173 AppDomain.Unload (ad);
177 public void ConfigurationFile_Null ()
180 // We use Environment.GetCommandLineArgs () to get the location of
181 // the entry assembly in the default domain (since the default domain
182 // is not exposed by any API)
184 // MS returns a lower-case path in Environment.GetCommandLineArgs ()
185 // and hence we need to perform a case-insensitive comparison
186 // if the Assert involves that path
188 string appBase = null;
189 string expectedAppBase = null;
190 string expectedConfigFile = null;
192 // do not set ApplicationBase
193 appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
194 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
195 appBase : appBase + Path.DirectorySeparatorChar;
196 expectedConfigFile = Environment.GetCommandLineArgs () [0] + ".config";
197 AppDomainSetup setup = new AppDomainSetup ();
198 setup.ConfigurationFile = null;
199 ad = CreateTestDomain (setup, true);
200 CrossDomainTester cdt = CreateCrossDomainTester (ad);
202 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
203 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
205 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
206 Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
208 AppDomain.Unload (ad);
210 // set ApplicationBase
211 appBase = Path.GetTempPath ();
212 expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
213 appBase : appBase + Path.DirectorySeparatorChar;
214 expectedConfigFile = Path.Combine (appBase, Path.GetFileName (Environment.GetCommandLineArgs () [0]) + ".config");
215 setup = new AppDomainSetup ();
216 setup.ApplicationBase = appBase;
217 setup.ConfigurationFile = null;
218 ad = CreateTestDomain (setup, true);
219 cdt = CreateCrossDomainTester (ad);
221 Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
223 Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#B1");
225 Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
226 AppDomain.Unload (ad);
229 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
230 public void DefineDynamicAssembly1_Access_Invalid ()
232 AssemblyName name = new AssemblyName ();
233 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");
251 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
252 name, AssemblyBuilderAccess.Run |
253 (AssemblyBuilderAccess) 666);
254 Assert.IsNotNull (ab, "#1");
258 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
259 public void DefineDynamicAssembly1_Name_InvalidChars ()
261 string [] invalid_char_names = new string [] {
271 AssemblyName name = new AssemblyName ();
273 foreach (string invalid_name in invalid_char_names) {
274 name.Name = invalid_name;
276 AppDomain.CurrentDomain.DefineDynamicAssembly (
278 AssemblyBuilderAccess.Run);
279 Assert.Fail ("#1:" + invalid_name);
280 } catch (ArgumentException ex) {
281 // Assembly names may not begin with whitespace
282 // or contain the characters '/', '\' or ':'
283 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
284 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
285 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
286 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
287 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
288 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
289 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
294 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
295 public void DefineDynamicAssembly1_Name_Null ()
298 AppDomain.CurrentDomain.DefineDynamicAssembly (
300 AssemblyBuilderAccess.Run);
302 } catch (ArgumentNullException ex) {
303 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
304 Assert.IsNull (ex.InnerException, "#A3");
305 Assert.IsNotNull (ex.Message, "#A4");
306 Assert.IsNotNull (ex.ParamName, "#A5");
307 Assert.AreEqual ("name", ex.ParamName, "#A6");
310 AssemblyName name = new AssemblyName ();
313 AppDomain.CurrentDomain.DefineDynamicAssembly (
315 AssemblyBuilderAccess.Run);
317 } catch (ArgumentException ex) {
318 // AssemblyName.Name cannot be null or an empty string
319 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
320 Assert.IsNull (ex.InnerException, "#B3");
321 Assert.IsNotNull (ex.Message, "#B4");
322 Assert.IsNull (ex.ParamName, "#B5");
325 name.Name = string.Empty;
328 AppDomain.CurrentDomain.DefineDynamicAssembly (
330 AssemblyBuilderAccess.Run);
332 } catch (ArgumentException ex) {
333 // AssemblyName.Name cannot be null or an empty string
334 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
335 Assert.IsNull (ex.InnerException, "#C3");
336 Assert.IsNotNull (ex.Message, "#C4");
337 Assert.IsNull (ex.ParamName, "#C5");
341 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
342 public void DefineDynamicAssembly2_Access_Invalid ()
344 AssemblyName name = new AssemblyName ();
345 name.Name = "DefineDynamicAssembly2";
349 AppDomain.CurrentDomain.DefineDynamicAssembly (
350 name, AssemblyBuilderAccess.Run |
351 (AssemblyBuilderAccess) 666,
352 AppDomain.CurrentDomain.Evidence);
354 } catch (ArgumentException ex) {
355 // Illegal enum value: 667
356 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
357 Assert.IsNull (ex.InnerException, "#3");
358 Assert.IsNotNull (ex.Message, "#4");
359 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
360 Assert.IsNotNull (ex.ParamName, "#6");
361 Assert.AreEqual ("access", ex.ParamName, "#7");
364 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
365 name, AssemblyBuilderAccess.Run |
366 (AssemblyBuilderAccess) 666,
367 AppDomain.CurrentDomain.Evidence);
368 Assert.IsNotNull (ab, "#1");
372 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
373 public void DefineDynamicAssembly2_Name_InvalidChars ()
375 string [] invalid_char_names = new string [] {
385 AssemblyName name = new AssemblyName ();
387 foreach (string invalid_name in invalid_char_names) {
388 name.Name = invalid_name;
390 AppDomain.CurrentDomain.DefineDynamicAssembly (
392 AssemblyBuilderAccess.Run,
393 AppDomain.CurrentDomain.Evidence);
394 Assert.Fail ("#1:" + invalid_name);
395 } catch (ArgumentException ex) {
396 // Assembly names may not begin with whitespace
397 // or contain the characters '/', '\' or ':'
398 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
399 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
400 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
401 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
402 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
403 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
404 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
409 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
410 public void DefineDynamicAssembly2_Name_Null ()
413 AppDomain.CurrentDomain.DefineDynamicAssembly (
415 AssemblyBuilderAccess.Run,
416 AppDomain.CurrentDomain.Evidence);
418 } catch (ArgumentNullException ex) {
419 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
420 Assert.IsNull (ex.InnerException, "#A3");
421 Assert.IsNotNull (ex.Message, "#A4");
422 Assert.IsNotNull (ex.ParamName, "#A5");
423 Assert.AreEqual ("name", ex.ParamName, "#A6");
426 AssemblyName name = new AssemblyName ();
429 AppDomain.CurrentDomain.DefineDynamicAssembly (
431 AssemblyBuilderAccess.Run,
432 AppDomain.CurrentDomain.Evidence);
434 } catch (ArgumentException ex) {
435 // AssemblyName.Name cannot be null or an empty string
436 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
437 Assert.IsNull (ex.InnerException, "#B3");
438 Assert.IsNotNull (ex.Message, "#B4");
439 Assert.IsNull (ex.ParamName, "#B5");
442 name.Name = string.Empty;
445 AppDomain.CurrentDomain.DefineDynamicAssembly (
447 AssemblyBuilderAccess.Run,
448 AppDomain.CurrentDomain.Evidence);
450 } catch (ArgumentException ex) {
451 // AssemblyName.Name cannot be null or an empty string
452 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
453 Assert.IsNull (ex.InnerException, "#C3");
454 Assert.IsNotNull (ex.Message, "#C4");
455 Assert.IsNull (ex.ParamName, "#C5");
459 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
460 public void DefineDynamicAssembly3_Access_Invalid ()
462 AssemblyName name = new AssemblyName ();
463 name.Name = "DefineDynamicAssembly3";
467 AppDomain.CurrentDomain.DefineDynamicAssembly (
468 name, AssemblyBuilderAccess.Run |
469 (AssemblyBuilderAccess) 666,
470 Path.GetTempPath ());
472 } catch (ArgumentException ex) {
473 // Illegal enum value: 667
474 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
475 Assert.IsNull (ex.InnerException, "#3");
476 Assert.IsNotNull (ex.Message, "#4");
477 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
478 Assert.IsNotNull (ex.ParamName, "#6");
479 Assert.AreEqual ("access", ex.ParamName, "#7");
482 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
483 name, AssemblyBuilderAccess.Run |
484 (AssemblyBuilderAccess) 666,
485 Path.GetTempPath ());
486 Assert.IsNotNull (ab, "#1");
490 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
491 public void DefineDynamicAssembly3_Name_InvalidChars ()
493 string [] invalid_char_names = new string [] {
503 AssemblyName name = new AssemblyName ();
505 foreach (string invalid_name in invalid_char_names) {
506 name.Name = invalid_name;
508 AppDomain.CurrentDomain.DefineDynamicAssembly (
510 AssemblyBuilderAccess.Run,
511 Path.GetTempPath ());
512 Assert.Fail ("#1:" + invalid_name);
513 } catch (ArgumentException ex) {
514 // Assembly names may not begin with whitespace
515 // or contain the characters '/', '\' or ':'
516 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
517 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
518 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
519 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
520 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
521 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
522 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
527 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
528 public void DefineDynamicAssembly3_Name_Null ()
531 AppDomain.CurrentDomain.DefineDynamicAssembly (
533 AssemblyBuilderAccess.Run,
534 Path.GetTempPath ());
536 } catch (ArgumentNullException ex) {
537 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
538 Assert.IsNull (ex.InnerException, "#A3");
539 Assert.IsNotNull (ex.Message, "#A4");
540 Assert.IsNotNull (ex.ParamName, "#A5");
541 Assert.AreEqual ("name", ex.ParamName, "#A6");
544 AssemblyName name = new AssemblyName ();
547 AppDomain.CurrentDomain.DefineDynamicAssembly (
549 AssemblyBuilderAccess.Run,
550 Path.GetTempPath ());
552 } catch (ArgumentException ex) {
553 // AssemblyName.Name cannot be null or an empty string
554 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
555 Assert.IsNull (ex.InnerException, "#B3");
556 Assert.IsNotNull (ex.Message, "#B4");
557 Assert.IsNull (ex.ParamName, "#B5");
560 name.Name = string.Empty;
563 AppDomain.CurrentDomain.DefineDynamicAssembly (
565 AssemblyBuilderAccess.Run,
566 Path.GetTempPath ());
568 } catch (ArgumentException ex) {
569 // AssemblyName.Name cannot be null or an empty string
570 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
571 Assert.IsNull (ex.InnerException, "#C3");
572 Assert.IsNotNull (ex.Message, "#C4");
573 Assert.IsNull (ex.ParamName, "#C5");
577 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
578 public void DefineDynamicAssembly4_Access_Invalid ()
580 AssemblyName name = new AssemblyName ();
581 name.Name = "DefineDynamicAssembly4";
585 AppDomain.CurrentDomain.DefineDynamicAssembly (
586 name, AssemblyBuilderAccess.Run |
587 (AssemblyBuilderAccess) 666,
589 AppDomain.CurrentDomain.Evidence);
591 } catch (ArgumentException ex) {
592 // Illegal enum value: 667
593 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
594 Assert.IsNull (ex.InnerException, "#3");
595 Assert.IsNotNull (ex.Message, "#4");
596 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
597 Assert.IsNotNull (ex.ParamName, "#6");
598 Assert.AreEqual ("access", ex.ParamName, "#7");
601 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
602 name, AssemblyBuilderAccess.Run |
603 (AssemblyBuilderAccess) 666,
605 AppDomain.CurrentDomain.Evidence);
606 Assert.IsNotNull (ab, "#1");
610 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
611 public void DefineDynamicAssembly4_Name_InvalidChars ()
613 string [] invalid_char_names = new string [] {
623 AssemblyName name = new AssemblyName ();
625 foreach (string invalid_name in invalid_char_names) {
626 name.Name = invalid_name;
628 AppDomain.CurrentDomain.DefineDynamicAssembly (
630 AssemblyBuilderAccess.Run,
632 AppDomain.CurrentDomain.Evidence);
633 Assert.Fail ("#1:" + invalid_name);
634 } catch (ArgumentException ex) {
635 // Assembly names may not begin with whitespace
636 // or contain the characters '/', '\' or ':'
637 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
638 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
639 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
640 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
641 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
642 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
643 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
648 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
649 public void DefineDynamicAssembly4_Name_Null ()
652 AppDomain.CurrentDomain.DefineDynamicAssembly (
654 AssemblyBuilderAccess.Run,
656 AppDomain.CurrentDomain.Evidence);
658 } catch (ArgumentNullException ex) {
659 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
660 Assert.IsNull (ex.InnerException, "#A3");
661 Assert.IsNotNull (ex.Message, "#A4");
662 Assert.IsNotNull (ex.ParamName, "#A5");
663 Assert.AreEqual ("name", ex.ParamName, "#A6");
666 AssemblyName name = new AssemblyName ();
669 AppDomain.CurrentDomain.DefineDynamicAssembly (
671 AssemblyBuilderAccess.Run,
673 AppDomain.CurrentDomain.Evidence);
675 } catch (ArgumentException ex) {
676 // AssemblyName.Name cannot be null or an empty string
677 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
678 Assert.IsNull (ex.InnerException, "#B3");
679 Assert.IsNotNull (ex.Message, "#B4");
680 Assert.IsNull (ex.ParamName, "#B5");
683 name.Name = string.Empty;
686 AppDomain.CurrentDomain.DefineDynamicAssembly (
688 AssemblyBuilderAccess.Run,
690 AppDomain.CurrentDomain.Evidence);
692 } catch (ArgumentException ex) {
693 // AssemblyName.Name cannot be null or an empty string
694 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
695 Assert.IsNull (ex.InnerException, "#C3");
696 Assert.IsNotNull (ex.Message, "#C4");
697 Assert.IsNull (ex.ParamName, "#C5");
701 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
702 public void DefineDynamicAssembly5_Access_Invalid ()
704 AssemblyName name = new AssemblyName ();
705 name.Name = "DefineDynamicAssembly5";
709 AppDomain.CurrentDomain.DefineDynamicAssembly (
710 name, AssemblyBuilderAccess.Run |
711 (AssemblyBuilderAccess) 666,
712 (PermissionSet) null,
713 (PermissionSet) null,
714 (PermissionSet) null);
716 } catch (ArgumentException ex) {
717 // Illegal enum value: 667
718 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
719 Assert.IsNull (ex.InnerException, "#3");
720 Assert.IsNotNull (ex.Message, "#4");
721 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
722 Assert.IsNotNull (ex.ParamName, "#6");
723 Assert.AreEqual ("access", ex.ParamName, "#7");
726 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
727 name, AssemblyBuilderAccess.Run |
728 (AssemblyBuilderAccess) 666,
729 (PermissionSet) null,
730 (PermissionSet) null,
731 (PermissionSet) null);
732 Assert.IsNotNull (ab, "#1");
736 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
737 public void DefineDynamicAssembly5_Name_InvalidChars ()
739 string [] invalid_char_names = new string [] {
749 AssemblyName name = new AssemblyName ();
751 foreach (string invalid_name in invalid_char_names) {
752 name.Name = invalid_name;
754 AppDomain.CurrentDomain.DefineDynamicAssembly (
756 AssemblyBuilderAccess.Run,
757 (PermissionSet) null,
758 (PermissionSet) null,
759 (PermissionSet) null);
760 Assert.Fail ("#1:" + invalid_name);
761 } catch (ArgumentException ex) {
762 // Assembly names may not begin with whitespace
763 // or contain the characters '/', '\' or ':'
764 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
765 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
766 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
767 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
768 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
769 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
770 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
775 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
776 public void DefineDynamicAssembly5_Name_Null ()
779 AppDomain.CurrentDomain.DefineDynamicAssembly (
781 AssemblyBuilderAccess.Run,
782 (PermissionSet) null,
783 (PermissionSet) null,
784 (PermissionSet) null);
786 } catch (ArgumentNullException ex) {
787 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
788 Assert.IsNull (ex.InnerException, "#A3");
789 Assert.IsNotNull (ex.Message, "#A4");
790 Assert.IsNotNull (ex.ParamName, "#A5");
791 Assert.AreEqual ("name", ex.ParamName, "#A6");
794 AssemblyName name = new AssemblyName ();
797 AppDomain.CurrentDomain.DefineDynamicAssembly (
799 AssemblyBuilderAccess.Run,
800 (PermissionSet) null,
801 (PermissionSet) null,
802 (PermissionSet) null);
804 } catch (ArgumentException ex) {
805 // AssemblyName.Name cannot be null or an empty string
806 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
807 Assert.IsNull (ex.InnerException, "#B3");
808 Assert.IsNotNull (ex.Message, "#B4");
809 Assert.IsNull (ex.ParamName, "#B5");
812 name.Name = string.Empty;
815 AppDomain.CurrentDomain.DefineDynamicAssembly (
817 AssemblyBuilderAccess.Run,
818 (PermissionSet) null,
819 (PermissionSet) null,
820 (PermissionSet) null);
822 } catch (ArgumentException ex) {
823 // AssemblyName.Name cannot be null or an empty string
824 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
825 Assert.IsNull (ex.InnerException, "#C3");
826 Assert.IsNotNull (ex.Message, "#C4");
827 Assert.IsNull (ex.ParamName, "#C5");
831 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
832 public void DefineDynamicAssembly6_Access_Invalid ()
834 AssemblyName name = new AssemblyName ();
835 name.Name = "DefineDynamicAssembly6";
839 AppDomain.CurrentDomain.DefineDynamicAssembly (
840 name, AssemblyBuilderAccess.Run |
841 (AssemblyBuilderAccess) 666,
842 AppDomain.CurrentDomain.Evidence,
843 (PermissionSet) null,
844 (PermissionSet) null,
845 (PermissionSet) null);
847 } catch (ArgumentException ex) {
848 // Illegal enum value: 667
849 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
850 Assert.IsNull (ex.InnerException, "#3");
851 Assert.IsNotNull (ex.Message, "#4");
852 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
853 Assert.IsNotNull (ex.ParamName, "#6");
854 Assert.AreEqual ("access", ex.ParamName, "#7");
857 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
858 name, AssemblyBuilderAccess.Run |
859 (AssemblyBuilderAccess) 666,
860 AppDomain.CurrentDomain.Evidence,
861 (PermissionSet) null,
862 (PermissionSet) null,
863 (PermissionSet) null);
864 Assert.IsNotNull (ab, "#1");
868 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
869 public void DefineDynamicAssembly6_Name_InvalidChars ()
871 string [] invalid_char_names = new string [] {
881 AssemblyName name = new AssemblyName ();
883 foreach (string invalid_name in invalid_char_names) {
884 name.Name = invalid_name;
886 AppDomain.CurrentDomain.DefineDynamicAssembly (
888 AssemblyBuilderAccess.Run,
889 AppDomain.CurrentDomain.Evidence,
890 (PermissionSet) null,
891 (PermissionSet) null,
892 (PermissionSet) null);
893 Assert.Fail ("#1:" + invalid_name);
894 } catch (ArgumentException ex) {
895 // Assembly names may not begin with whitespace
896 // or contain the characters '/', '\' or ':'
897 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
898 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
899 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
900 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
901 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
902 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
903 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
908 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
909 public void DefineDynamicAssembly6_Name_Null ()
912 AppDomain.CurrentDomain.DefineDynamicAssembly (
914 AssemblyBuilderAccess.Run,
915 AppDomain.CurrentDomain.Evidence,
916 (PermissionSet) null,
917 (PermissionSet) null,
918 (PermissionSet) null);
920 } catch (ArgumentNullException ex) {
921 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
922 Assert.IsNull (ex.InnerException, "#A3");
923 Assert.IsNotNull (ex.Message, "#A4");
924 Assert.IsNotNull (ex.ParamName, "#A5");
925 Assert.AreEqual ("name", ex.ParamName, "#A6");
928 AssemblyName name = new AssemblyName ();
931 AppDomain.CurrentDomain.DefineDynamicAssembly (
933 AssemblyBuilderAccess.Run,
934 AppDomain.CurrentDomain.Evidence,
935 (PermissionSet) null,
936 (PermissionSet) null,
937 (PermissionSet) null);
939 } catch (ArgumentException ex) {
940 // AssemblyName.Name cannot be null or an empty string
941 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
942 Assert.IsNull (ex.InnerException, "#B3");
943 Assert.IsNotNull (ex.Message, "#B4");
944 Assert.IsNull (ex.ParamName, "#B5");
947 name.Name = string.Empty;
950 AppDomain.CurrentDomain.DefineDynamicAssembly (
952 AssemblyBuilderAccess.Run,
953 AppDomain.CurrentDomain.Evidence,
954 (PermissionSet) null,
955 (PermissionSet) null,
956 (PermissionSet) null);
958 } catch (ArgumentException ex) {
959 // AssemblyName.Name cannot be null or an empty string
960 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
961 Assert.IsNull (ex.InnerException, "#C3");
962 Assert.IsNotNull (ex.Message, "#C4");
963 Assert.IsNull (ex.ParamName, "#C5");
967 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
968 public void DefineDynamicAssembly7_Access_Invalid ()
970 AssemblyName name = new AssemblyName ();
971 name.Name = "DefineDynamicAssembly7";
975 AppDomain.CurrentDomain.DefineDynamicAssembly (
976 name, AssemblyBuilderAccess.Run |
977 (AssemblyBuilderAccess) 666,
979 (PermissionSet) null,
980 (PermissionSet) null,
981 (PermissionSet) null);
983 } catch (ArgumentException ex) {
984 // Illegal enum value: 667
985 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
986 Assert.IsNull (ex.InnerException, "#3");
987 Assert.IsNotNull (ex.Message, "#4");
988 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
989 Assert.IsNotNull (ex.ParamName, "#6");
990 Assert.AreEqual ("access", ex.ParamName, "#7");
993 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
994 name, AssemblyBuilderAccess.Run |
995 (AssemblyBuilderAccess) 666,
997 (PermissionSet) null,
998 (PermissionSet) null,
999 (PermissionSet) null);
1000 Assert.IsNotNull (ab, "#1");
1004 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
1005 public void DefineDynamicAssembly7_Name_InvalidChars ()
1007 string [] invalid_char_names = new string [] {
1017 AssemblyName name = new AssemblyName ();
1019 foreach (string invalid_name in invalid_char_names) {
1020 name.Name = invalid_name;
1022 AppDomain.CurrentDomain.DefineDynamicAssembly (
1024 AssemblyBuilderAccess.Run,
1025 Path.GetTempPath (),
1026 (PermissionSet) null,
1027 (PermissionSet) null,
1028 (PermissionSet) null);
1029 Assert.Fail ("#1:" + invalid_name);
1030 } catch (ArgumentException ex) {
1031 // Assembly names may not begin with whitespace
1032 // or contain the characters '/', '\' or ':'
1033 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1034 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1035 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1036 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1037 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1038 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1039 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1044 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
1045 public void DefineDynamicAssembly7_Name_Null ()
1048 AppDomain.CurrentDomain.DefineDynamicAssembly (
1049 (AssemblyName) null,
1050 AssemblyBuilderAccess.Run,
1051 Path.GetTempPath (),
1052 (PermissionSet) null,
1053 (PermissionSet) null,
1054 (PermissionSet) null);
1055 Assert.Fail ("#A1");
1056 } catch (ArgumentNullException ex) {
1057 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1058 Assert.IsNull (ex.InnerException, "#A3");
1059 Assert.IsNotNull (ex.Message, "#A4");
1060 Assert.IsNotNull (ex.ParamName, "#A5");
1061 Assert.AreEqual ("name", ex.ParamName, "#A6");
1064 AssemblyName name = new AssemblyName ();
1067 AppDomain.CurrentDomain.DefineDynamicAssembly (
1069 AssemblyBuilderAccess.Run,
1070 Path.GetTempPath (),
1071 (PermissionSet) null,
1072 (PermissionSet) null,
1073 (PermissionSet) null);
1074 Assert.Fail ("#B1");
1075 } catch (ArgumentException ex) {
1076 // AssemblyName.Name cannot be null or an empty string
1077 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1078 Assert.IsNull (ex.InnerException, "#B3");
1079 Assert.IsNotNull (ex.Message, "#B4");
1080 Assert.IsNull (ex.ParamName, "#B5");
1083 name.Name = string.Empty;
1086 AppDomain.CurrentDomain.DefineDynamicAssembly (
1088 AssemblyBuilderAccess.Run,
1089 Path.GetTempPath (),
1090 (PermissionSet) null,
1091 (PermissionSet) null,
1092 (PermissionSet) null);
1093 Assert.Fail ("#C1");
1094 } catch (ArgumentException ex) {
1095 // AssemblyName.Name cannot be null or an empty string
1096 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1097 Assert.IsNull (ex.InnerException, "#C3");
1098 Assert.IsNotNull (ex.Message, "#C4");
1099 Assert.IsNull (ex.ParamName, "#C5");
1103 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
1104 public void DefineDynamicAssembly8_Access_Invalid ()
1106 AssemblyName name = new AssemblyName ();
1107 name.Name = "DefineDynamicAssembly8";
1111 AppDomain.CurrentDomain.DefineDynamicAssembly (
1112 name, AssemblyBuilderAccess.Run |
1113 (AssemblyBuilderAccess) 666,
1114 Path.GetTempPath (),
1115 AppDomain.CurrentDomain.Evidence,
1116 (PermissionSet) null,
1117 (PermissionSet) null,
1118 (PermissionSet) null);
1120 } catch (ArgumentException ex) {
1121 // Illegal enum value: 667
1122 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1123 Assert.IsNull (ex.InnerException, "#3");
1124 Assert.IsNotNull (ex.Message, "#4");
1125 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1126 Assert.IsNotNull (ex.ParamName, "#6");
1127 Assert.AreEqual ("access", ex.ParamName, "#7");
1130 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1131 name, AssemblyBuilderAccess.Run |
1132 (AssemblyBuilderAccess) 666,
1133 Path.GetTempPath (),
1134 AppDomain.CurrentDomain.Evidence,
1135 (PermissionSet) null,
1136 (PermissionSet) null,
1137 (PermissionSet) null);
1138 Assert.IsNotNull (ab, "#1");
1142 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
1143 public void DefineDynamicAssembly8_Name_InvalidChars ()
1145 string [] invalid_char_names = new string [] {
1155 AssemblyName name = new AssemblyName ();
1157 foreach (string invalid_name in invalid_char_names) {
1158 name.Name = invalid_name;
1160 AppDomain.CurrentDomain.DefineDynamicAssembly (
1162 AssemblyBuilderAccess.Run,
1163 Path.GetTempPath (),
1164 AppDomain.CurrentDomain.Evidence,
1165 (PermissionSet) null,
1166 (PermissionSet) null,
1167 (PermissionSet) null);
1168 Assert.Fail ("#1:" + invalid_name);
1169 } catch (ArgumentException ex) {
1170 // Assembly names may not begin with whitespace
1171 // or contain the characters '/', '\' or ':'
1172 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1173 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1174 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1175 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1176 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1177 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1178 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1183 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
1184 public void DefineDynamicAssembly8_Name_Null ()
1187 AppDomain.CurrentDomain.DefineDynamicAssembly (
1188 (AssemblyName) null,
1189 AssemblyBuilderAccess.Run,
1190 Path.GetTempPath (),
1191 AppDomain.CurrentDomain.Evidence,
1192 (PermissionSet) null,
1193 (PermissionSet) null,
1194 (PermissionSet) null);
1195 Assert.Fail ("#A1");
1196 } catch (ArgumentNullException ex) {
1197 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1198 Assert.IsNull (ex.InnerException, "#A3");
1199 Assert.IsNotNull (ex.Message, "#A4");
1200 Assert.IsNotNull (ex.ParamName, "#A5");
1201 Assert.AreEqual ("name", ex.ParamName, "#A6");
1204 AssemblyName name = new AssemblyName ();
1207 AppDomain.CurrentDomain.DefineDynamicAssembly (
1209 AssemblyBuilderAccess.Run,
1210 Path.GetTempPath (),
1211 AppDomain.CurrentDomain.Evidence,
1212 (PermissionSet) null,
1213 (PermissionSet) null,
1214 (PermissionSet) null);
1215 Assert.Fail ("#B1");
1216 } catch (ArgumentException ex) {
1217 // AssemblyName.Name cannot be null or an empty string
1218 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1219 Assert.IsNull (ex.InnerException, "#B3");
1220 Assert.IsNotNull (ex.Message, "#B4");
1221 Assert.IsNull (ex.ParamName, "#B5");
1224 name.Name = string.Empty;
1227 AppDomain.CurrentDomain.DefineDynamicAssembly (
1229 AssemblyBuilderAccess.Run,
1230 Path.GetTempPath (),
1231 AppDomain.CurrentDomain.Evidence,
1232 (PermissionSet) null,
1233 (PermissionSet) null,
1234 (PermissionSet) null);
1235 Assert.Fail ("#C1");
1236 } catch (ArgumentException ex) {
1237 // AssemblyName.Name cannot be null or an empty string
1238 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1239 Assert.IsNull (ex.InnerException, "#C3");
1240 Assert.IsNotNull (ex.Message, "#C4");
1241 Assert.IsNull (ex.ParamName, "#C5");
1245 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
1246 public void DefineDynamicAssembly9_Access_Invalid ()
1248 AssemblyName name = new AssemblyName ();
1249 name.Name = "DefineDynamicAssembly9";
1253 AppDomain.CurrentDomain.DefineDynamicAssembly (
1254 name, AssemblyBuilderAccess.Run |
1255 (AssemblyBuilderAccess) 666,
1256 Path.GetTempPath (),
1257 AppDomain.CurrentDomain.Evidence,
1258 (PermissionSet) null,
1259 (PermissionSet) null,
1260 (PermissionSet) null,
1263 } catch (ArgumentException ex) {
1264 // Illegal enum value: 667
1265 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1266 Assert.IsNull (ex.InnerException, "#3");
1267 Assert.IsNotNull (ex.Message, "#4");
1268 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1269 Assert.IsNotNull (ex.ParamName, "#6");
1270 Assert.AreEqual ("access", ex.ParamName, "#7");
1273 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1274 name, AssemblyBuilderAccess.Run |
1275 (AssemblyBuilderAccess) 666,
1276 Path.GetTempPath (),
1277 AppDomain.CurrentDomain.Evidence,
1278 (PermissionSet) null,
1279 (PermissionSet) null,
1280 (PermissionSet) null,
1282 Assert.IsNotNull (ab, "#1");
1286 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
1287 public void DefineDynamicAssembly9_Name_InvalidChars ()
1289 string [] invalid_char_names = new string [] {
1299 AssemblyName name = new AssemblyName ();
1301 foreach (string invalid_name in invalid_char_names) {
1302 name.Name = invalid_name;
1304 AppDomain.CurrentDomain.DefineDynamicAssembly (
1306 AssemblyBuilderAccess.Run,
1307 Path.GetTempPath (),
1308 AppDomain.CurrentDomain.Evidence,
1309 (PermissionSet) null,
1310 (PermissionSet) null,
1311 (PermissionSet) null,
1313 Assert.Fail ("#1:" + invalid_name);
1314 } catch (ArgumentException ex) {
1315 // Assembly names may not begin with whitespace
1316 // or contain the characters '/', '\' or ':'
1317 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1318 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1319 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1320 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1321 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1322 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1323 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1328 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
1329 public void DefineDynamicAssembly9_Name_Null ()
1332 AppDomain.CurrentDomain.DefineDynamicAssembly (
1333 (AssemblyName) null,
1334 AssemblyBuilderAccess.Run,
1335 Path.GetTempPath (),
1336 AppDomain.CurrentDomain.Evidence,
1337 (PermissionSet) null,
1338 (PermissionSet) null,
1339 (PermissionSet) null,
1341 Assert.Fail ("#A1");
1342 } catch (ArgumentNullException ex) {
1343 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1344 Assert.IsNull (ex.InnerException, "#A3");
1345 Assert.IsNotNull (ex.Message, "#A4");
1346 Assert.IsNotNull (ex.ParamName, "#A5");
1347 Assert.AreEqual ("name", ex.ParamName, "#A6");
1350 AssemblyName name = new AssemblyName ();
1353 AppDomain.CurrentDomain.DefineDynamicAssembly (
1355 AssemblyBuilderAccess.Run,
1356 Path.GetTempPath (),
1357 AppDomain.CurrentDomain.Evidence,
1358 (PermissionSet) null,
1359 (PermissionSet) null,
1360 (PermissionSet) null,
1362 Assert.Fail ("#B1");
1363 } catch (ArgumentException ex) {
1364 // AssemblyName.Name cannot be null or an empty string
1365 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1366 Assert.IsNull (ex.InnerException, "#B3");
1367 Assert.IsNotNull (ex.Message, "#B4");
1368 Assert.IsNull (ex.ParamName, "#B5");
1371 name.Name = string.Empty;
1374 AppDomain.CurrentDomain.DefineDynamicAssembly (
1376 AssemblyBuilderAccess.Run,
1377 Path.GetTempPath (),
1378 AppDomain.CurrentDomain.Evidence,
1379 (PermissionSet) null,
1380 (PermissionSet) null,
1381 (PermissionSet) null,
1383 Assert.Fail ("#C1");
1384 } catch (ArgumentException ex) {
1385 // AssemblyName.Name cannot be null or an empty string
1386 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1387 Assert.IsNull (ex.InnerException, "#C3");
1388 Assert.IsNotNull (ex.Message, "#C4");
1389 Assert.IsNull (ex.ParamName, "#C5");
1394 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1395 public void DefineDynamicAssembly10_Access_Invalid ()
1397 AssemblyName name = new AssemblyName ();
1398 name.Name = "DefineDynamicAssembly10";
1402 AppDomain.CurrentDomain.DefineDynamicAssembly (
1403 name, AssemblyBuilderAccess.Run |
1404 (AssemblyBuilderAccess) 666,
1405 Path.GetTempPath (),
1406 AppDomain.CurrentDomain.Evidence,
1407 (PermissionSet) null,
1408 (PermissionSet) null,
1409 (PermissionSet) null,
1411 new List<CustomAttributeBuilder> ());
1413 } catch (ArgumentException ex) {
1414 // Illegal enum value: 667
1415 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1416 Assert.IsNull (ex.InnerException, "#3");
1417 Assert.IsNotNull (ex.Message, "#4");
1418 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1419 Assert.IsNotNull (ex.ParamName, "#6");
1420 Assert.AreEqual ("access", ex.ParamName, "#7");
1423 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1424 name, AssemblyBuilderAccess.Run |
1425 (AssemblyBuilderAccess) 666,
1426 Path.GetTempPath (),
1427 AppDomain.CurrentDomain.Evidence,
1428 (PermissionSet) null,
1429 (PermissionSet) null,
1430 (PermissionSet) null,
1432 new List<CustomAttributeBuilder> ());
1433 Assert.IsNotNull (ab, "#1");
1437 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1438 public void DefineDynamicAssembly10_Name_InvalidChars ()
1440 string [] invalid_char_names = new string [] {
1450 AssemblyName name = new AssemblyName ();
1452 foreach (string invalid_name in invalid_char_names) {
1453 name.Name = invalid_name;
1455 AppDomain.CurrentDomain.DefineDynamicAssembly (
1457 AssemblyBuilderAccess.Run,
1458 Path.GetTempPath (),
1459 AppDomain.CurrentDomain.Evidence,
1460 (PermissionSet) null,
1461 (PermissionSet) null,
1462 (PermissionSet) null,
1464 new List<CustomAttributeBuilder> ());
1465 Assert.Fail ("#1:" + invalid_name);
1466 } catch (ArgumentException ex) {
1467 // Assembly names may not begin with whitespace
1468 // or contain the characters '/', '\' or ':'
1469 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1470 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1471 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1472 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1473 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1474 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1475 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1480 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1481 public void DefineDynamicAssembly10_Name_Null ()
1484 AppDomain.CurrentDomain.DefineDynamicAssembly (
1485 (AssemblyName) null,
1486 AssemblyBuilderAccess.Run,
1487 Path.GetTempPath (),
1488 AppDomain.CurrentDomain.Evidence,
1489 (PermissionSet) null,
1490 (PermissionSet) null,
1491 (PermissionSet) null,
1493 new List<CustomAttributeBuilder> ());
1494 Assert.Fail ("#A1");
1495 } catch (ArgumentNullException ex) {
1496 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1497 Assert.IsNull (ex.InnerException, "#A3");
1498 Assert.IsNotNull (ex.Message, "#A4");
1499 Assert.IsNotNull (ex.ParamName, "#A5");
1500 Assert.AreEqual ("name", ex.ParamName, "#A6");
1503 AssemblyName name = new AssemblyName ();
1506 AppDomain.CurrentDomain.DefineDynamicAssembly (
1508 AssemblyBuilderAccess.Run,
1509 Path.GetTempPath (),
1510 AppDomain.CurrentDomain.Evidence,
1511 (PermissionSet) null,
1512 (PermissionSet) null,
1513 (PermissionSet) null,
1515 new List<CustomAttributeBuilder> ());
1516 Assert.Fail ("#B1");
1517 } catch (ArgumentException ex) {
1518 // AssemblyName.Name cannot be null or an empty string
1519 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1520 Assert.IsNull (ex.InnerException, "#B3");
1521 Assert.IsNotNull (ex.Message, "#B4");
1522 Assert.IsNull (ex.ParamName, "#B5");
1525 name.Name = string.Empty;
1528 AppDomain.CurrentDomain.DefineDynamicAssembly (
1530 AssemblyBuilderAccess.Run,
1531 Path.GetTempPath (),
1532 AppDomain.CurrentDomain.Evidence,
1533 (PermissionSet) null,
1534 (PermissionSet) null,
1535 (PermissionSet) null,
1537 new List<CustomAttributeBuilder> ());
1538 Assert.Fail ("#C1");
1539 } catch (ArgumentException ex) {
1540 // AssemblyName.Name cannot be null or an empty string
1541 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1542 Assert.IsNull (ex.InnerException, "#C3");
1543 Assert.IsNotNull (ex.Message, "#C4");
1544 Assert.IsNull (ex.ParamName, "#C5");
1548 [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
1549 public void DefineDynamicAssembly11 ()
1551 List<CustomAttributeBuilder> cattrs;
1555 string assemblyFile;
1556 string current_dir = Directory.GetCurrentDirectory ();
1558 name = new AssemblyName ();
1559 name.Name = "DefineDynamicAssembly11A";
1561 cattrs = new List<CustomAttributeBuilder> ();
1562 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).
1563 GetConstructor (new Type [] { typeof (string) }),
1564 new object [] { "1.2.3.4"}));
1565 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).
1566 GetConstructor (new Type [] { typeof (string) }),
1567 new object [] { "nl-BE"}));
1568 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).
1569 GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }),
1570 new object [] { AssemblyHashAlgorithm.MD5 }));
1571 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).
1572 GetConstructor (new Type [] { typeof (uint) }),
1573 new object [] { (uint)0x0100 }));
1574 cattrs.Add (new CustomAttributeBuilder (typeof (CLSCompliantAttribute).
1575 GetConstructor (new Type [] { typeof (bool) }),
1576 new object [] { true }));
1578 ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1579 name, AssemblyBuilderAccess.Save, cattrs);
1581 ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (ComVisibleAttribute).
1582 GetConstructor (new Type [] { typeof (bool) }),
1583 new object [] { true }));
1585 ab.Save ("DefineDynamicAssembly11A.dll");
1587 assemblyFile = Path.Combine (current_dir, "DefineDynamicAssembly11A.dll");
1590 AssemblyName an = AssemblyName.GetAssemblyName (assemblyFile);
1591 Assert.AreEqual (CultureInfo.InvariantCulture, an.CultureInfo, "#A1");
1592 Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#A2");
1593 Assert.AreEqual ("DefineDynamicAssembly11A, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", an.FullName, "#A3");
1594 Assert.IsNull (an.GetPublicKey (), "#A4");
1595 Assert.AreEqual (new byte [0], an.GetPublicKeyToken (), "#A5");
1596 Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "#A6");
1597 Assert.IsNull (an.KeyPair, "#A7");
1598 Assert.AreEqual ("DefineDynamicAssembly11A", an.Name, "#A8");
1599 //Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "#A9");
1600 Assert.AreEqual (an.FullName, an.ToString (), "#A10");
1601 Assert.AreEqual (new Version (0, 0, 0, 0), an.Version, "#A11");
1602 Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, an.VersionCompatibility, "#A12");
1606 using (FileStream fs = File.OpenRead (assemblyFile)) {
1607 byte [] buffer = new byte [fs.Length];
1608 fs.Read (buffer, 0, buffer.Length);
1609 a = Assembly.Load (buffer);
1612 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyVersionAttribute));
1613 Assert.IsNotNull (attr, "#A13a");
1614 Assert.AreEqual ("1.2.3.4", ((AssemblyVersionAttribute) attr).Version, "#A13b");
1615 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyCultureAttribute));
1616 Assert.IsNotNull (attr, "#A14a");
1617 Assert.AreEqual ("nl-BE", ((AssemblyCultureAttribute) attr).Culture, "#A14b");
1618 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyAlgorithmIdAttribute));
1619 Assert.IsNotNull (attr, "#A15a");
1620 Assert.AreEqual ((uint) AssemblyHashAlgorithm.MD5, ((AssemblyAlgorithmIdAttribute) attr).AlgorithmId, "#A15b");
1621 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyFlagsAttribute));
1622 Assert.IsNotNull (attr, "#A16a");
1623 Assert.AreEqual ((uint) 0x0100, ((AssemblyFlagsAttribute) attr).Flags, "#A16b");
1624 attr = Attribute.GetCustomAttribute (a, typeof (CLSCompliantAttribute));
1625 Assert.IsNotNull (attr, "#A17a");
1626 Assert.IsTrue (((CLSCompliantAttribute) attr).IsCompliant, "#A17b");
1627 attr = Attribute.GetCustomAttribute (a, typeof (ComVisibleAttribute));
1628 Assert.IsNotNull (attr, "#A18a");
1629 Assert.IsTrue (((ComVisibleAttribute) attr).Value, "#A18b");
1631 File.Delete (assemblyFile);
1634 name = new AssemblyName ();
1635 name.CultureInfo = new CultureInfo ("fr-BE");
1636 name.KeyPair = new StrongNameKeyPair (keyPair);
1637 name.Name = "DefineDynamicAssembly11B";
1638 name.Version = new Version (3, 2, 4, 1);
1640 cattrs = new List<CustomAttributeBuilder> ();
1641 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).
1642 GetConstructor (new Type [] { typeof (string) }),
1643 new object [] { "1.2.3.4"}));
1644 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).
1645 GetConstructor (new Type [] { typeof (string) }),
1646 new object [] { "nl-BE"}));
1647 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).
1648 GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }),
1649 new object [] { AssemblyHashAlgorithm.MD5 }));
1650 cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).
1651 GetConstructor (new Type [] { typeof (uint) }),
1652 new object [] { (uint)0x0100 }));
1653 cattrs.Add (new CustomAttributeBuilder (typeof (CLSCompliantAttribute).
1654 GetConstructor (new Type [] { typeof (bool) }),
1655 new object [] { true }));
1657 ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1658 name, AssemblyBuilderAccess.Save, cattrs);
1660 ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (ComVisibleAttribute).
1661 GetConstructor (new Type [] { typeof (bool) }),
1662 new object [] { true }));
1664 ab.Save ("DefineDynamicAssembly11B.dll");
1666 assemblyFile = Path.Combine (current_dir, "DefineDynamicAssembly11B.dll");
1669 AssemblyName an = AssemblyName.GetAssemblyName (assemblyFile);
1670 Assert.AreEqual ("fr-BE", an.CultureInfo.Name, "#B1");
1671 Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#B2");
1672 Assert.AreEqual ("DefineDynamicAssembly11B, Version=3.2.4.1, Culture=fr-BE, PublicKeyToken=ce5276d8687ec6dc", an.FullName, "#B3");
1673 Assert.AreEqual (publicKey, an.GetPublicKey (), "#B4");
1674 Assert.AreEqual (pk_token, an.GetPublicKeyToken (), "#B5");
1675 Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "#B6");
1676 Assert.IsNull (an.KeyPair, "#B7");
1677 Assert.AreEqual ("DefineDynamicAssembly11B", an.Name, "#B8");
1678 //Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "#B9");
1679 Assert.AreEqual (an.FullName, an.ToString (), "#B10");
1680 Assert.AreEqual (new Version (3, 2, 4, 1), an.Version, "#B11");
1681 Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, an.VersionCompatibility, "#B12");
1685 using (FileStream fs = File.OpenRead (assemblyFile)) {
1686 byte [] buffer = new byte [fs.Length];
1687 fs.Read (buffer, 0, buffer.Length);
1688 a = Assembly.Load (buffer);
1691 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyVersionAttribute));
1692 Assert.IsNotNull (attr, "#B13a");
1693 Assert.AreEqual ("1.2.3.4", ((AssemblyVersionAttribute) attr).Version, "#B13b");
1694 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyCultureAttribute));
1695 Assert.IsNotNull (attr, "#B14a");
1696 Assert.AreEqual ("nl-BE", ((AssemblyCultureAttribute) attr).Culture, "#B14b");
1697 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyAlgorithmIdAttribute));
1698 Assert.IsNotNull (attr, "#B15a");
1699 Assert.AreEqual ((uint) AssemblyHashAlgorithm.MD5, ((AssemblyAlgorithmIdAttribute) attr).AlgorithmId, "#B15b");
1700 attr = Attribute.GetCustomAttribute (a, typeof (AssemblyFlagsAttribute));
1701 Assert.IsNotNull (attr, "#B16a");
1702 Assert.AreEqual ((uint) 0x0100, ((AssemblyFlagsAttribute) attr).Flags, "#B16b");
1703 attr = Attribute.GetCustomAttribute (a, typeof (CLSCompliantAttribute));
1704 Assert.IsNotNull (attr, "#B17a");
1705 Assert.IsTrue (((CLSCompliantAttribute) attr).IsCompliant, "#B17b");
1706 attr = Attribute.GetCustomAttribute (a, typeof (ComVisibleAttribute));
1707 Assert.IsNotNull (attr, "#B18a");
1708 Assert.IsTrue (((ComVisibleAttribute) attr).Value, "#B18b");
1710 File.Delete (assemblyFile);
1714 [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
1715 public void DefineDynamicAssembly11_Access_Invalid ()
1717 AssemblyName name = new AssemblyName ();
1718 name.Name = "DefineDynamicAssembly11";
1722 AppDomain.CurrentDomain.DefineDynamicAssembly (
1723 name, AssemblyBuilderAccess.Run |
1724 (AssemblyBuilderAccess) 666,
1725 new List<CustomAttributeBuilder> ());
1727 } catch (ArgumentException ex) {
1728 // Illegal enum value: 667
1729 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1730 Assert.IsNull (ex.InnerException, "#3");
1731 Assert.IsNotNull (ex.Message, "#4");
1732 Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
1733 Assert.IsNotNull (ex.ParamName, "#6");
1734 Assert.AreEqual ("access", ex.ParamName, "#7");
1737 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
1738 name, AssemblyBuilderAccess.Run |
1739 (AssemblyBuilderAccess) 666,
1740 new List<CustomAttributeBuilder> ());
1741 Assert.IsNotNull (ab, "#1");
1745 [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
1746 public void DefineDynamicAssembly11_Name_InvalidChars ()
1748 string [] invalid_char_names = new string [] {
1758 AssemblyName name = new AssemblyName ();
1760 foreach (string invalid_name in invalid_char_names) {
1761 name.Name = invalid_name;
1763 AppDomain.CurrentDomain.DefineDynamicAssembly (
1765 AssemblyBuilderAccess.Run,
1766 new List<CustomAttributeBuilder> ());
1767 Assert.Fail ("#1:" + invalid_name);
1768 } catch (ArgumentException ex) {
1769 // Assembly names may not begin with whitespace
1770 // or contain the characters '/', '\' or ':'
1771 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
1772 Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
1773 Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
1774 Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
1775 Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
1776 Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
1777 Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
1782 [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
1783 public void DefineDynamicAssembly11_Name_Null ()
1786 AppDomain.CurrentDomain.DefineDynamicAssembly (
1787 (AssemblyName) null,
1788 AssemblyBuilderAccess.Run,
1789 new List<CustomAttributeBuilder> ());
1790 Assert.Fail ("#A1");
1791 } catch (ArgumentNullException ex) {
1792 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
1793 Assert.IsNull (ex.InnerException, "#A3");
1794 Assert.IsNotNull (ex.Message, "#A4");
1795 Assert.IsNotNull (ex.ParamName, "#A5");
1796 Assert.AreEqual ("name", ex.ParamName, "#A6");
1799 AssemblyName name = new AssemblyName ();
1802 AppDomain.CurrentDomain.DefineDynamicAssembly (
1804 AssemblyBuilderAccess.Run,
1805 new List<CustomAttributeBuilder> ());
1806 Assert.Fail ("#B1");
1807 } catch (ArgumentException ex) {
1808 // AssemblyName.Name cannot be null or an empty string
1809 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1810 Assert.IsNull (ex.InnerException, "#B3");
1811 Assert.IsNotNull (ex.Message, "#B4");
1812 Assert.IsNull (ex.ParamName, "#B5");
1815 name.Name = string.Empty;
1818 AppDomain.CurrentDomain.DefineDynamicAssembly (
1820 AssemblyBuilderAccess.Run,
1821 new List<CustomAttributeBuilder> ());
1822 Assert.Fail ("#C1");
1823 } catch (ArgumentException ex) {
1824 // AssemblyName.Name cannot be null or an empty string
1825 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
1826 Assert.IsNull (ex.InnerException, "#C3");
1827 Assert.IsNotNull (ex.Message, "#C4");
1828 Assert.IsNull (ex.ParamName, "#C5");
1832 [Test] // ExecuteAssemblyByName (String)
1833 public void ExecuteAssemblyByName1_NoEntryPoint ()
1836 AppDomain.CurrentDomain.ExecuteAssemblyByName ("mscorlib");
1838 } catch (MissingMethodException ex) {
1839 // Entry point not found in assembly '...'
1840 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1841 Assert.IsNull (ex.InnerException, "#3");
1842 Assert.IsNotNull (ex.Message, "#4");
1843 Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5");
1847 [Test] // ExecuteAssemblyByName (String, Evidence)
1848 public void ExecuteAssemblyByName2_NoEntryPoint ()
1851 AppDomain.CurrentDomain.ExecuteAssemblyByName (
1852 "mscorlib", (Evidence) null);
1854 } catch (MissingMethodException ex) {
1855 // Entry point not found in assembly '...'
1856 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1857 Assert.IsNull (ex.InnerException, "#3");
1858 Assert.IsNotNull (ex.Message, "#4");
1859 Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5");
1863 [Test] // ExecuteAssemblyByName (String, Evidence, String [])
1864 public void ExecuteAssemblyByName3_NoEntryPoint ()
1867 AppDomain.CurrentDomain.ExecuteAssemblyByName (
1868 "mscorlib", (Evidence) null,
1871 } catch (MissingMethodException ex) {
1872 // Entry point not found in assembly '...'
1873 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1874 Assert.IsNull (ex.InnerException, "#3");
1875 Assert.IsNotNull (ex.Message, "#4");
1876 Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5");
1880 [Test] // ExecuteAssemblyByName (AssemblyName, Evidence, String [])
1881 public void ExecuteAssemblyByName4_NoEntryPoint ()
1883 AssemblyName aname = new AssemblyName ("mscorlib");
1886 AppDomain.CurrentDomain.ExecuteAssemblyByName (
1887 aname, (Evidence) null, new string [0]);
1889 } catch (MissingMethodException ex) {
1890 // Entry point not found in assembly '...'
1891 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
1892 Assert.IsNull (ex.InnerException, "#3");
1893 Assert.IsNotNull (ex.Message, "#4");
1894 Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5");
1900 public void SetThreadPrincipal ()
1902 IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
1903 IPrincipal p = new GenericPrincipal (i, null);
1904 ad = AppDomain.CreateDomain ("SetThreadPrincipal");
1905 ad.SetThreadPrincipal (p);
1909 [ExpectedException (typeof (ArgumentNullException))]
1910 public void SetThreadPrincipalNull ()
1912 AppDomain.CurrentDomain.SetThreadPrincipal (null);
1916 [ExpectedException (typeof (PolicyException))]
1917 public void SetThreadPrincipalTwice ()
1919 IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
1920 IPrincipal p = new GenericPrincipal (i, null);
1921 ad = AppDomain.CreateDomain ("SetThreadPrincipalTwice");
1922 ad.SetThreadPrincipal (p);
1923 // you only live twice (or so James told me ;-)
1924 ad.SetThreadPrincipal (p);
1928 [ExpectedException (typeof (AppDomainUnloadedException))]
1929 public void SetThreadPrincipalUnloaded ()
1931 ad = AppDomain.CreateDomain ("Ximian");
1932 AppDomain.Unload (ad);
1933 IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
1934 IPrincipal p = new GenericPrincipal (i, null);
1935 ad.SetThreadPrincipal (p);
1939 public void SetPrincipalPolicy_NoPrincipal ()
1941 AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
1945 public void SetPrincipalPolicy_UnauthenticatedPrincipal ()
1947 AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.UnauthenticatedPrincipal);
1951 public void SetPrincipalPolicy_WindowsPrincipal ()
1953 AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.WindowsPrincipal);
1957 [ExpectedException (typeof (AppDomainUnloadedException))]
1958 public void SetPrincipalPolicyUnloaded ()
1960 ad = AppDomain.CreateDomain ("Ximian");
1961 AppDomain.Unload (ad);
1962 ad.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
1966 public void CreateDomain_String ()
1968 ad = AppDomain.CreateDomain ("CreateDomain_String");
1969 Assert.IsNotNull (ad.Evidence, "Evidence");
1970 // Evidence are copied (or referenced?) from default app domain
1971 // we can't get default so we use the current (which should have copied the default)
1972 Assert.AreEqual (AppDomain.CurrentDomain.Evidence.Count, ad.Evidence.Count, "Evidence.Count");
1976 [ExpectedException (typeof (ArgumentNullException))]
1977 public void CreateDomain_String_Null ()
1979 ad = AppDomain.CreateDomain (null);
1983 [Category ("NotDotNet")]
1984 public void CreateDomain_StringEvidence ()
1986 Evidence e = new Evidence ();
1987 ad = AppDomain.CreateDomain ("CreateDomain_StringEvidence", e);
1988 Assert.IsNotNull (ad.Evidence, "Evidence");
1989 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
1991 e.AddHost (new Zone (SecurityZone.MyComputer));
1992 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
1993 // evidence isn't copied but referenced
1997 [ExpectedException (typeof (ArgumentNullException))]
1998 public void CreateDomain_StringNullEvidence ()
2000 ad = AppDomain.CreateDomain (null, new Evidence ());
2004 public void CreateDomain_StringEvidenceNull ()
2006 ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceNull", null);
2007 Assert.IsNotNull (ad.Evidence, "Evidence");
2008 // Evidence are copied (or referenced?) from default app domain
2009 // we can't get default so we use the current (which should have copied the default)
2010 Evidence e = AppDomain.CurrentDomain.Evidence;
2011 Assert.AreEqual (e.Count, ad.Evidence.Count, "Evidence.Count-1");
2012 e.AddHost (new Zone (SecurityZone.MyComputer));
2013 Assert.AreEqual (e.Count - 1, ad.Evidence.Count, "Evidence.Count-2");
2014 // evidence are copied
2018 [Category ("NotDotNet")]
2019 public void CreateDomain_StringEvidenceAppDomainSetup ()
2021 Evidence e = new Evidence ();
2022 AppDomainSetup info = new AppDomainSetup ();
2023 info.ApplicationName = "ApplicationName";
2025 ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceAppDomainSetup", e, info);
2026 Assert.IsNotNull (ad.Evidence, "Evidence");
2027 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
2028 Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
2029 Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName);
2031 e.AddHost (new Zone (SecurityZone.MyComputer));
2032 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
2033 // evidence isn't copied but referenced
2037 [ExpectedException (typeof (ArgumentNullException))]
2038 public void CreateDomain_StringNullEvidenceAppDomainSetup ()
2040 AppDomainSetup info = new AppDomainSetup ();
2041 ad = AppDomain.CreateDomain (null, new Evidence (), info);
2045 public void CreateDomain_StringEvidenceNullAppDomainSetup ()
2047 AppDomainSetup info = new AppDomainSetup ();
2048 info.ApplicationName = "ApplicationName";
2049 ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceNullAppDomainSetup", null, info);
2050 Assert.IsNotNull (ad.Evidence, "Evidence");
2051 // Evidence are copied (or referenced?) from default app domain
2052 // we can't get default so we use the current (which should have copied the default)
2053 Assert.AreEqual (AppDomain.CurrentDomain.Evidence.Count, ad.Evidence.Count, "Evidence.Count");
2054 Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName, "ApplicationName-1");
2055 info.ApplicationName = "Test";
2056 Assert.AreEqual ("Test", info.ApplicationName, "ApplicationName-2");
2057 Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName, "ApplicationName-3");
2062 [Category ("NotDotNet")]
2063 public void CreateDomain_StringEvidenceAppDomainSetupNull ()
2065 Evidence e = new Evidence ();
2066 ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceAppDomainSetupNull", e, null);
2067 Assert.IsNotNull (ad.Evidence, "Evidence");
2068 Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
2069 // SetupInformation is copied from default app domain
2070 Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
2073 [Test] // ExecuteAssembly (String)
2074 public void ExecuteAssembly1_NoEntryPoint ()
2076 Assembly assembly = typeof (AppDomainTest).Assembly;
2079 AppDomain.CurrentDomain.ExecuteAssembly (
2083 } catch (MissingMethodException ex) {
2084 // Entry point not found in assembly '...'
2085 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2086 Assert.IsNull (ex.InnerException, "#3");
2087 Assert.IsNotNull (ex.Message, "#4");
2088 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2091 } catch (COMException ex) {
2092 // Unspecified error
2093 Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
2094 Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
2095 Assert.IsNull (ex.InnerException, "#4");
2096 Assert.IsNotNull (ex.Message, "#5");
2101 [Test] // ExecuteAssembly (String, Evidence)
2102 public void ExecuteAssembly2_NoEntryPoint ()
2104 Assembly assembly = typeof (AppDomainTest).Assembly;
2107 AppDomain.CurrentDomain.ExecuteAssembly (
2112 } catch (MissingMethodException ex) {
2113 // Entry point not found in assembly '...'
2114 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2115 Assert.IsNull (ex.InnerException, "#3");
2116 Assert.IsNotNull (ex.Message, "#4");
2117 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2120 } catch (COMException ex) {
2121 // Unspecified error
2122 Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
2123 Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
2124 Assert.IsNull (ex.InnerException, "#4");
2125 Assert.IsNotNull (ex.Message, "#5");
2130 [Test] // ExecuteAssembly (String, Evidence, String [])
2131 public void ExecuteAssembly3_NoEntryPoint ()
2133 Assembly assembly = typeof (AppDomainTest).Assembly;
2136 AppDomain.CurrentDomain.ExecuteAssembly (
2142 } catch (MissingMethodException ex) {
2143 // Entry point not found in assembly '...'
2144 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2145 Assert.IsNull (ex.InnerException, "#3");
2146 Assert.IsNotNull (ex.Message, "#4");
2147 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2150 } catch (COMException ex) {
2151 // Unspecified error
2152 Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
2153 Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
2154 Assert.IsNull (ex.InnerException, "#4");
2155 Assert.IsNotNull (ex.Message, "#5");
2160 [Test] // ExecuteAssembly (String, Evidence, String [], Byte [], AssemblyHashAlgorithm)
2161 [Category ("NotWorking")] // Not implemented
2162 public void ExecuteAssembly4_NoEntryPoint ()
2164 Assembly assembly = typeof (AppDomainTest).Assembly;
2167 AppDomain.CurrentDomain.ExecuteAssembly (
2172 AssemblyHashAlgorithm.SHA1);
2175 } catch (MissingMethodException ex) {
2176 // Entry point not found in assembly '...'
2177 Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
2178 Assert.IsNull (ex.InnerException, "#3");
2179 Assert.IsNotNull (ex.Message, "#4");
2180 Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
2183 } catch (COMException ex) {
2184 // Unspecified error
2185 Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
2186 Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
2187 Assert.IsNull (ex.InnerException, "#4");
2188 Assert.IsNotNull (ex.Message, "#5");
2193 [Test] // bug #79720
2194 [Category ("NotWorking")]
2195 public void Load_Loaded_Ignore ()
2197 int assemblyStartCount = AppDomain.CurrentDomain.GetAssemblies ().Length;
2201 string assemblyFile = Path.Combine (tempDir, "bug79720A.dll");
2202 AssemblyName aname = new AssemblyName ();
2203 aname.Name = "bug79720A";
2204 aname.Version = new Version (2, 4);
2206 GenerateAssembly (aname, assemblyFile);
2208 Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A1");
2210 aname = new AssemblyName ();
2211 aname.Name = "bug79720A";
2213 AppDomain.CurrentDomain.Load (aname);
2214 Assert.Fail ("#A2");
2215 } catch (FileNotFoundException) {
2218 aname = new AssemblyName ();
2219 aname.Name = "bug79720A";
2220 aname.Version = new Version (0, 0, 0, 0);
2222 AppDomain.CurrentDomain.Load (aname);
2223 Assert.Fail ("#A3");
2224 } catch (FileNotFoundException) {
2227 aname = new AssemblyName ();
2228 aname.Name = "bug79720A";
2229 aname.Version = new Version (2, 4);
2231 AppDomain.CurrentDomain.Load (aname);
2232 Assert.Fail ("#A4");
2233 } catch (FileNotFoundException) {
2236 Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A5");
2238 Assembly.LoadFrom (assemblyFile);
2240 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A6");
2242 aname = new AssemblyName ();
2243 aname.Name = "bug79720A";
2245 AppDomain.CurrentDomain.Load (aname);
2246 Assert.Fail ("#A7");
2247 } catch (FileNotFoundException) {
2250 aname = new AssemblyName ();
2251 aname.Name = "bug79720A";
2252 aname.Version = new Version (0, 0, 0, 0);
2254 AppDomain.CurrentDomain.Load (aname);
2255 Assert.Fail ("#A8");
2256 } catch (FileNotFoundException) {
2259 aname = new AssemblyName ();
2260 aname.Name = "bug79720A";
2261 aname.Version = new Version (2, 4);
2263 AppDomain.CurrentDomain.Load (aname);
2264 Assert.Fail ("#A9");
2265 } catch (FileNotFoundException) {
2268 aname = new AssemblyName ();
2269 aname.Name = "bug79720A";
2270 aname.Version = new Version (2, 4);
2271 aname.CultureInfo = CultureInfo.InvariantCulture;
2273 AppDomain.CurrentDomain.Load (aname);
2274 Assert.Fail ("#A10");
2275 } catch (FileNotFoundException) {
2278 aname = new AssemblyName ();
2279 aname.Name = "bug79720A";
2280 aname.Version = new Version (2, 4, 0, 0);
2281 aname.CultureInfo = CultureInfo.InvariantCulture;
2283 AppDomain.CurrentDomain.Load (aname);
2284 Assert.Fail ("#A11");
2285 } catch (FileNotFoundException) {
2288 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A12");
2292 assemblyFile = Path.Combine (tempDir, "bug79720B.dll");
2293 aname = new AssemblyName ();
2294 aname.Name = "bug79720B";
2295 aname.Version = new Version (2, 4, 1);
2296 aname.CultureInfo = new CultureInfo ("nl-BE");
2298 GenerateAssembly (aname, assemblyFile);
2300 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B1");
2302 aname = new AssemblyName ();
2303 aname.Name = "bug79720B";
2305 AppDomain.CurrentDomain.Load (aname);
2306 Assert.Fail ("#B2");
2307 } catch (FileNotFoundException) {
2310 aname = new AssemblyName ();
2311 aname.Name = "bug79720B";
2312 aname.Version = new Version (0, 0, 0, 0);
2314 AppDomain.CurrentDomain.Load (aname);
2315 Assert.Fail ("#B3");
2316 } catch (FileNotFoundException) {
2319 aname = new AssemblyName ();
2320 aname.Name = "bug79720B";
2321 aname.Version = new Version (2, 4, 1);
2323 AppDomain.CurrentDomain.Load (aname);
2324 Assert.Fail ("#B4");
2325 } catch (FileNotFoundException) {
2328 aname = new AssemblyName ();
2329 aname.Name = "bug79720B";
2330 aname.Version = new Version (2, 4, 1);
2331 aname.CultureInfo = new CultureInfo ("nl-BE");
2333 AppDomain.CurrentDomain.Load (aname);
2334 Assert.Fail ("#B5");
2335 } catch (FileNotFoundException) {
2338 Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B6");
2340 Assembly.LoadFrom (assemblyFile);
2342 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B7");
2344 aname = new AssemblyName ();
2345 aname.Name = "bug79720B";
2347 AppDomain.CurrentDomain.Load (aname);
2348 Assert.Fail ("#B8");
2349 } catch (FileNotFoundException) {
2352 aname = new AssemblyName ();
2353 aname.Name = "bug79720B";
2354 aname.Version = new Version (0, 0, 0, 0);
2356 AppDomain.CurrentDomain.Load (aname);
2357 Assert.Fail ("#B9");
2358 } catch (FileNotFoundException) {
2361 aname = new AssemblyName ();
2362 aname.Name = "bug79720B";
2363 aname.Version = new Version (2, 4, 1);
2365 AppDomain.CurrentDomain.Load (aname);
2366 Assert.Fail ("#B10");
2367 } catch (FileNotFoundException) {
2370 aname = new AssemblyName ();
2371 aname.Name = "bug79720B";
2372 aname.Version = new Version (2, 4, 1);
2373 aname.CultureInfo = new CultureInfo ("nl-BE");
2375 AppDomain.CurrentDomain.Load (aname);
2376 Assert.Fail ("#B11");
2377 } catch (FileNotFoundException) {
2380 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B12");
2384 assemblyFile = Path.Combine (tempDir, "bug79720C.dll");
2385 aname = new AssemblyName ();
2386 aname.Name = "bug79720C";
2387 aname.CultureInfo = new CultureInfo ("nl-BE");
2388 aname.Version = new Version (2, 4);
2389 aname.KeyPair = new StrongNameKeyPair (keyPair);
2391 GenerateAssembly (aname, assemblyFile);
2393 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C1");
2395 aname = new AssemblyName ();
2396 aname.Name = "bug79720C";
2398 AppDomain.CurrentDomain.Load (aname);
2399 Assert.Fail ("#C2");
2400 } catch (FileNotFoundException) {
2403 aname = new AssemblyName ();
2404 aname.Name = "bug79720C";
2405 aname.Version = new Version (0, 0, 0, 0);
2407 AppDomain.CurrentDomain.Load (aname);
2408 Assert.Fail ("#C3");
2409 } catch (FileNotFoundException) {
2412 aname = new AssemblyName ();
2413 aname.Name = "bug79720C";
2414 aname.Version = new Version (2, 4, 1);
2416 AppDomain.CurrentDomain.Load (aname);
2417 Assert.Fail ("#C4");
2418 } catch (FileNotFoundException) {
2421 aname = new AssemblyName ();
2422 aname.Name = "bug79720C";
2423 aname.Version = new Version (2, 4, 1);
2424 aname.CultureInfo = new CultureInfo ("nl-BE");
2426 AppDomain.CurrentDomain.Load (aname);
2427 Assert.Fail ("#C5");
2428 } catch (FileNotFoundException) {
2431 aname = new AssemblyName ();
2432 aname.Name = "bug79720C";
2433 aname.Version = new Version (2, 4, 1);
2434 aname.CultureInfo = new CultureInfo ("nl-BE");
2435 aname.SetPublicKey (publicKey);
2437 AppDomain.CurrentDomain.Load (aname);
2438 Assert.Fail ("#C6");
2439 } catch (FileNotFoundException) {
2442 Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C7");
2444 Assembly.LoadFrom (assemblyFile);
2446 Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C8");
2448 aname = new AssemblyName ();
2449 aname.Name = "bug79720C";
2451 AppDomain.CurrentDomain.Load (aname);
2452 Assert.Fail ("#C9");
2453 } catch (FileNotFoundException) {
2456 aname = new AssemblyName ();
2457 aname.Name = "bug79720C";
2458 aname.Version = new Version (0, 0, 0, 0);
2460 AppDomain.CurrentDomain.Load (aname);
2461 Assert.Fail ("#C10");
2462 } catch (FileNotFoundException) {
2465 aname = new AssemblyName ();
2466 aname.Name = "bug79720C";
2467 aname.Version = new Version (2, 4);
2469 AppDomain.CurrentDomain.Load (aname);
2470 Assert.Fail ("#C11");
2471 } catch (FileNotFoundException) {
2474 aname = new AssemblyName ();
2475 aname.Name = "bug79720C";
2476 aname.Version = new Version (2, 4);
2477 aname.CultureInfo = new CultureInfo ("nl-BE");
2479 AppDomain.CurrentDomain.Load (aname);
2480 Assert.Fail ("#C12");
2481 } catch (FileNotFoundException) {
2484 aname = new AssemblyName ();
2485 aname.Name = "bug79720C";
2486 aname.Version = new Version (2, 4);
2487 aname.CultureInfo = new CultureInfo ("nl-BE");
2488 aname.SetPublicKey (publicKey);
2490 AppDomain.CurrentDomain.Load (aname);
2491 Assert.Fail ("#C13");
2492 } catch (FileNotFoundException) {
2495 Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C14");
2499 [Category ("NotWorking")]
2500 public void Load_Loaded_Multiple ()
2502 string cultureDir = Path.Combine (tempDir, "nl-BE");
2503 if (!Directory.Exists (cultureDir))
2504 Directory.CreateDirectory (cultureDir);
2506 AppDomain ad = CreateTestDomain (tempDir, true);
2508 CrossDomainTester cdt = CreateCrossDomainTester (ad);
2510 int assemblyCount = cdt.AssemblyCount;
2514 AssemblyName aname = new AssemblyName ();
2515 aname.Name = "multipleA";
2516 aname.Version = new Version (1, 2, 3, 4);
2517 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "multipleA.dll"));
2519 Assert.AreEqual (assemblyCount + 1, cdt.AssemblyCount, "#A1");
2521 aname = new AssemblyName ();
2522 aname.Name = "multipleA";
2523 Assert.IsTrue (cdt.AssertLoad (aname), "#A2");
2525 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A3");
2527 aname = new AssemblyName ();
2528 aname.Name = "multipleA";
2529 Assert.IsTrue (cdt.AssertLoad (aname), "#A4");
2531 aname = new AssemblyName ();
2532 aname.Name = "multipleA";
2533 aname.CultureInfo = CultureInfo.InvariantCulture;
2534 Assert.IsTrue (cdt.AssertLoad (aname), "#A5");
2536 aname = new AssemblyName ();
2537 aname.Name = "multipleA";
2538 aname.CultureInfo = CultureInfo.InvariantCulture;
2539 Assert.IsTrue (cdt.AssertLoad (aname), "#A6");
2541 aname = new AssemblyName ();
2542 aname.Name = "multipleA";
2543 aname.CultureInfo = CultureInfo.InvariantCulture;
2544 aname.Version = new Version (1, 2, 3, 4);
2545 Assert.IsTrue (cdt.AssertLoad (aname), "#A7");
2547 aname = new AssemblyName ();
2548 aname.Name = "multipleA";
2549 aname.CultureInfo = CultureInfo.InvariantCulture;
2550 aname.Version = new Version (1, 2, 3, 4);
2551 Assert.IsTrue (cdt.AssertLoad (aname), "#A8");
2553 Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A9");
2557 aname = new AssemblyName ();
2558 aname.Name = "multipleB";
2559 aname.CultureInfo = new CultureInfo ("nl-BE");
2560 aname.Version = new Version (2, 4, 1, 0);
2561 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleB.dll"));
2563 Assert.AreEqual (assemblyCount + 3, cdt.AssemblyCount, "#B1");
2565 aname = new AssemblyName ();
2566 aname.Name = "multipleB";
2567 Assert.IsTrue (cdt.AssertLoad (aname), "#B2");
2569 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B3");
2571 aname = new AssemblyName ();
2572 aname.Name = "multipleB";
2573 Assert.IsTrue (cdt.AssertLoad (aname), "#B4");
2575 aname = new AssemblyName ();
2576 aname.Name = "multipleB";
2577 aname.CultureInfo = new CultureInfo ("nl-BE");
2578 Assert.IsTrue (cdt.AssertLoad (aname), "#B5");
2580 aname = new AssemblyName ();
2581 aname.Name = "multipleB";
2582 aname.CultureInfo = new CultureInfo ("nl-BE");
2583 Assert.IsTrue (cdt.AssertLoad (aname), "#B6");
2585 aname = new AssemblyName ();
2586 aname.Name = "multipleB";
2587 aname.CultureInfo = new CultureInfo ("nl-BE");
2588 aname.Version = new Version (2, 4, 1, 0);
2589 Assert.IsTrue (cdt.AssertLoad (aname), "#B7");
2591 aname = new AssemblyName ();
2592 aname.Name = "multipleB";
2593 aname.CultureInfo = new CultureInfo ("nl-BE");
2594 aname.Version = new Version (2, 4, 1, 0);
2595 Assert.IsTrue (cdt.AssertLoad (aname), "#B8");
2597 Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B9");
2601 aname = new AssemblyName ();
2602 aname.Name = "multipleC";
2603 aname.CultureInfo = new CultureInfo ("nl-BE");
2604 aname.Version = new Version (2, 4, 0, 0);
2605 aname.KeyPair = new StrongNameKeyPair (keyPair);
2606 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleC.dll"));
2608 Assert.AreEqual (assemblyCount + 5, cdt.AssemblyCount, "#C1");
2610 aname = new AssemblyName ();
2611 aname.Name = "multipleC";
2612 aname.CultureInfo = new CultureInfo ("nl-BE");
2613 aname.Version = new Version (2, 4, 0, 0);
2614 aname.SetPublicKey (publicKey);
2615 Assert.IsTrue (cdt.AssertLoad (aname), "#C2");
2617 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C3");
2619 aname = new AssemblyName ();
2620 aname.Name = "multipleC";
2621 aname.CultureInfo = new CultureInfo ("nl-BE");
2622 aname.Version = new Version (2, 4, 0, 0);
2623 aname.SetPublicKey (publicKey);
2624 Assert.IsTrue (cdt.AssertLoad (aname), "#C4");
2626 Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C5");
2628 AppDomain.Unload (ad);
2632 [Test] // bug #79522
2633 [Category ("NotWorking")]
2634 public void Load_Manifest_Mismatch ()
2636 string assemblyFile = Path.Combine (tempDir, "bug79522A.dll");
2637 AssemblyName aname = new AssemblyName ();
2638 aname.Name = "bug79522A";
2639 aname.Version = new Version (2, 4);
2641 GenerateAssembly (aname, assemblyFile);
2643 aname = new AssemblyName ();
2644 aname.CodeBase = assemblyFile;
2645 aname.Name = "whateveryouwant";
2646 aname.Version = new Version (1, 1);
2648 // despite the fact that no assembly with the specified name
2649 // exists, the assembly pointed to by the CodeBase of the
2650 // AssemblyName will be loaded
2652 // however the display name of the loaded assembly does not
2653 // match the display name of the AssemblyName, and as a result
2654 // a FileLoadException is thrown
2656 AppDomain.CurrentDomain.Load (aname);
2657 Assert.Fail ("#A1");
2658 } catch (FileLoadException) {
2661 // if we set CodeBase to some garbage, then we'll get a
2662 // FileNotFoundException instead
2663 aname.CodeBase = "whatever";
2665 AppDomain.CurrentDomain.Load (aname);
2666 Assert.Fail ("#A2");
2667 } catch (FileNotFoundException) {
2670 aname = new AssemblyName ();
2671 aname.Name = "bug79522A";
2672 aname.CodeBase = assemblyFile;
2674 AppDomain.CurrentDomain.Load (aname);
2677 AppDomain.CurrentDomain.Load (aname);
2678 Assert.Fail ("#A3");
2679 } catch (FileLoadException) {
2683 aname = new AssemblyName ();
2684 aname.Name = "bug79522A";
2685 aname.CodeBase = assemblyFile;
2686 aname.Version = new Version (2, 5);
2688 // the version number is not considered when comparing the manifest
2689 // of the assembly found using codebase
2690 AppDomain.CurrentDomain.Load (aname);
2693 AppDomain.CurrentDomain.Load (aname);
2694 Assert.Fail ("#A4");
2695 } catch (FileLoadException) {
2699 aname = new AssemblyName ();
2700 aname.Name = "bug79522A";
2701 aname.CodeBase = assemblyFile;
2702 aname.Version = new Version (2, 4, 1);
2704 // the version number is not considered when comparing the manifest
2705 // of the assembly found using codebase
2706 AppDomain.CurrentDomain.Load (aname);
2709 AppDomain.CurrentDomain.Load (aname);
2710 Assert.Fail ("#A5");
2711 } catch (FileLoadException) {
2715 // if version is set, then culture must also be set
2716 aname = new AssemblyName ();
2717 aname.Name = "bug79522A";
2718 aname.CodeBase = assemblyFile;
2719 aname.Version = new Version (2, 4);
2721 AppDomain.CurrentDomain.Load (aname);
2724 AppDomain.CurrentDomain.Load (aname);
2725 Assert.Fail ("#A6");
2726 } catch (FileLoadException) {
2730 // version number does not need to be set
2731 aname = new AssemblyName ();
2732 aname.Name = "bug79522A";
2733 aname.CodeBase = assemblyFile;
2734 aname.CultureInfo = CultureInfo.InvariantCulture;
2735 AppDomain.CurrentDomain.Load (aname);
2737 // if set, the version number must match exactly
2738 aname = new AssemblyName ();
2739 aname.Name = "bug79522A";
2740 aname.CodeBase = assemblyFile;
2741 aname.CultureInfo = CultureInfo.InvariantCulture;
2742 aname.Version = new Version (2, 4);
2743 AppDomain.CurrentDomain.Load (aname);
2745 // if both culture and version are set, then the version diff
2747 aname = new AssemblyName ();
2748 aname.Name = "bug79522A";
2749 aname.CodeBase = assemblyFile;
2750 aname.CultureInfo = CultureInfo.InvariantCulture;
2751 aname.Version = new Version (2, 5);
2752 AppDomain.CurrentDomain.Load (aname);
2754 // loaded assembly is not signed
2755 aname = new AssemblyName ();
2756 aname.Name = "bug79522A";
2757 aname.CodeBase = assemblyFile;
2758 aname.CultureInfo = CultureInfo.InvariantCulture;
2759 aname.Version = new Version (2, 4);
2760 aname.SetPublicKey (publicKey);
2762 AppDomain.CurrentDomain.Load (aname);
2763 Assert.Fail ("#A7");
2764 } catch (FileLoadException) {
2767 // if set, the culture must match
2768 aname = new AssemblyName ();
2769 aname.Name = "bug79522A";
2770 aname.CodeBase = assemblyFile;
2771 aname.Version = new Version (2, 4);
2772 aname.CultureInfo = new CultureInfo ("en-US");
2774 AppDomain.CurrentDomain.Load (aname);
2775 Assert.Fail ("#A8");
2776 } catch (FileLoadException) {
2781 assemblyFile = Path.Combine (tempDir, "bug79522B.dll");
2782 aname = new AssemblyName ();
2783 aname.Name = "bug79522B";
2784 aname.CultureInfo = new CultureInfo ("nl-BE");
2785 aname.Version = new Version (2, 4, 1);
2787 GenerateAssembly (aname, assemblyFile);
2789 aname = new AssemblyName ();
2790 aname.CodeBase = assemblyFile;
2791 aname.Name = "whateveryouwant";
2792 aname.CultureInfo = new CultureInfo ("nl-BE");
2793 aname.Version = new Version (1, 1);
2795 // despite the fact that no assembly with the specified name
2796 // exists, the assembly pointed to by the CodeBase of the
2797 // AssemblyName will be loaded
2799 // however the display name of the loaded assembly does not
2800 // match the display name of the AssemblyName, and as a result
2801 // a FileLoadException is thrown
2803 AppDomain.CurrentDomain.Load (aname);
2804 Assert.Fail ("#B1");
2805 } catch (FileLoadException) {
2808 // if we set CodeBase to some garbage, then we'll get a
2809 // FileNotFoundException instead
2810 aname.CodeBase = "whatever";
2812 AppDomain.CurrentDomain.Load (aname);
2813 Assert.Fail ("#B2");
2814 } catch (FileNotFoundException) {
2817 aname = new AssemblyName ();
2818 aname.Name = "bug79522B";
2819 aname.CodeBase = assemblyFile;
2821 // the version number is not considered when comparing the manifest
2822 // of the assembly found using codebase
2823 AppDomain.CurrentDomain.Load (aname);
2826 AppDomain.CurrentDomain.Load (aname);
2827 Assert.Fail ("#B3");
2828 } catch (FileLoadException) {
2832 aname = new AssemblyName ();
2833 aname.Name = "bug79522B";
2834 aname.CodeBase = assemblyFile;
2835 aname.Version = new Version (5, 5);
2837 // the version number is not considered when comparing the manifest
2838 // of the assembly found using codebase
2839 AppDomain.CurrentDomain.Load (aname);
2842 AppDomain.CurrentDomain.Load (aname);
2843 Assert.Fail ("#B3");
2844 } catch (FileLoadException) {
2848 aname = new AssemblyName ();
2849 aname.Name = "bug79522B";
2850 aname.CodeBase = assemblyFile;
2851 aname.Version = new Version (2, 4, 1);
2853 AppDomain.CurrentDomain.Load (aname);
2855 // when the loaded assembly has a specific culture, then that
2856 // culture must be set if you set the Version on the aname
2858 AppDomain.CurrentDomain.Load (aname);
2859 Assert.Fail ("#B4");
2860 } catch (FileLoadException) {
2864 // version does not need to be set
2865 aname = new AssemblyName ();
2866 aname.Name = "bug79522B";
2867 aname.CodeBase = assemblyFile;
2868 aname.CultureInfo = new CultureInfo ("nl-BE");
2869 AppDomain.CurrentDomain.Load (aname);
2871 // if both culture and version are set, then the version diff
2873 aname = new AssemblyName ();
2874 aname.Name = "bug79522B";
2875 aname.CodeBase = assemblyFile;
2876 aname.CultureInfo = new CultureInfo ("nl-BE");
2877 aname.Version = new Version (6, 5);
2878 AppDomain.CurrentDomain.Load (aname);
2880 // loaded assembly is not signed
2881 aname = new AssemblyName ();
2882 aname.Name = "bug79522B";
2883 aname.CodeBase = assemblyFile;
2884 aname.CultureInfo = new CultureInfo ("nl-BE");
2885 aname.SetPublicKey (publicKey);
2887 AppDomain.CurrentDomain.Load (aname);
2888 Assert.Fail ("#B5");
2889 } catch (FileLoadException) {
2892 // if set, the culture must match
2893 aname = new AssemblyName ();
2894 aname.Name = "bug79522B";
2895 aname.CodeBase = assemblyFile;
2896 aname.Version = new Version (2, 4, 1);
2897 aname.CultureInfo = new CultureInfo ("en-US");
2899 AppDomain.CurrentDomain.Load (aname);
2900 Assert.Fail ("#B6");
2901 } catch (FileLoadException) {
2906 assemblyFile = Path.Combine (tempDir, "bug79522C.dll");
2907 aname = new AssemblyName ();
2908 aname.Name = "bug79522C";
2909 aname.CultureInfo = new CultureInfo ("nl-BE");
2910 aname.Version = new Version (2, 4);
2911 aname.KeyPair = new StrongNameKeyPair (keyPair);
2913 GenerateAssembly (aname, assemblyFile);
2915 aname = new AssemblyName ();
2916 aname.CodeBase = assemblyFile;
2917 aname.Name = "whateveryouwant";
2918 aname.CultureInfo = new CultureInfo ("nl-BE");
2919 aname.Version = new Version (1, 1);
2920 aname.SetPublicKey (publicKey);
2922 // despite the fact that no assembly with the specified name
2923 // exists, the assembly pointed to by the CodeBase of the
2924 // AssemblyName will be loaded
2926 // however the display name of the loaded assembly does not
2927 // match the display name of the AssemblyName, and as a result
2928 // a FileLoadException is thrown
2930 AppDomain.CurrentDomain.Load (aname);
2931 Assert.Fail ("#C1");
2932 } catch (FileLoadException) {
2935 // if we set CodeBase to some garbage, then we'll get a
2936 // FileNotFoundException instead
2937 aname.CodeBase = "whatever";
2939 AppDomain.CurrentDomain.Load (aname);
2940 Assert.Fail ("#C2");
2941 } catch (FileNotFoundException) {
2944 aname = new AssemblyName ();
2945 aname.Name = "bug79522C";
2946 aname.CodeBase = assemblyFile;
2948 AppDomain.CurrentDomain.Load (aname);
2951 AppDomain.CurrentDomain.Load (aname);
2952 Assert.Fail ("#C3");
2953 } catch (FileLoadException) {
2957 aname = new AssemblyName ();
2958 aname.Name = "bug79522C";
2959 aname.CodeBase = assemblyFile;
2960 aname.Version = new Version (5, 5);
2962 AppDomain.CurrentDomain.Load (aname);
2963 Assert.Fail ("#C3");
2964 } catch (FileLoadException) {
2967 aname = new AssemblyName ();
2968 aname.Name = "bug79522C";
2969 aname.CodeBase = assemblyFile;
2970 aname.Version = new Version (2, 4);
2972 AppDomain.CurrentDomain.Load (aname);
2974 // when the loaded assembly has a specific culture/publickey,
2975 // then that culture/publickey must be set if you set the
2976 // Version on the aname
2978 AppDomain.CurrentDomain.Load (aname);
2979 Assert.Fail ("#C4");
2980 } catch (FileLoadException) {
2984 aname = new AssemblyName ();
2985 aname.Name = "bug79522C";
2986 aname.CodeBase = assemblyFile;
2987 aname.CultureInfo = new CultureInfo ("nl-BE");
2988 aname.Version = new Version (2, 4);
2990 AppDomain.CurrentDomain.Load (aname);
2992 // if loaded assembly is signed, then the public key must be set
2994 AppDomain.CurrentDomain.Load (aname);
2995 Assert.Fail ("#C5");
2996 } catch (FileLoadException) {
3000 aname = new AssemblyName ();
3001 aname.Name = "bug79522C";
3002 aname.CodeBase = assemblyFile;
3003 aname.CultureInfo = new CultureInfo ("nl-BE");
3004 aname.SetPublicKey (publicKey);
3006 AppDomain.CurrentDomain.Load (aname);
3008 // if public key is set, then version must be set
3010 AppDomain.CurrentDomain.Load (aname);
3011 Assert.Fail ("#C6");
3012 } catch (FileLoadException) {
3016 aname = new AssemblyName ();
3017 aname.Name = "bug79522C";
3018 aname.CodeBase = assemblyFile;
3019 aname.CultureInfo = new CultureInfo ("nl-BE");
3021 AppDomain.CurrentDomain.Load (aname);
3024 AppDomain.CurrentDomain.Load (aname);
3025 Assert.Fail ("#C7");
3026 } catch (FileLoadException) {
3030 // if culture and version are set, then the version must match
3031 aname = new AssemblyName ();
3032 aname.Name = "bug79522C";
3033 aname.CodeBase = assemblyFile;
3034 aname.CultureInfo = new CultureInfo ("nl-BE");
3035 aname.SetPublicKey (publicKey);
3036 aname.Version = new Version (5, 6);
3038 AppDomain.CurrentDomain.Load (aname);
3039 Assert.Fail ("#C8");
3040 } catch (FileLoadException) {
3043 // publickey must match
3044 aname = new AssemblyName ();
3045 aname.Name = "bug79522C";
3046 aname.CodeBase = assemblyFile;
3047 aname.CultureInfo = new CultureInfo ("nl-BE");
3048 aname.Version = new Version (2, 4);
3049 aname.SetPublicKey (publicKey2);
3051 AppDomain.CurrentDomain.Load (aname);
3052 Assert.Fail ("#C9");
3054 } catch (SecurityException) {
3055 // Invalid assembly public key
3058 } catch (FileLoadException) {
3062 aname = new AssemblyName ();
3063 aname.Name = "bug79522C";
3064 aname.CodeBase = assemblyFile;
3065 aname.SetPublicKey (publicKey);
3066 aname.CultureInfo = new CultureInfo ("nl-BE");
3067 aname.Version = new Version (2, 4);
3068 AppDomain.CurrentDomain.Load (aname);
3071 [Test] // bug #79715
3072 public void Load_PartialVersion ()
3074 AppDomain ad = CreateTestDomain (tempDir, true);
3076 CrossDomainTester cdt = CreateCrossDomainTester (ad);
3078 AssemblyName aname = new AssemblyName ();
3079 aname.Name = "bug79715";
3080 aname.Version = new Version (1, 2, 3, 4);
3081 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "bug79715.dll"));
3083 aname = new AssemblyName ();
3084 aname.Name = "bug79715";
3085 aname.Version = new Version (1, 2);
3086 Assert.IsTrue (cdt.AssertLoad (aname), "#A1");
3087 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#A2");
3089 aname = new AssemblyName ();
3090 aname.Name = "bug79715";
3091 aname.Version = new Version (1, 2, 3);
3092 Assert.IsTrue (cdt.AssertLoad (aname), "#B1");
3093 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#B2");
3095 aname = new AssemblyName ();
3096 aname.Name = "bug79715";
3097 aname.Version = new Version (1, 2, 3, 4);
3098 Assert.IsTrue (cdt.AssertLoad (aname), "#C1");
3099 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#C2");
3101 AppDomain.Unload (ad);
3106 [ExpectedException (typeof (ArgumentException))]
3107 public void Load_EmptyString ()
3109 AppDomain.CurrentDomain.Load ("");
3113 public void SetAppDomainPolicy ()
3115 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
3116 ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
3121 [ExpectedException (typeof (ArgumentNullException))]
3122 public void SetAppDomainPolicy_Null ()
3124 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
3125 ad.SetAppDomainPolicy (null);
3129 [ExpectedException (typeof (PolicyException))]
3130 public void SetAppDomainPolicy_Dual ()
3132 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Dual");
3133 PolicyLevel pl = PolicyLevel.CreateAppDomainLevel ();
3134 PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
3135 pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
3136 ad.SetAppDomainPolicy (pl);
3139 pl = PolicyLevel.CreateAppDomainLevel ();
3140 ps = new PermissionSet (PermissionState.None);
3141 pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
3142 ad.SetAppDomainPolicy (pl);
3146 [ExpectedException (typeof (AppDomainUnloadedException))]
3147 public void SetAppDomainPolicy_Unloaded ()
3149 ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Unloaded");
3150 AppDomain.Unload (ad);
3151 ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
3155 [ExpectedException (typeof (ArgumentNullException))]
3156 public void GetData_Null ()
3158 AppDomain.CurrentDomain.GetData (null);
3162 public void SetData ()
3164 AppDomain.CurrentDomain.SetData ("data", "data");
3165 Assert.AreEqual ("data", AppDomain.CurrentDomain.GetData ("data"), "GetData");
3166 AppDomain.CurrentDomain.SetData ("data", null);
3167 Assert.IsNull (AppDomain.CurrentDomain.GetData ("data"), "GetData-Null");
3171 [ExpectedException (typeof (ArgumentNullException))]
3172 public void SetData_Null ()
3174 AppDomain.CurrentDomain.SetData (null, "data");
3179 public void ApplyPolicy ()
3181 ad = AppDomain.CreateDomain ("ApplyPolicy");
3182 string fullname = Assembly.GetExecutingAssembly ().FullName;
3183 string result = ad.ApplyPolicy (fullname);
3184 Assert.AreEqual (fullname, result, "ApplyPolicy");
3185 // doesn't even requires an assembly name
3186 Assert.AreEqual ("123", ad.ApplyPolicy ("123"), "Invalid FullName");
3190 [ExpectedException (typeof (ArgumentException))]
3191 public void ApplyPolicy_Empty ()
3193 ad = AppDomain.CreateDomain ("ApplyPolicy_Empty");
3194 ad.ApplyPolicy (String.Empty);
3198 [ExpectedException (typeof (ArgumentNullException))]
3199 public void ApplyPolicy_Null ()
3201 ad = AppDomain.CreateDomain ("ApplyPolicy_Null");
3202 ad.ApplyPolicy (null);
3206 public void DomainManager ()
3208 Assert.IsNull (AppDomain.CurrentDomain.DomainManager, "CurrentDomain.DomainManager");
3209 ad = AppDomain.CreateDomain ("DomainManager");
3210 Assert.IsNull (ad.DomainManager, "ad.DomainManager");
3214 public void IsDefaultAppDomain ()
3216 ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
3217 Assert.IsFalse (ad.IsDefaultAppDomain (), "IsDefaultAppDomain");
3218 // we have no public way to get the default appdomain
3222 public void ReflectionOnlyGetAssemblies ()
3224 ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
3225 Assembly [] a = ad.ReflectionOnlyGetAssemblies ();
3226 Assert.IsNotNull (a, "ReflectionOnlyGetAssemblies");
3227 Assert.AreEqual (0, a.Length, "Count");
3229 string assemblyFile = Path.Combine (tempDir, "bug499013.dll");
3230 AssemblyName aname = new AssemblyName ();
3231 aname.Name = "bug499013";
3232 aname.Version = new Version (2, 4);
3234 GenerateAssembly (aname, assemblyFile);
3236 Assembly.ReflectionOnlyLoadFrom (assemblyFile);
3237 foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies ())
3238 Assert.IsTrue (assembly.GetName ().Name != "bug499013");
3242 public void ReflectionOnlyAssemblyResolve ()
3244 AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
3245 Assembly asm = Assembly.ReflectionOnlyLoad(Assembly.LoadWithPartialName("System").FullName);
3249 private static Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
3251 return Assembly.ReflectionOnlyLoad(args.Name);
3255 private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
3257 AppDomainSetup setup = new AppDomainSetup ();
3258 setup.ApplicationBase = baseDirectory;
3259 setup.ApplicationName = "testdomain";
3260 return CreateTestDomain (setup, assemblyResolver);
3263 private static AppDomain CreateTestDomain (AppDomainSetup setup, bool assemblyResolver)
3265 AppDomain ad = AppDomain.CreateDomain ("testdomain",
3266 AppDomain.CurrentDomain.Evidence, setup);
3268 if (assemblyResolver) {
3269 Assembly ea = Assembly.GetExecutingAssembly ();
3270 ad.CreateInstanceFrom (ea.CodeBase,
3271 typeof (AssemblyResolveHandler).FullName,
3273 BindingFlags.Public | BindingFlags.Instance,
3275 new object [] { ea.Location, ea.FullName },
3276 CultureInfo.InvariantCulture,
3285 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
3287 Type testerType = typeof (CrossDomainTester);
3288 return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
3289 testerType.Assembly.FullName, testerType.FullName, false,
3290 BindingFlags.Public | BindingFlags.Instance, null, new object [0],
3291 CultureInfo.InvariantCulture, new object [0], null);
3294 private static void GenerateAssembly (AssemblyName aname, string path)
3296 AppDomain ad = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory,
3299 CrossDomainTester cdt = CreateCrossDomainTester (ad);
3300 cdt.GenerateAssembly (aname, path);
3302 AppDomain.Unload (ad);
3306 private bool RunningOnUnix {
3308 // check for Unix platforms - see FAQ for more details
3309 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
3310 int platform = (int) Environment.OSVersion.Platform;
3311 return ((platform == 4) || (platform == 128) || (platform == 6));
3315 private class CrossDomainTester : MarshalByRefObject
3317 public void GenerateAssembly (AssemblyName aname, string path)
3319 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
3320 aname, AssemblyBuilderAccess.Save, Path.GetDirectoryName (path));
3321 ab.Save (Path.GetFileName (path));
3324 public int AssemblyCount {
3326 return AppDomain.CurrentDomain.GetAssemblies ().Length;
3330 public string GetApplicationBase ()
3332 return AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
3335 public string GetConfigurationFile ()
3337 return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
3340 public void Load (AssemblyName assemblyRef)
3342 AppDomain.CurrentDomain.Load (assemblyRef);
3345 public void LoadFrom (string assemblyFile)
3347 Assembly.LoadFrom (assemblyFile);
3350 public bool AssertLoad (AssemblyName assemblyRef)
3353 AppDomain.CurrentDomain.Load (assemblyRef);
3360 public bool AssertLoad (string assemblyString)
3363 AppDomain.CurrentDomain.Load (assemblyString);
3370 public bool AssertFileLoadException (AssemblyName assemblyRef)
3373 AppDomain.CurrentDomain.Load (assemblyRef);
3375 } catch (FileLoadException) {
3380 public bool AssertFileNotFoundException (AssemblyName assemblyRef)
3383 AppDomain.CurrentDomain.Load (assemblyRef);
3385 } catch (FileNotFoundException) {
3392 private class AssemblyResolveHandler
3394 public AssemblyResolveHandler (string assemblyFile, string assemblyName)
3396 _assemblyFile = assemblyFile;
3397 _assemblyName = assemblyName;
3399 AppDomain.CurrentDomain.AssemblyResolve +=
3400 new ResolveEventHandler (ResolveAssembly);
3403 private Assembly ResolveAssembly (object sender, ResolveEventArgs args)
3405 if (args.Name == _assemblyName)
3406 return Assembly.LoadFrom (_assemblyFile);
3411 private readonly string _assemblyFile;
3412 private readonly string _assemblyName;
3415 static byte [] keyPair = {
3416 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
3417 0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3D, 0xBD,
3418 0x72, 0x08, 0xC6, 0x2B, 0x0E, 0xA8, 0xC1, 0xC0, 0x58, 0x07, 0x2B,
3419 0x63, 0x5F, 0x7C, 0x9A, 0xBD, 0xCB, 0x22, 0xDB, 0x20, 0xB2, 0xA9,
3420 0xDA, 0xDA, 0xEF, 0xE8, 0x00, 0x64, 0x2F, 0x5D, 0x8D, 0xEB, 0x78,
3421 0x02, 0xF7, 0xA5, 0x36, 0x77, 0x28, 0xD7, 0x55, 0x8D, 0x14, 0x68,
3422 0xDB, 0xEB, 0x24, 0x09, 0xD0, 0x2B, 0x13, 0x1B, 0x92, 0x6E, 0x2E,
3423 0x59, 0x54, 0x4A, 0xAC, 0x18, 0xCF, 0xC9, 0x09, 0x02, 0x3F, 0x4F,
3424 0xA8, 0x3E, 0x94, 0x00, 0x1F, 0xC2, 0xF1, 0x1A, 0x27, 0x47, 0x7D,
3425 0x10, 0x84, 0xF5, 0x14, 0xB8, 0x61, 0x62, 0x1A, 0x0C, 0x66, 0xAB,
3426 0xD2, 0x4C, 0x4B, 0x9F, 0xC9, 0x0F, 0x3C, 0xD8, 0x92, 0x0F, 0xF5,
3427 0xFF, 0xCE, 0xD7, 0x6E, 0x5C, 0x6F, 0xB1, 0xF5, 0x7D, 0xD3, 0x56,
3428 0xF9, 0x67, 0x27, 0xA4, 0xA5, 0x48, 0x5B, 0x07, 0x93, 0x44, 0x00,
3429 0x4A, 0xF8, 0xFF, 0xA4, 0xCB, 0x73, 0xC0, 0x6A, 0x62, 0xB4, 0xB7,
3430 0xC8, 0x92, 0x58, 0x87, 0xCD, 0x07, 0x0C, 0x7D, 0x6C, 0xC1, 0x4A,
3431 0xFC, 0x82, 0x57, 0x0E, 0x43, 0x85, 0x09, 0x75, 0x98, 0x51, 0xBB,
3432 0x35, 0xF5, 0x64, 0x83, 0xC7, 0x79, 0x89, 0x5C, 0x55, 0x36, 0x66,
3433 0xAB, 0x27, 0xA4, 0xD9, 0xD4, 0x7E, 0x6B, 0x67, 0x64, 0xC1, 0x54,
3434 0x4E, 0x37, 0xF1, 0x4E, 0xCA, 0xB3, 0xE5, 0x63, 0x91, 0x57, 0x12,
3435 0x14, 0xA6, 0xEA, 0x8F, 0x8F, 0x2B, 0xFE, 0xF3, 0xE9, 0x16, 0x08,
3436 0x2B, 0x86, 0xBC, 0x26, 0x0D, 0xD0, 0xC6, 0xC4, 0x1A, 0x72, 0x43,
3437 0x76, 0xDC, 0xFF, 0x28, 0x52, 0xA1, 0xDE, 0x8D, 0xFA, 0xD5, 0x1F,
3438 0x0B, 0xB5, 0x4F, 0xAF, 0x06, 0x79, 0x11, 0xEE, 0xA8, 0xEC, 0xD3,
3439 0x74, 0x55, 0xA2, 0x80, 0xFC, 0xF8, 0xD9, 0x50, 0x69, 0x48, 0x01,
3440 0xC2, 0x5A, 0x04, 0x56, 0xB4, 0x3E, 0x24, 0x32, 0x20, 0xB5, 0x2C,
3441 0xDE, 0xBB, 0xBD, 0x13, 0xFD, 0x13, 0xF7, 0x03, 0x3E, 0xE3, 0x37,
3442 0x84, 0x74, 0xE7, 0xD0, 0x5E, 0x9E, 0xB6, 0x26, 0xAE, 0x6E, 0xB0,
3443 0x55, 0x6A, 0x52, 0x63, 0x6F, 0x5A, 0x9D, 0xF2, 0x67, 0xD6, 0x61,
3444 0x4F, 0x7A, 0x45, 0xEE, 0x5C, 0x3D, 0x2B, 0x7C, 0xB2, 0x40, 0x79,
3445 0x54, 0x84, 0xD1, 0xBE, 0x61, 0x3E, 0x5E, 0xD6, 0x18, 0x8E, 0x14,
3446 0x98, 0xFC, 0x35, 0xBF, 0x5F, 0x1A, 0x20, 0x2E, 0x1A, 0xD8, 0xFF,
3447 0xC4, 0x6B, 0xC0, 0xC9, 0x7D, 0x06, 0xEF, 0x09, 0xF9, 0xF3, 0x69,
3448 0xFC, 0xBC, 0xA2, 0xE6, 0x80, 0x22, 0xB9, 0x79, 0x7E, 0xEF, 0x57,
3449 0x9F, 0x49, 0xE1, 0xBC, 0x0D, 0xB6, 0xA1, 0xFE, 0x8D, 0xBC, 0xBB,
3450 0xA3, 0x05, 0x02, 0x6B, 0x04, 0x45, 0xF7, 0x5D, 0xEE, 0x43, 0x06,
3451 0xD6, 0x9C, 0x94, 0x48, 0x1A, 0x0B, 0x9C, 0xBC, 0xB4, 0x4E, 0x93,
3452 0x60, 0x87, 0xCD, 0x58, 0xD6, 0x9A, 0x39, 0xA6, 0xC0, 0x7F, 0x8E,
3453 0xFF, 0x25, 0xC1, 0xD7, 0x2C, 0xF6, 0xF4, 0x6F, 0x24, 0x52, 0x0B,
3454 0x39, 0x42, 0x1B, 0x0D, 0x04, 0xC1, 0x93, 0x2A, 0x19, 0x1C, 0xF0,
3455 0xB1, 0x9B, 0xC1, 0x24, 0x6D, 0x1B, 0x0B, 0xDA, 0x1C, 0x8B, 0x72,
3456 0x48, 0xF0, 0x3E, 0x52, 0xBF, 0x0A, 0x84, 0x3A, 0x9B, 0xC8, 0x6D,
3457 0x13, 0x1E, 0x72, 0xF4, 0x46, 0x93, 0x88, 0x1A, 0x5F, 0x4C, 0x3C,
3458 0xE5, 0x9D, 0x6E, 0xBB, 0x4E, 0xDD, 0x5D, 0x1F, 0x11, 0x40, 0xF4,
3459 0xD7, 0xAF, 0xB3, 0xAB, 0x9A, 0x99, 0x15, 0xF0, 0xDC, 0xAA, 0xFF,
3460 0x9F, 0x2D, 0x9E, 0x56, 0x4F, 0x35, 0x5B, 0xBA, 0x06, 0x99, 0xEA,
3461 0xC6, 0xB4, 0x48, 0x51, 0x17, 0x1E, 0xD1, 0x95, 0x84, 0x81, 0x18,
3462 0xC0, 0xF1, 0x71, 0xDE, 0x44, 0x42, 0x02, 0x06, 0xAC, 0x0E, 0xA8,
3463 0xE2, 0xF3, 0x1F, 0x96, 0x1F, 0xBE, 0xB6, 0x1F, 0xB5, 0x3E, 0xF6,
3464 0x81, 0x05, 0x20, 0xFA, 0x2E, 0x40, 0x2E, 0x4D, 0xA0, 0x0E, 0xDA,
3465 0x42, 0x9C, 0x05, 0xAA, 0x9E, 0xAF, 0x5C, 0xF7, 0x3A, 0x3F, 0xBB,
3466 0x91, 0x73, 0x45, 0x27, 0xA8, 0xA2, 0x07, 0x4A, 0xEF, 0x59, 0x1E,
3467 0x97, 0x9D, 0xE0, 0x30, 0x5A, 0x83, 0xCE, 0x1E, 0x57, 0x32, 0x89,
3468 0x43, 0x41, 0x28, 0x7D, 0x14, 0x8D, 0x8B, 0x41, 0x1A, 0x56, 0x76,
3469 0x43, 0xDB, 0x64, 0x86, 0x41, 0x64, 0x8D, 0x4C, 0x91, 0x83, 0x4E,
3472 static byte [] publicKey2 = {
3473 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
3474 0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x7F, 0x7C,
3475 0xEA, 0x4A, 0x28, 0x33, 0xD8, 0x3C, 0x86, 0x90, 0x86, 0x91, 0x11,
3476 0xBB, 0x30, 0x0D, 0x3D, 0x69, 0x04, 0x4C, 0x48, 0xF5, 0x4F, 0xE7,
3477 0x64, 0xA5, 0x82, 0x72, 0x5A, 0x92, 0xC4, 0x3D, 0xC5, 0x90, 0x93,
3478 0x41, 0xC9, 0x1D, 0x34, 0x16, 0x72, 0x2B, 0x85, 0xC1, 0xF3, 0x99,
3479 0x62, 0x07, 0x32, 0x98, 0xB7, 0xE4, 0xFA, 0x75, 0x81, 0x8D, 0x08,
3480 0xB9, 0xFD, 0xDB, 0x00, 0x25, 0x30, 0xC4, 0x89, 0x13, 0xB6, 0x43,
3481 0xE8, 0xCC, 0xBE, 0x03, 0x2E, 0x1A, 0x6A, 0x4D, 0x36, 0xB1, 0xEB,
3482 0x49, 0x26, 0x6C, 0xAB, 0xC4, 0x29, 0xD7, 0x8F, 0x25, 0x11, 0xA4,
3483 0x7C, 0x81, 0x61, 0x97, 0xCB, 0x44, 0x2D, 0x80, 0x49, 0x93, 0x48,
3484 0xA7, 0xC9, 0xAB, 0xDB, 0xCF, 0xA3, 0x34, 0xCB, 0x6B, 0x86, 0xE0,
3485 0x4D, 0x27, 0xFC, 0xA7, 0x4F, 0x36, 0xCA, 0x13, 0x42, 0xD3, 0x83,
3486 0xC4, 0x06, 0x6E, 0x12, 0xE0, 0xA1, 0x3D, 0x9F, 0xA9, 0xEC, 0xD1,
3487 0xC6, 0x08, 0x1B, 0x3D, 0xF5, 0xDB, 0x4C, 0xD4, 0xF0, 0x2C, 0xAA,
3488 0xFC, 0xBA, 0x18, 0x6F, 0x48, 0x7E, 0xB9, 0x47, 0x68, 0x2E, 0xF6,
3489 0x1E, 0x67, 0x1C, 0x7E, 0x0A, 0xCE, 0x10, 0x07, 0xC0, 0x0C, 0xAD,
3490 0x5E, 0xC1, 0x53, 0x70, 0xD5, 0xE7, 0x25, 0xCA, 0x37, 0x5E, 0x49,
3491 0x59, 0xD0, 0x67, 0x2A, 0xBE, 0x92, 0x36, 0x86, 0x8A, 0xBF, 0x3E,
3492 0x17, 0x04, 0xFB, 0x1F, 0x46, 0xC8, 0x10, 0x5C, 0x93, 0x02, 0x43,
3493 0x14, 0x96, 0x6A, 0xD9, 0x87, 0x17, 0x62, 0x7D, 0x3A, 0x45, 0xBE,
3494 0x35, 0xDE, 0x75, 0x0B, 0x2A, 0xCE, 0x7D, 0xF3, 0x19, 0x85, 0x4B,
3495 0x0D, 0x6F, 0x8D, 0x15, 0xA3, 0x60, 0x61, 0x28, 0x55, 0x46, 0xCE,
3496 0x78, 0x31, 0x04, 0x18, 0x3C, 0x56, 0x4A, 0x3F, 0xA4, 0xC9, 0xB1,
3497 0x41, 0xED, 0x22, 0x80, 0xA1, 0xB3, 0xE2, 0xC7, 0x1B, 0x62, 0x85,
3498 0xE4, 0x81, 0x39, 0xCB, 0x1F, 0x95, 0xCC, 0x61, 0x61, 0xDF, 0xDE,
3499 0xF3, 0x05, 0x68, 0xB9, 0x7D, 0x4F, 0xFF, 0xF3, 0xC0, 0x0A, 0x25,
3500 0x62, 0xD9, 0x8A, 0x8A, 0x9E, 0x99, 0x0B, 0xFB, 0x85, 0x27, 0x8D,
3501 0xF6, 0xD4, 0xE1, 0xB9, 0xDE, 0xB4, 0x16, 0xBD, 0xDF, 0x6A, 0x25,
3502 0x9C, 0xAC, 0xCD, 0x91, 0xF7, 0xCB, 0xC1, 0x81, 0x22, 0x0D, 0xF4,
3503 0x7E, 0xEC, 0x0C, 0x84, 0x13, 0x5A, 0x74, 0x59, 0x3F, 0x3E, 0x61,
3504 0x00, 0xD6, 0xB5, 0x4A, 0xA1, 0x04, 0xB5, 0xA7, 0x1C, 0x29, 0xD0,
3505 0xE1, 0x11, 0x19, 0xD7, 0x80, 0x5C, 0xEE, 0x08, 0x15, 0xEB, 0xC9,
3506 0xA8, 0x98, 0xF5, 0xA0, 0xF0, 0x92, 0x2A, 0xB0, 0xD3, 0xC7, 0x8C,
3507 0x8D, 0xBB, 0x88, 0x96, 0x4F, 0x18, 0xF0, 0x8A, 0xF9, 0x31, 0x9E,
3508 0x44, 0x94, 0x75, 0x6F, 0x78, 0x04, 0x10, 0xEC, 0xF3, 0xB0, 0xCE,
3509 0xA0, 0xBE, 0x7B, 0x25, 0xE1, 0xF7, 0x8A, 0xA8, 0xD4, 0x63, 0xC2,
3510 0x65, 0x47, 0xCC, 0x5C, 0xED, 0x7D, 0x8B, 0x07, 0x4D, 0x76, 0x29,
3511 0x53, 0xAC, 0x27, 0x8F, 0x5D, 0x78, 0x56, 0xFA, 0x99, 0x45, 0xA2,
3512 0xCC, 0x65, 0xC4, 0x54, 0x13, 0x9F, 0x38, 0x41, 0x7A, 0x61, 0x0E,
3513 0x0D, 0x34, 0xBC, 0x11, 0xAF, 0xE2, 0xF1, 0x8B, 0xFA, 0x2B, 0x54,
3514 0x6C, 0xA3, 0x6C, 0x09, 0x1F, 0x0B, 0x43, 0x9B, 0x07, 0x95, 0x83,
3515 0x3F, 0x97, 0x99, 0x89, 0xF5, 0x51, 0x41, 0xF6, 0x8E, 0x5D, 0xEF,
3516 0x6D, 0x24, 0x71, 0x41, 0x7A, 0xAF, 0xBE, 0x81, 0x71, 0xAB, 0x76,
3517 0x2F, 0x1A, 0x5A, 0xBA, 0xF3, 0xA6, 0x65, 0x7A, 0x80, 0x50, 0xCE,
3518 0x23, 0xC3, 0xC7, 0x53, 0xB0, 0x7C, 0x97, 0x77, 0x27, 0x70, 0x98,
3519 0xAE, 0xB5, 0x24, 0x66, 0xE1, 0x60, 0x39, 0x41, 0xDA, 0x54, 0x01,
3520 0x64, 0xFB, 0x10, 0x33, 0xCE, 0x8B, 0xBE, 0x27, 0xD4, 0x21, 0x57,
3521 0xCC, 0x0F, 0x1A, 0xC1, 0x3D, 0xF3, 0xCC, 0x39, 0xF0, 0x2F, 0xAE,
3522 0xF1, 0xC0, 0xCD, 0x3B, 0x23, 0x87, 0x49, 0x7E, 0x40, 0x32, 0x6A,
3523 0xD3, 0x96, 0x4A, 0xE5, 0x5E, 0x6E, 0x26, 0xFD, 0x8A, 0xCF, 0x7E,
3524 0xFC, 0x37, 0xDE, 0x39, 0x0C, 0x53, 0x81, 0x75, 0x08, 0xAF, 0x6B,
3525 0x39, 0x6C, 0xFB, 0xC9, 0x79, 0xC0, 0x9B, 0x5F, 0x34, 0x86, 0xB2,
3526 0xDE, 0xC4, 0x19, 0x84, 0x5F, 0x0E, 0xED, 0x9B, 0xB8, 0xD3, 0x17,
3529 static byte [] publicKey = {
3530 0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00,
3531 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53,
3532 0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3d,
3533 0xbd, 0x72, 0x08, 0xc6, 0x2b, 0x0e, 0xa8, 0xc1, 0xc0, 0x58, 0x07,
3534 0x2b, 0x63, 0x5f, 0x7c, 0x9a, 0xbd, 0xcb, 0x22, 0xdb, 0x20, 0xb2,
3535 0xa9, 0xda, 0xda, 0xef, 0xe8, 0x00, 0x64, 0x2f, 0x5d, 0x8d, 0xeb,
3536 0x78, 0x02, 0xf7, 0xa5, 0x36, 0x77, 0x28, 0xd7, 0x55, 0x8d, 0x14,
3537 0x68, 0xdb, 0xeb, 0x24, 0x09, 0xd0, 0x2b, 0x13, 0x1b, 0x92, 0x6e,
3538 0x2e, 0x59, 0x54, 0x4a, 0xac, 0x18, 0xcf, 0xc9, 0x09, 0x02, 0x3f,
3539 0x4f, 0xa8, 0x3e, 0x94, 0x00, 0x1f, 0xc2, 0xf1, 0x1a, 0x27, 0x47,
3540 0x7d, 0x10, 0x84, 0xf5, 0x14, 0xb8, 0x61, 0x62, 0x1a, 0x0c, 0x66,
3541 0xab, 0xd2, 0x4c, 0x4b, 0x9f, 0xc9, 0x0f, 0x3c, 0xd8, 0x92, 0x0f,
3542 0xf5, 0xff, 0xce, 0xd7, 0x6e, 0x5c, 0x6f, 0xb1, 0xf5, 0x7d, 0xd3,
3543 0x56, 0xf9, 0x67, 0x27, 0xa4, 0xa5, 0x48, 0x5b, 0x07, 0x93, 0x44,
3544 0x00, 0x4a, 0xf8, 0xff, 0xa4, 0xcb };
3546 static byte [] pk_token = { 0xce, 0x52, 0x76, 0xd8, 0x68, 0x7e, 0Xc6, 0xdc };