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