PageRenderTime 74ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/corlib/Test/System/AppDomainTest.cs

https://bitbucket.org/danipen/mono
C# | 3559 lines | 3382 code | 91 blank | 86 comment | 44 complexity | 46dc4c6e0d9c93802ee7af4c254a5a7e MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. //
  2. // AppDomainTest.cs - NUnit Test Cases for AppDomain
  3. //
  4. // Author:
  5. // Sebastien Pouliot (sebastien@ximian.com)
  6. //
  7. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  8. // Copyright 2011 Xamarin Inc (http://www.xamarin.com).
  9. //
  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:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  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.
  28. //
  29. #if !MOBILE
  30. using NUnit.Framework;
  31. using System;
  32. using System.Collections;
  33. using System.Collections.Generic;
  34. using System.Configuration.Assemblies;
  35. using System.Globalization;
  36. using System.IO;
  37. using System.Reflection;
  38. using System.Reflection.Emit;
  39. using System.Runtime.InteropServices;
  40. using System.Security;
  41. using System.Security.Permissions;
  42. using System.Security.Policy;
  43. using System.Security.Principal;
  44. namespace MonoTests.System
  45. {
  46. [TestFixture]
  47. public class AppDomainTest
  48. {
  49. private AppDomain ad;
  50. private ArrayList files = new ArrayList ();
  51. private string tempDir;
  52. [SetUp]
  53. public void SetUp ()
  54. {
  55. tempDir = Path.Combine (Path.GetTempPath (), Environment.UserName);
  56. tempDir = Path.Combine (tempDir, "MonoTests.System.AppDomainTest");
  57. if (!Directory.Exists (tempDir)) {
  58. Directory.CreateDirectory (tempDir);
  59. }
  60. }
  61. [TearDown]
  62. public void TearDown ()
  63. {
  64. if (ad != null) {
  65. try {
  66. AppDomain.Unload (ad);
  67. ad = null;
  68. } catch { } // do not affect unit test results in TearDown
  69. }
  70. foreach (string fname in files) {
  71. File.Delete (fname);
  72. }
  73. files.Clear ();
  74. }
  75. [Test] // bug #80934
  76. public void ConfigurationFile_Relative ()
  77. {
  78. // Note:
  79. // We use Environment.GetCommandLineArgs () to get the location of
  80. // the entry assembly in the default domain (since the default domain
  81. // is not exposed by any API)
  82. //
  83. // MS returns a lower-case path in Environment.GetCommandLineArgs ()
  84. // and hence we need to perform a case-insensitive comparison
  85. // if the Assert involves that path
  86. string configFile = "test.config";
  87. string appBase = null;
  88. string expectedConfigFile = null;
  89. string expectedAppBase = null;
  90. // do not set ApplicationBase
  91. appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
  92. expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
  93. appBase : appBase + Path.DirectorySeparatorChar;
  94. expectedConfigFile = Path.Combine (appBase, configFile);
  95. AppDomainSetup setup = new AppDomainSetup();
  96. setup.ConfigurationFile = configFile;
  97. ad = CreateTestDomain (setup, true);
  98. CrossDomainTester cdt = CreateCrossDomainTester (ad);
  99. if (RunningOnUnix) {
  100. Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
  101. Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
  102. } else {
  103. Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
  104. Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
  105. }
  106. AppDomain.Unload (ad);
  107. // set ApplicationBase
  108. appBase = Path.GetTempPath ();
  109. expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
  110. appBase : appBase + Path.DirectorySeparatorChar;
  111. expectedConfigFile = Path.Combine (appBase, configFile);
  112. setup = new AppDomainSetup ();
  113. setup.ApplicationBase = appBase;
  114. setup.ConfigurationFile = configFile;
  115. ad = CreateTestDomain (setup, true);
  116. cdt = CreateCrossDomainTester (ad);
  117. Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
  118. Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
  119. AppDomain.Unload (ad);
  120. }
  121. [Test] // bug #80934
  122. public void ConfigurationFile_Absolute ()
  123. {
  124. // Note:
  125. // We use Environment.GetCommandLineArgs () to get the location of
  126. // the entry assembly in the default domain (since the default domain
  127. // is not exposed by any API)
  128. //
  129. // MS returns a lower-case path in Environment.GetCommandLineArgs ()
  130. // and hence on Windows we need to perform a case-insensitive
  131. // comparison if the Assert involves that path
  132. string configFile = Path.Combine (tempDir, "test.config");
  133. string appBase = null;
  134. string expectedAppBase = null;
  135. // do not set ApplicationBase
  136. appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
  137. expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
  138. appBase : appBase + Path.DirectorySeparatorChar;
  139. AppDomainSetup setup = new AppDomainSetup ();
  140. setup.ConfigurationFile = configFile;
  141. ad = CreateTestDomain (setup, true);
  142. CrossDomainTester cdt = CreateCrossDomainTester (ad);
  143. Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#A1");
  144. if (RunningOnUnix) {
  145. Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
  146. } else {
  147. Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
  148. }
  149. AppDomain.Unload (ad);
  150. // set ApplicationBase
  151. appBase = Path.GetTempPath ();
  152. expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
  153. appBase : appBase + Path.DirectorySeparatorChar;
  154. setup = new AppDomainSetup ();
  155. setup.ApplicationBase = appBase;
  156. setup.ConfigurationFile = configFile;
  157. ad = CreateTestDomain (setup, true);
  158. cdt = CreateCrossDomainTester (ad);
  159. Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#B1");
  160. Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
  161. AppDomain.Unload (ad);
  162. }
  163. [Test] // bug #80934
  164. public void ConfigurationFile_Null ()
  165. {
  166. // Note:
  167. // We use Environment.GetCommandLineArgs () to get the location of
  168. // the entry assembly in the default domain (since the default domain
  169. // is not exposed by any API)
  170. //
  171. // MS returns a lower-case path in Environment.GetCommandLineArgs ()
  172. // and hence we need to perform a case-insensitive comparison
  173. // if the Assert involves that path
  174. string appBase = null;
  175. string expectedAppBase = null;
  176. string expectedConfigFile = null;
  177. // do not set ApplicationBase
  178. appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
  179. expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
  180. appBase : appBase + Path.DirectorySeparatorChar;
  181. expectedConfigFile = Environment.GetCommandLineArgs () [0] + ".config";
  182. AppDomainSetup setup = new AppDomainSetup ();
  183. setup.ConfigurationFile = null;
  184. ad = CreateTestDomain (setup, true);
  185. CrossDomainTester cdt = CreateCrossDomainTester (ad);
  186. if (RunningOnUnix) {
  187. Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
  188. Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
  189. } else {
  190. Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
  191. Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
  192. }
  193. AppDomain.Unload (ad);
  194. // set ApplicationBase
  195. appBase = Path.GetTempPath ();
  196. expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
  197. appBase : appBase + Path.DirectorySeparatorChar;
  198. expectedConfigFile = Path.Combine (appBase, Path.GetFileName (Environment.GetCommandLineArgs () [0]) + ".config");
  199. setup = new AppDomainSetup ();
  200. setup.ApplicationBase = appBase;
  201. setup.ConfigurationFile = null;
  202. ad = CreateTestDomain (setup, true);
  203. cdt = CreateCrossDomainTester (ad);
  204. if (RunningOnUnix) {
  205. Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
  206. } else {
  207. Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#B1");
  208. }
  209. Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
  210. AppDomain.Unload (ad);
  211. }
  212. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
  213. public void DefineDynamicAssembly1_Access_Invalid ()
  214. {
  215. AssemblyName name = new AssemblyName ();
  216. name.Name = "DefineDynamicAssembly1";
  217. try {
  218. AppDomain.CurrentDomain.DefineDynamicAssembly (
  219. name, AssemblyBuilderAccess.Run |
  220. (AssemblyBuilderAccess) 666);
  221. Assert.Fail ("#1");
  222. } catch (ArgumentException ex) {
  223. // Illegal enum value: 667
  224. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  225. Assert.IsNull (ex.InnerException, "#3");
  226. Assert.IsNotNull (ex.Message, "#4");
  227. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  228. Assert.IsNotNull (ex.ParamName, "#6");
  229. Assert.AreEqual ("access", ex.ParamName, "#7");
  230. }
  231. }
  232. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
  233. public void DefineDynamicAssembly1_Name_InvalidChars ()
  234. {
  235. string [] invalid_char_names = new string [] {
  236. "\tAB",
  237. " AB",
  238. "\rAB",
  239. "A/B",
  240. ":AB",
  241. "B:A",
  242. "B\\A",
  243. "BA\\"};
  244. AssemblyName name = new AssemblyName ();
  245. foreach (string invalid_name in invalid_char_names) {
  246. name.Name = invalid_name;
  247. try {
  248. AppDomain.CurrentDomain.DefineDynamicAssembly (
  249. name,
  250. AssemblyBuilderAccess.Run);
  251. Assert.Fail ("#1:" + invalid_name);
  252. } catch (ArgumentException ex) {
  253. // Assembly names may not begin with whitespace
  254. // or contain the characters '/', '\' or ':'
  255. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  256. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  257. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  258. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  259. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  260. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  261. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  262. }
  263. }
  264. }
  265. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
  266. public void DefineDynamicAssembly1_Name_Null ()
  267. {
  268. try {
  269. AppDomain.CurrentDomain.DefineDynamicAssembly (
  270. (AssemblyName) null,
  271. AssemblyBuilderAccess.Run);
  272. Assert.Fail ("#A1");
  273. } catch (ArgumentNullException ex) {
  274. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  275. Assert.IsNull (ex.InnerException, "#A3");
  276. Assert.IsNotNull (ex.Message, "#A4");
  277. Assert.IsNotNull (ex.ParamName, "#A5");
  278. Assert.AreEqual ("name", ex.ParamName, "#A6");
  279. }
  280. AssemblyName name = new AssemblyName ();
  281. try {
  282. AppDomain.CurrentDomain.DefineDynamicAssembly (
  283. name,
  284. AssemblyBuilderAccess.Run);
  285. Assert.Fail ("#B1");
  286. } catch (ArgumentException ex) {
  287. // AssemblyName.Name cannot be null or an empty string
  288. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  289. Assert.IsNull (ex.InnerException, "#B3");
  290. Assert.IsNotNull (ex.Message, "#B4");
  291. Assert.IsNull (ex.ParamName, "#B5");
  292. }
  293. name.Name = string.Empty;
  294. try {
  295. AppDomain.CurrentDomain.DefineDynamicAssembly (
  296. name,
  297. AssemblyBuilderAccess.Run);
  298. Assert.Fail ("#C1");
  299. } catch (ArgumentException ex) {
  300. // AssemblyName.Name cannot be null or an empty string
  301. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  302. Assert.IsNull (ex.InnerException, "#C3");
  303. Assert.IsNotNull (ex.Message, "#C4");
  304. Assert.IsNull (ex.ParamName, "#C5");
  305. }
  306. }
  307. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
  308. public void DefineDynamicAssembly2_Access_Invalid ()
  309. {
  310. AssemblyName name = new AssemblyName ();
  311. name.Name = "DefineDynamicAssembly2";
  312. #if NET_2_0
  313. try {
  314. AppDomain.CurrentDomain.DefineDynamicAssembly (
  315. name, AssemblyBuilderAccess.Run |
  316. (AssemblyBuilderAccess) 666,
  317. AppDomain.CurrentDomain.Evidence);
  318. Assert.Fail ("#1");
  319. } catch (ArgumentException ex) {
  320. // Illegal enum value: 667
  321. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  322. Assert.IsNull (ex.InnerException, "#3");
  323. Assert.IsNotNull (ex.Message, "#4");
  324. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  325. Assert.IsNotNull (ex.ParamName, "#6");
  326. Assert.AreEqual ("access", ex.ParamName, "#7");
  327. }
  328. #else
  329. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  330. name, AssemblyBuilderAccess.Run |
  331. (AssemblyBuilderAccess) 666,
  332. AppDomain.CurrentDomain.Evidence);
  333. Assert.IsNotNull (ab, "#1");
  334. #endif
  335. }
  336. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
  337. public void DefineDynamicAssembly2_Name_InvalidChars ()
  338. {
  339. string [] invalid_char_names = new string [] {
  340. "\tAB",
  341. " AB",
  342. "\rAB",
  343. "A/B",
  344. ":AB",
  345. "B:A",
  346. "B\\A",
  347. "BA\\"};
  348. AssemblyName name = new AssemblyName ();
  349. foreach (string invalid_name in invalid_char_names) {
  350. name.Name = invalid_name;
  351. try {
  352. AppDomain.CurrentDomain.DefineDynamicAssembly (
  353. name,
  354. AssemblyBuilderAccess.Run,
  355. AppDomain.CurrentDomain.Evidence);
  356. Assert.Fail ("#1:" + invalid_name);
  357. } catch (ArgumentException ex) {
  358. // Assembly names may not begin with whitespace
  359. // or contain the characters '/', '\' or ':'
  360. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  361. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  362. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  363. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  364. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  365. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  366. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  367. }
  368. }
  369. }
  370. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
  371. public void DefineDynamicAssembly2_Name_Null ()
  372. {
  373. try {
  374. AppDomain.CurrentDomain.DefineDynamicAssembly (
  375. (AssemblyName) null,
  376. AssemblyBuilderAccess.Run,
  377. AppDomain.CurrentDomain.Evidence);
  378. Assert.Fail ("#A1");
  379. } catch (ArgumentNullException ex) {
  380. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  381. Assert.IsNull (ex.InnerException, "#A3");
  382. Assert.IsNotNull (ex.Message, "#A4");
  383. Assert.IsNotNull (ex.ParamName, "#A5");
  384. Assert.AreEqual ("name", ex.ParamName, "#A6");
  385. }
  386. AssemblyName name = new AssemblyName ();
  387. try {
  388. AppDomain.CurrentDomain.DefineDynamicAssembly (
  389. name,
  390. AssemblyBuilderAccess.Run,
  391. AppDomain.CurrentDomain.Evidence);
  392. Assert.Fail ("#B1");
  393. } catch (ArgumentException ex) {
  394. // AssemblyName.Name cannot be null or an empty string
  395. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  396. Assert.IsNull (ex.InnerException, "#B3");
  397. Assert.IsNotNull (ex.Message, "#B4");
  398. Assert.IsNull (ex.ParamName, "#B5");
  399. }
  400. name.Name = string.Empty;
  401. try {
  402. AppDomain.CurrentDomain.DefineDynamicAssembly (
  403. name,
  404. AssemblyBuilderAccess.Run,
  405. AppDomain.CurrentDomain.Evidence);
  406. Assert.Fail ("#C1");
  407. } catch (ArgumentException ex) {
  408. // AssemblyName.Name cannot be null or an empty string
  409. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  410. Assert.IsNull (ex.InnerException, "#C3");
  411. Assert.IsNotNull (ex.Message, "#C4");
  412. Assert.IsNull (ex.ParamName, "#C5");
  413. }
  414. }
  415. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
  416. public void DefineDynamicAssembly3_Access_Invalid ()
  417. {
  418. AssemblyName name = new AssemblyName ();
  419. name.Name = "DefineDynamicAssembly3";
  420. #if NET_2_0
  421. try {
  422. AppDomain.CurrentDomain.DefineDynamicAssembly (
  423. name, AssemblyBuilderAccess.Run |
  424. (AssemblyBuilderAccess) 666,
  425. Path.GetTempPath ());
  426. Assert.Fail ("#1");
  427. } catch (ArgumentException ex) {
  428. // Illegal enum value: 667
  429. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  430. Assert.IsNull (ex.InnerException, "#3");
  431. Assert.IsNotNull (ex.Message, "#4");
  432. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  433. Assert.IsNotNull (ex.ParamName, "#6");
  434. Assert.AreEqual ("access", ex.ParamName, "#7");
  435. }
  436. #else
  437. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  438. name, AssemblyBuilderAccess.Run |
  439. (AssemblyBuilderAccess) 666,
  440. Path.GetTempPath ());
  441. Assert.IsNotNull (ab, "#1");
  442. #endif
  443. }
  444. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
  445. public void DefineDynamicAssembly3_Name_InvalidChars ()
  446. {
  447. string [] invalid_char_names = new string [] {
  448. "\tAB",
  449. " AB",
  450. "\rAB",
  451. "A/B",
  452. ":AB",
  453. "B:A",
  454. "B\\A",
  455. "BA\\"};
  456. AssemblyName name = new AssemblyName ();
  457. foreach (string invalid_name in invalid_char_names) {
  458. name.Name = invalid_name;
  459. try {
  460. AppDomain.CurrentDomain.DefineDynamicAssembly (
  461. name,
  462. AssemblyBuilderAccess.Run,
  463. Path.GetTempPath ());
  464. Assert.Fail ("#1:" + invalid_name);
  465. } catch (ArgumentException ex) {
  466. // Assembly names may not begin with whitespace
  467. // or contain the characters '/', '\' or ':'
  468. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  469. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  470. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  471. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  472. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  473. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  474. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  475. }
  476. }
  477. }
  478. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
  479. public void DefineDynamicAssembly3_Name_Null ()
  480. {
  481. try {
  482. AppDomain.CurrentDomain.DefineDynamicAssembly (
  483. (AssemblyName) null,
  484. AssemblyBuilderAccess.Run,
  485. Path.GetTempPath ());
  486. Assert.Fail ("#A1");
  487. } catch (ArgumentNullException ex) {
  488. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  489. Assert.IsNull (ex.InnerException, "#A3");
  490. Assert.IsNotNull (ex.Message, "#A4");
  491. Assert.IsNotNull (ex.ParamName, "#A5");
  492. Assert.AreEqual ("name", ex.ParamName, "#A6");
  493. }
  494. AssemblyName name = new AssemblyName ();
  495. try {
  496. AppDomain.CurrentDomain.DefineDynamicAssembly (
  497. name,
  498. AssemblyBuilderAccess.Run,
  499. Path.GetTempPath ());
  500. Assert.Fail ("#B1");
  501. } catch (ArgumentException ex) {
  502. // AssemblyName.Name cannot be null or an empty string
  503. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  504. Assert.IsNull (ex.InnerException, "#B3");
  505. Assert.IsNotNull (ex.Message, "#B4");
  506. Assert.IsNull (ex.ParamName, "#B5");
  507. }
  508. name.Name = string.Empty;
  509. try {
  510. AppDomain.CurrentDomain.DefineDynamicAssembly (
  511. name,
  512. AssemblyBuilderAccess.Run,
  513. Path.GetTempPath ());
  514. Assert.Fail ("#C1");
  515. } catch (ArgumentException ex) {
  516. // AssemblyName.Name cannot be null or an empty string
  517. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  518. Assert.IsNull (ex.InnerException, "#C3");
  519. Assert.IsNotNull (ex.Message, "#C4");
  520. Assert.IsNull (ex.ParamName, "#C5");
  521. }
  522. }
  523. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
  524. public void DefineDynamicAssembly4_Access_Invalid ()
  525. {
  526. AssemblyName name = new AssemblyName ();
  527. name.Name = "DefineDynamicAssembly4";
  528. #if NET_2_0
  529. try {
  530. AppDomain.CurrentDomain.DefineDynamicAssembly (
  531. name, AssemblyBuilderAccess.Run |
  532. (AssemblyBuilderAccess) 666,
  533. Path.GetTempPath (),
  534. AppDomain.CurrentDomain.Evidence);
  535. Assert.Fail ("#1");
  536. } catch (ArgumentException ex) {
  537. // Illegal enum value: 667
  538. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  539. Assert.IsNull (ex.InnerException, "#3");
  540. Assert.IsNotNull (ex.Message, "#4");
  541. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  542. Assert.IsNotNull (ex.ParamName, "#6");
  543. Assert.AreEqual ("access", ex.ParamName, "#7");
  544. }
  545. #else
  546. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  547. name, AssemblyBuilderAccess.Run |
  548. (AssemblyBuilderAccess) 666,
  549. Path.GetTempPath (),
  550. AppDomain.CurrentDomain.Evidence);
  551. Assert.IsNotNull (ab, "#1");
  552. #endif
  553. }
  554. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
  555. public void DefineDynamicAssembly4_Name_InvalidChars ()
  556. {
  557. string [] invalid_char_names = new string [] {
  558. "\tAB",
  559. " AB",
  560. "\rAB",
  561. "A/B",
  562. ":AB",
  563. "B:A",
  564. "B\\A",
  565. "BA\\"};
  566. AssemblyName name = new AssemblyName ();
  567. foreach (string invalid_name in invalid_char_names) {
  568. name.Name = invalid_name;
  569. try {
  570. AppDomain.CurrentDomain.DefineDynamicAssembly (
  571. name,
  572. AssemblyBuilderAccess.Run,
  573. Path.GetTempPath (),
  574. AppDomain.CurrentDomain.Evidence);
  575. Assert.Fail ("#1:" + invalid_name);
  576. } catch (ArgumentException ex) {
  577. // Assembly names may not begin with whitespace
  578. // or contain the characters '/', '\' or ':'
  579. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  580. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  581. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  582. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  583. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  584. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  585. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  586. }
  587. }
  588. }
  589. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
  590. public void DefineDynamicAssembly4_Name_Null ()
  591. {
  592. try {
  593. AppDomain.CurrentDomain.DefineDynamicAssembly (
  594. (AssemblyName) null,
  595. AssemblyBuilderAccess.Run,
  596. Path.GetTempPath (),
  597. AppDomain.CurrentDomain.Evidence);
  598. Assert.Fail ("#A1");
  599. } catch (ArgumentNullException ex) {
  600. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  601. Assert.IsNull (ex.InnerException, "#A3");
  602. Assert.IsNotNull (ex.Message, "#A4");
  603. Assert.IsNotNull (ex.ParamName, "#A5");
  604. Assert.AreEqual ("name", ex.ParamName, "#A6");
  605. }
  606. AssemblyName name = new AssemblyName ();
  607. try {
  608. AppDomain.CurrentDomain.DefineDynamicAssembly (
  609. name,
  610. AssemblyBuilderAccess.Run,
  611. Path.GetTempPath (),
  612. AppDomain.CurrentDomain.Evidence);
  613. Assert.Fail ("#B1");
  614. } catch (ArgumentException ex) {
  615. // AssemblyName.Name cannot be null or an empty string
  616. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  617. Assert.IsNull (ex.InnerException, "#B3");
  618. Assert.IsNotNull (ex.Message, "#B4");
  619. Assert.IsNull (ex.ParamName, "#B5");
  620. }
  621. name.Name = string.Empty;
  622. try {
  623. AppDomain.CurrentDomain.DefineDynamicAssembly (
  624. name,
  625. AssemblyBuilderAccess.Run,
  626. Path.GetTempPath (),
  627. AppDomain.CurrentDomain.Evidence);
  628. Assert.Fail ("#C1");
  629. } catch (ArgumentException ex) {
  630. // AssemblyName.Name cannot be null or an empty string
  631. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  632. Assert.IsNull (ex.InnerException, "#C3");
  633. Assert.IsNotNull (ex.Message, "#C4");
  634. Assert.IsNull (ex.ParamName, "#C5");
  635. }
  636. }
  637. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
  638. public void DefineDynamicAssembly5_Access_Invalid ()
  639. {
  640. AssemblyName name = new AssemblyName ();
  641. name.Name = "DefineDynamicAssembly5";
  642. #if NET_2_0
  643. try {
  644. AppDomain.CurrentDomain.DefineDynamicAssembly (
  645. name, AssemblyBuilderAccess.Run |
  646. (AssemblyBuilderAccess) 666,
  647. (PermissionSet) null,
  648. (PermissionSet) null,
  649. (PermissionSet) null);
  650. Assert.Fail ("#1");
  651. } catch (ArgumentException ex) {
  652. // Illegal enum value: 667
  653. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  654. Assert.IsNull (ex.InnerException, "#3");
  655. Assert.IsNotNull (ex.Message, "#4");
  656. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  657. Assert.IsNotNull (ex.ParamName, "#6");
  658. Assert.AreEqual ("access", ex.ParamName, "#7");
  659. }
  660. #else
  661. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  662. name, AssemblyBuilderAccess.Run |
  663. (AssemblyBuilderAccess) 666,
  664. (PermissionSet) null,
  665. (PermissionSet) null,
  666. (PermissionSet) null);
  667. Assert.IsNotNull (ab, "#1");
  668. #endif
  669. }
  670. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
  671. public void DefineDynamicAssembly5_Name_InvalidChars ()
  672. {
  673. string [] invalid_char_names = new string [] {
  674. "\tAB",
  675. " AB",
  676. "\rAB",
  677. "A/B",
  678. ":AB",
  679. "B:A",
  680. "B\\A",
  681. "BA\\"};
  682. AssemblyName name = new AssemblyName ();
  683. foreach (string invalid_name in invalid_char_names) {
  684. name.Name = invalid_name;
  685. try {
  686. AppDomain.CurrentDomain.DefineDynamicAssembly (
  687. name,
  688. AssemblyBuilderAccess.Run,
  689. (PermissionSet) null,
  690. (PermissionSet) null,
  691. (PermissionSet) null);
  692. Assert.Fail ("#1:" + invalid_name);
  693. } catch (ArgumentException ex) {
  694. // Assembly names may not begin with whitespace
  695. // or contain the characters '/', '\' or ':'
  696. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  697. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  698. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  699. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  700. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  701. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  702. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  703. }
  704. }
  705. }
  706. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
  707. public void DefineDynamicAssembly5_Name_Null ()
  708. {
  709. try {
  710. AppDomain.CurrentDomain.DefineDynamicAssembly (
  711. (AssemblyName) null,
  712. AssemblyBuilderAccess.Run,
  713. (PermissionSet) null,
  714. (PermissionSet) null,
  715. (PermissionSet) null);
  716. Assert.Fail ("#A1");
  717. } catch (ArgumentNullException ex) {
  718. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  719. Assert.IsNull (ex.InnerException, "#A3");
  720. Assert.IsNotNull (ex.Message, "#A4");
  721. Assert.IsNotNull (ex.ParamName, "#A5");
  722. Assert.AreEqual ("name", ex.ParamName, "#A6");
  723. }
  724. AssemblyName name = new AssemblyName ();
  725. try {
  726. AppDomain.CurrentDomain.DefineDynamicAssembly (
  727. name,
  728. AssemblyBuilderAccess.Run,
  729. (PermissionSet) null,
  730. (PermissionSet) null,
  731. (PermissionSet) null);
  732. Assert.Fail ("#B1");
  733. } catch (ArgumentException ex) {
  734. // AssemblyName.Name cannot be null or an empty string
  735. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  736. Assert.IsNull (ex.InnerException, "#B3");
  737. Assert.IsNotNull (ex.Message, "#B4");
  738. Assert.IsNull (ex.ParamName, "#B5");
  739. }
  740. name.Name = string.Empty;
  741. try {
  742. AppDomain.CurrentDomain.DefineDynamicAssembly (
  743. name,
  744. AssemblyBuilderAccess.Run,
  745. (PermissionSet) null,
  746. (PermissionSet) null,
  747. (PermissionSet) null);
  748. Assert.Fail ("#C1");
  749. } catch (ArgumentException ex) {
  750. // AssemblyName.Name cannot be null or an empty string
  751. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  752. Assert.IsNull (ex.InnerException, "#C3");
  753. Assert.IsNotNull (ex.Message, "#C4");
  754. Assert.IsNull (ex.ParamName, "#C5");
  755. }
  756. }
  757. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
  758. public void DefineDynamicAssembly6_Access_Invalid ()
  759. {
  760. AssemblyName name = new AssemblyName ();
  761. name.Name = "DefineDynamicAssembly6";
  762. #if NET_2_0
  763. try {
  764. AppDomain.CurrentDomain.DefineDynamicAssembly (
  765. name, AssemblyBuilderAccess.Run |
  766. (AssemblyBuilderAccess) 666,
  767. AppDomain.CurrentDomain.Evidence,
  768. (PermissionSet) null,
  769. (PermissionSet) null,
  770. (PermissionSet) null);
  771. Assert.Fail ("#1");
  772. } catch (ArgumentException ex) {
  773. // Illegal enum value: 667
  774. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  775. Assert.IsNull (ex.InnerException, "#3");
  776. Assert.IsNotNull (ex.Message, "#4");
  777. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  778. Assert.IsNotNull (ex.ParamName, "#6");
  779. Assert.AreEqual ("access", ex.ParamName, "#7");
  780. }
  781. #else
  782. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  783. name, AssemblyBuilderAccess.Run |
  784. (AssemblyBuilderAccess) 666,
  785. AppDomain.CurrentDomain.Evidence,
  786. (PermissionSet) null,
  787. (PermissionSet) null,
  788. (PermissionSet) null);
  789. Assert.IsNotNull (ab, "#1");
  790. #endif
  791. }
  792. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
  793. public void DefineDynamicAssembly6_Name_InvalidChars ()
  794. {
  795. string [] invalid_char_names = new string [] {
  796. "\tAB",
  797. " AB",
  798. "\rAB",
  799. "A/B",
  800. ":AB",
  801. "B:A",
  802. "B\\A",
  803. "BA\\"};
  804. AssemblyName name = new AssemblyName ();
  805. foreach (string invalid_name in invalid_char_names) {
  806. name.Name = invalid_name;
  807. try {
  808. AppDomain.CurrentDomain.DefineDynamicAssembly (
  809. name,
  810. AssemblyBuilderAccess.Run,
  811. AppDomain.CurrentDomain.Evidence,
  812. (PermissionSet) null,
  813. (PermissionSet) null,
  814. (PermissionSet) null);
  815. Assert.Fail ("#1:" + invalid_name);
  816. } catch (ArgumentException ex) {
  817. // Assembly names may not begin with whitespace
  818. // or contain the characters '/', '\' or ':'
  819. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  820. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  821. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  822. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  823. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  824. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  825. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  826. }
  827. }
  828. }
  829. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
  830. public void DefineDynamicAssembly6_Name_Null ()
  831. {
  832. try {
  833. AppDomain.CurrentDomain.DefineDynamicAssembly (
  834. (AssemblyName) null,
  835. AssemblyBuilderAccess.Run,
  836. AppDomain.CurrentDomain.Evidence,
  837. (PermissionSet) null,
  838. (PermissionSet) null,
  839. (PermissionSet) null);
  840. Assert.Fail ("#A1");
  841. } catch (ArgumentNullException ex) {
  842. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  843. Assert.IsNull (ex.InnerException, "#A3");
  844. Assert.IsNotNull (ex.Message, "#A4");
  845. Assert.IsNotNull (ex.ParamName, "#A5");
  846. Assert.AreEqual ("name", ex.ParamName, "#A6");
  847. }
  848. AssemblyName name = new AssemblyName ();
  849. try {
  850. AppDomain.CurrentDomain.DefineDynamicAssembly (
  851. name,
  852. AssemblyBuilderAccess.Run,
  853. AppDomain.CurrentDomain.Evidence,
  854. (PermissionSet) null,
  855. (PermissionSet) null,
  856. (PermissionSet) null);
  857. Assert.Fail ("#B1");
  858. } catch (ArgumentException ex) {
  859. // AssemblyName.Name cannot be null or an empty string
  860. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  861. Assert.IsNull (ex.InnerException, "#B3");
  862. Assert.IsNotNull (ex.Message, "#B4");
  863. Assert.IsNull (ex.ParamName, "#B5");
  864. }
  865. name.Name = string.Empty;
  866. try {
  867. AppDomain.CurrentDomain.DefineDynamicAssembly (
  868. name,
  869. AssemblyBuilderAccess.Run,
  870. AppDomain.CurrentDomain.Evidence,
  871. (PermissionSet) null,
  872. (PermissionSet) null,
  873. (PermissionSet) null);
  874. Assert.Fail ("#C1");
  875. } catch (ArgumentException ex) {
  876. // AssemblyName.Name cannot be null or an empty string
  877. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  878. Assert.IsNull (ex.InnerException, "#C3");
  879. Assert.IsNotNull (ex.Message, "#C4");
  880. Assert.IsNull (ex.ParamName, "#C5");
  881. }
  882. }
  883. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
  884. public void DefineDynamicAssembly7_Access_Invalid ()
  885. {
  886. AssemblyName name = new AssemblyName ();
  887. name.Name = "DefineDynamicAssembly7";
  888. #if NET_2_0
  889. try {
  890. AppDomain.CurrentDomain.DefineDynamicAssembly (
  891. name, AssemblyBuilderAccess.Run |
  892. (AssemblyBuilderAccess) 666,
  893. Path.GetTempPath (),
  894. (PermissionSet) null,
  895. (PermissionSet) null,
  896. (PermissionSet) null);
  897. Assert.Fail ("#1");
  898. } catch (ArgumentException ex) {
  899. // Illegal enum value: 667
  900. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  901. Assert.IsNull (ex.InnerException, "#3");
  902. Assert.IsNotNull (ex.Message, "#4");
  903. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  904. Assert.IsNotNull (ex.ParamName, "#6");
  905. Assert.AreEqual ("access", ex.ParamName, "#7");
  906. }
  907. #else
  908. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  909. name, AssemblyBuilderAccess.Run |
  910. (AssemblyBuilderAccess) 666,
  911. Path.GetTempPath (),
  912. (PermissionSet) null,
  913. (PermissionSet) null,
  914. (PermissionSet) null);
  915. Assert.IsNotNull (ab, "#1");
  916. #endif
  917. }
  918. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
  919. public void DefineDynamicAssembly7_Name_InvalidChars ()
  920. {
  921. string [] invalid_char_names = new string [] {
  922. "\tAB",
  923. " AB",
  924. "\rAB",
  925. "A/B",
  926. ":AB",
  927. "B:A",
  928. "B\\A",
  929. "BA\\"};
  930. AssemblyName name = new AssemblyName ();
  931. foreach (string invalid_name in invalid_char_names) {
  932. name.Name = invalid_name;
  933. try {
  934. AppDomain.CurrentDomain.DefineDynamicAssembly (
  935. name,
  936. AssemblyBuilderAccess.Run,
  937. Path.GetTempPath (),
  938. (PermissionSet) null,
  939. (PermissionSet) null,
  940. (PermissionSet) null);
  941. Assert.Fail ("#1:" + invalid_name);
  942. } catch (ArgumentException ex) {
  943. // Assembly names may not begin with whitespace
  944. // or contain the characters '/', '\' or ':'
  945. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  946. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  947. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  948. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  949. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  950. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  951. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  952. }
  953. }
  954. }
  955. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
  956. public void DefineDynamicAssembly7_Name_Null ()
  957. {
  958. try {
  959. AppDomain.CurrentDomain.DefineDynamicAssembly (
  960. (AssemblyName) null,
  961. AssemblyBuilderAccess.Run,
  962. Path.GetTempPath (),
  963. (PermissionSet) null,
  964. (PermissionSet) null,
  965. (PermissionSet) null);
  966. Assert.Fail ("#A1");
  967. } catch (ArgumentNullException ex) {
  968. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  969. Assert.IsNull (ex.InnerException, "#A3");
  970. Assert.IsNotNull (ex.Message, "#A4");
  971. Assert.IsNotNull (ex.ParamName, "#A5");
  972. Assert.AreEqual ("name", ex.ParamName, "#A6");
  973. }
  974. AssemblyName name = new AssemblyName ();
  975. try {
  976. AppDomain.CurrentDomain.DefineDynamicAssembly (
  977. name,
  978. AssemblyBuilderAccess.Run,
  979. Path.GetTempPath (),
  980. (PermissionSet) null,
  981. (PermissionSet) null,
  982. (PermissionSet) null);
  983. Assert.Fail ("#B1");
  984. } catch (ArgumentException ex) {
  985. // AssemblyName.Name cannot be null or an empty string
  986. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  987. Assert.IsNull (ex.InnerException, "#B3");
  988. Assert.IsNotNull (ex.Message, "#B4");
  989. Assert.IsNull (ex.ParamName, "#B5");
  990. }
  991. name.Name = string.Empty;
  992. try {
  993. AppDomain.CurrentDomain.DefineDynamicAssembly (
  994. name,
  995. AssemblyBuilderAccess.Run,
  996. Path.GetTempPath (),
  997. (PermissionSet) null,
  998. (PermissionSet) null,
  999. (PermissionSet) null);
  1000. Assert.Fail ("#C1");
  1001. } catch (ArgumentException ex) {
  1002. // AssemblyName.Name cannot be null or an empty string
  1003. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  1004. Assert.IsNull (ex.InnerException, "#C3");
  1005. Assert.IsNotNull (ex.Message, "#C4");
  1006. Assert.IsNull (ex.ParamName, "#C5");
  1007. }
  1008. }
  1009. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
  1010. public void DefineDynamicAssembly8_Access_Invalid ()
  1011. {
  1012. AssemblyName name = new AssemblyName ();
  1013. name.Name = "DefineDynamicAssembly8";
  1014. #if NET_2_0
  1015. try {
  1016. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1017. name, AssemblyBuilderAccess.Run |
  1018. (AssemblyBuilderAccess) 666,
  1019. Path.GetTempPath (),
  1020. AppDomain.CurrentDomain.Evidence,
  1021. (PermissionSet) null,
  1022. (PermissionSet) null,
  1023. (PermissionSet) null);
  1024. Assert.Fail ("#1");
  1025. } catch (ArgumentException ex) {
  1026. // Illegal enum value: 667
  1027. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  1028. Assert.IsNull (ex.InnerException, "#3");
  1029. Assert.IsNotNull (ex.Message, "#4");
  1030. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  1031. Assert.IsNotNull (ex.ParamName, "#6");
  1032. Assert.AreEqual ("access", ex.ParamName, "#7");
  1033. }
  1034. #else
  1035. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  1036. name, AssemblyBuilderAccess.Run |
  1037. (AssemblyBuilderAccess) 666,
  1038. Path.GetTempPath (),
  1039. AppDomain.CurrentDomain.Evidence,
  1040. (PermissionSet) null,
  1041. (PermissionSet) null,
  1042. (PermissionSet) null);
  1043. Assert.IsNotNull (ab, "#1");
  1044. #endif
  1045. }
  1046. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
  1047. public void DefineDynamicAssembly8_Name_InvalidChars ()
  1048. {
  1049. string [] invalid_char_names = new string [] {
  1050. "\tAB",
  1051. " AB",
  1052. "\rAB",
  1053. "A/B",
  1054. ":AB",
  1055. "B:A",
  1056. "B\\A",
  1057. "BA\\"};
  1058. AssemblyName name = new AssemblyName ();
  1059. foreach (string invalid_name in invalid_char_names) {
  1060. name.Name = invalid_name;
  1061. try {
  1062. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1063. name,
  1064. AssemblyBuilderAccess.Run,
  1065. Path.GetTempPath (),
  1066. AppDomain.CurrentDomain.Evidence,
  1067. (PermissionSet) null,
  1068. (PermissionSet) null,
  1069. (PermissionSet) null);
  1070. Assert.Fail ("#1:" + invalid_name);
  1071. } catch (ArgumentException ex) {
  1072. // Assembly names may not begin with whitespace
  1073. // or contain the characters '/', '\' or ':'
  1074. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  1075. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  1076. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  1077. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  1078. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  1079. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  1080. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  1081. }
  1082. }
  1083. }
  1084. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
  1085. public void DefineDynamicAssembly8_Name_Null ()
  1086. {
  1087. try {
  1088. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1089. (AssemblyName) null,
  1090. AssemblyBuilderAccess.Run,
  1091. Path.GetTempPath (),
  1092. AppDomain.CurrentDomain.Evidence,
  1093. (PermissionSet) null,
  1094. (PermissionSet) null,
  1095. (PermissionSet) null);
  1096. Assert.Fail ("#A1");
  1097. } catch (ArgumentNullException ex) {
  1098. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  1099. Assert.IsNull (ex.InnerException, "#A3");
  1100. Assert.IsNotNull (ex.Message, "#A4");
  1101. Assert.IsNotNull (ex.ParamName, "#A5");
  1102. Assert.AreEqual ("name", ex.ParamName, "#A6");
  1103. }
  1104. AssemblyName name = new AssemblyName ();
  1105. try {
  1106. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1107. name,
  1108. AssemblyBuilderAccess.Run,
  1109. Path.GetTempPath (),
  1110. AppDomain.CurrentDomain.Evidence,
  1111. (PermissionSet) null,
  1112. (PermissionSet) null,
  1113. (PermissionSet) null);
  1114. Assert.Fail ("#B1");
  1115. } catch (ArgumentException ex) {
  1116. // AssemblyName.Name cannot be null or an empty string
  1117. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  1118. Assert.IsNull (ex.InnerException, "#B3");
  1119. Assert.IsNotNull (ex.Message, "#B4");
  1120. Assert.IsNull (ex.ParamName, "#B5");
  1121. }
  1122. name.Name = string.Empty;
  1123. try {
  1124. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1125. name,
  1126. AssemblyBuilderAccess.Run,
  1127. Path.GetTempPath (),
  1128. AppDomain.CurrentDomain.Evidence,
  1129. (PermissionSet) null,
  1130. (PermissionSet) null,
  1131. (PermissionSet) null);
  1132. Assert.Fail ("#C1");
  1133. } catch (ArgumentException ex) {
  1134. // AssemblyName.Name cannot be null or an empty string
  1135. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  1136. Assert.IsNull (ex.InnerException, "#C3");
  1137. Assert.IsNotNull (ex.Message, "#C4");
  1138. Assert.IsNull (ex.ParamName, "#C5");
  1139. }
  1140. }
  1141. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
  1142. public void DefineDynamicAssembly9_Access_Invalid ()
  1143. {
  1144. AssemblyName name = new AssemblyName ();
  1145. name.Name = "DefineDynamicAssembly9";
  1146. #if NET_2_0
  1147. try {
  1148. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1149. name, AssemblyBuilderAccess.Run |
  1150. (AssemblyBuilderAccess) 666,
  1151. Path.GetTempPath (),
  1152. AppDomain.CurrentDomain.Evidence,
  1153. (PermissionSet) null,
  1154. (PermissionSet) null,
  1155. (PermissionSet) null,
  1156. true);
  1157. Assert.Fail ("#1");
  1158. } catch (ArgumentException ex) {
  1159. // Illegal enum value: 667
  1160. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  1161. Assert.IsNull (ex.InnerException, "#3");
  1162. Assert.IsNotNull (ex.Message, "#4");
  1163. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  1164. Assert.IsNotNull (ex.ParamName, "#6");
  1165. Assert.AreEqual ("access", ex.ParamName, "#7");
  1166. }
  1167. #else
  1168. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  1169. name, AssemblyBuilderAccess.Run |
  1170. (AssemblyBuilderAccess) 666,
  1171. Path.GetTempPath (),
  1172. AppDomain.CurrentDomain.Evidence,
  1173. (PermissionSet) null,
  1174. (PermissionSet) null,
  1175. (PermissionSet) null,
  1176. true);
  1177. Assert.IsNotNull (ab, "#1");
  1178. #endif
  1179. }
  1180. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
  1181. public void DefineDynamicAssembly9_Name_InvalidChars ()
  1182. {
  1183. string [] invalid_char_names = new string [] {
  1184. "\tAB",
  1185. " AB",
  1186. "\rAB",
  1187. "A/B",
  1188. ":AB",
  1189. "B:A",
  1190. "B\\A",
  1191. "BA\\"};
  1192. AssemblyName name = new AssemblyName ();
  1193. foreach (string invalid_name in invalid_char_names) {
  1194. name.Name = invalid_name;
  1195. try {
  1196. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1197. name,
  1198. AssemblyBuilderAccess.Run,
  1199. Path.GetTempPath (),
  1200. AppDomain.CurrentDomain.Evidence,
  1201. (PermissionSet) null,
  1202. (PermissionSet) null,
  1203. (PermissionSet) null,
  1204. true);
  1205. Assert.Fail ("#1:" + invalid_name);
  1206. } catch (ArgumentException ex) {
  1207. // Assembly names may not begin with whitespace
  1208. // or contain the characters '/', '\' or ':'
  1209. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  1210. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  1211. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  1212. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  1213. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  1214. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  1215. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  1216. }
  1217. }
  1218. }
  1219. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
  1220. public void DefineDynamicAssembly9_Name_Null ()
  1221. {
  1222. try {
  1223. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1224. (AssemblyName) null,
  1225. AssemblyBuilderAccess.Run,
  1226. Path.GetTempPath (),
  1227. AppDomain.CurrentDomain.Evidence,
  1228. (PermissionSet) null,
  1229. (PermissionSet) null,
  1230. (PermissionSet) null,
  1231. true);
  1232. Assert.Fail ("#A1");
  1233. } catch (ArgumentNullException ex) {
  1234. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  1235. Assert.IsNull (ex.InnerException, "#A3");
  1236. Assert.IsNotNull (ex.Message, "#A4");
  1237. Assert.IsNotNull (ex.ParamName, "#A5");
  1238. Assert.AreEqual ("name", ex.ParamName, "#A6");
  1239. }
  1240. AssemblyName name = new AssemblyName ();
  1241. try {
  1242. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1243. name,
  1244. AssemblyBuilderAccess.Run,
  1245. Path.GetTempPath (),
  1246. AppDomain.CurrentDomain.Evidence,
  1247. (PermissionSet) null,
  1248. (PermissionSet) null,
  1249. (PermissionSet) null,
  1250. true);
  1251. Assert.Fail ("#B1");
  1252. } catch (ArgumentException ex) {
  1253. // AssemblyName.Name cannot be null or an empty string
  1254. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  1255. Assert.IsNull (ex.InnerException, "#B3");
  1256. Assert.IsNotNull (ex.Message, "#B4");
  1257. Assert.IsNull (ex.ParamName, "#B5");
  1258. }
  1259. name.Name = string.Empty;
  1260. try {
  1261. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1262. name,
  1263. AssemblyBuilderAccess.Run,
  1264. Path.GetTempPath (),
  1265. AppDomain.CurrentDomain.Evidence,
  1266. (PermissionSet) null,
  1267. (PermissionSet) null,
  1268. (PermissionSet) null,
  1269. true);
  1270. Assert.Fail ("#C1");
  1271. } catch (ArgumentException ex) {
  1272. // AssemblyName.Name cannot be null or an empty string
  1273. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  1274. Assert.IsNull (ex.InnerException, "#C3");
  1275. Assert.IsNotNull (ex.Message, "#C4");
  1276. Assert.IsNull (ex.ParamName, "#C5");
  1277. }
  1278. }
  1279. #if NET_2_0
  1280. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
  1281. public void DefineDynamicAssembly10_Access_Invalid ()
  1282. {
  1283. AssemblyName name = new AssemblyName ();
  1284. name.Name = "DefineDynamicAssembly10";
  1285. #if NET_2_0
  1286. try {
  1287. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1288. name, AssemblyBuilderAccess.Run |
  1289. (AssemblyBuilderAccess) 666,
  1290. Path.GetTempPath (),
  1291. AppDomain.CurrentDomain.Evidence,
  1292. (PermissionSet) null,
  1293. (PermissionSet) null,
  1294. (PermissionSet) null,
  1295. true,
  1296. new List<CustomAttributeBuilder> ());
  1297. Assert.Fail ("#1");
  1298. } catch (ArgumentException ex) {
  1299. // Illegal enum value: 667
  1300. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  1301. Assert.IsNull (ex.InnerException, "#3");
  1302. Assert.IsNotNull (ex.Message, "#4");
  1303. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  1304. Assert.IsNotNull (ex.ParamName, "#6");
  1305. Assert.AreEqual ("access", ex.ParamName, "#7");
  1306. }
  1307. #else
  1308. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  1309. name, AssemblyBuilderAccess.Run |
  1310. (AssemblyBuilderAccess) 666,
  1311. Path.GetTempPath (),
  1312. AppDomain.CurrentDomain.Evidence,
  1313. (PermissionSet) null,
  1314. (PermissionSet) null,
  1315. (PermissionSet) null,
  1316. true,
  1317. new List<CustomAttributeBuilder> ());
  1318. Assert.IsNotNull (ab, "#1");
  1319. #endif
  1320. }
  1321. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
  1322. public void DefineDynamicAssembly10_Name_InvalidChars ()
  1323. {
  1324. string [] invalid_char_names = new string [] {
  1325. "\tAB",
  1326. " AB",
  1327. "\rAB",
  1328. "A/B",
  1329. ":AB",
  1330. "B:A",
  1331. "B\\A",
  1332. "BA\\"};
  1333. AssemblyName name = new AssemblyName ();
  1334. foreach (string invalid_name in invalid_char_names) {
  1335. name.Name = invalid_name;
  1336. try {
  1337. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1338. name,
  1339. AssemblyBuilderAccess.Run,
  1340. Path.GetTempPath (),
  1341. AppDomain.CurrentDomain.Evidence,
  1342. (PermissionSet) null,
  1343. (PermissionSet) null,
  1344. (PermissionSet) null,
  1345. true,
  1346. new List<CustomAttributeBuilder> ());
  1347. Assert.Fail ("#1:" + invalid_name);
  1348. } catch (ArgumentException ex) {
  1349. // Assembly names may not begin with whitespace
  1350. // or contain the characters '/', '\' or ':'
  1351. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  1352. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  1353. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  1354. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  1355. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  1356. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  1357. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  1358. }
  1359. }
  1360. }
  1361. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
  1362. public void DefineDynamicAssembly10_Name_Null ()
  1363. {
  1364. try {
  1365. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1366. (AssemblyName) null,
  1367. AssemblyBuilderAccess.Run,
  1368. Path.GetTempPath (),
  1369. AppDomain.CurrentDomain.Evidence,
  1370. (PermissionSet) null,
  1371. (PermissionSet) null,
  1372. (PermissionSet) null,
  1373. true,
  1374. new List<CustomAttributeBuilder> ());
  1375. Assert.Fail ("#A1");
  1376. } catch (ArgumentNullException ex) {
  1377. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  1378. Assert.IsNull (ex.InnerException, "#A3");
  1379. Assert.IsNotNull (ex.Message, "#A4");
  1380. Assert.IsNotNull (ex.ParamName, "#A5");
  1381. Assert.AreEqual ("name", ex.ParamName, "#A6");
  1382. }
  1383. AssemblyName name = new AssemblyName ();
  1384. try {
  1385. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1386. name,
  1387. AssemblyBuilderAccess.Run,
  1388. Path.GetTempPath (),
  1389. AppDomain.CurrentDomain.Evidence,
  1390. (PermissionSet) null,
  1391. (PermissionSet) null,
  1392. (PermissionSet) null,
  1393. true,
  1394. new List<CustomAttributeBuilder> ());
  1395. Assert.Fail ("#B1");
  1396. } catch (ArgumentException ex) {
  1397. // AssemblyName.Name cannot be null or an empty string
  1398. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  1399. Assert.IsNull (ex.InnerException, "#B3");
  1400. Assert.IsNotNull (ex.Message, "#B4");
  1401. Assert.IsNull (ex.ParamName, "#B5");
  1402. }
  1403. name.Name = string.Empty;
  1404. try {
  1405. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1406. name,
  1407. AssemblyBuilderAccess.Run,
  1408. Path.GetTempPath (),
  1409. AppDomain.CurrentDomain.Evidence,
  1410. (PermissionSet) null,
  1411. (PermissionSet) null,
  1412. (PermissionSet) null,
  1413. true,
  1414. new List<CustomAttributeBuilder> ());
  1415. Assert.Fail ("#C1");
  1416. } catch (ArgumentException ex) {
  1417. // AssemblyName.Name cannot be null or an empty string
  1418. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  1419. Assert.IsNull (ex.InnerException, "#C3");
  1420. Assert.IsNotNull (ex.Message, "#C4");
  1421. Assert.IsNull (ex.ParamName, "#C5");
  1422. }
  1423. }
  1424. [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
  1425. public void DefineDynamicAssembly11 ()
  1426. {
  1427. List<CustomAttributeBuilder> cattrs;
  1428. AssemblyBuilder ab;
  1429. Attribute attr;
  1430. AssemblyName name;
  1431. string assemblyFile;
  1432. string current_dir = Directory.GetCurrentDirectory ();
  1433. name = new AssemblyName ();
  1434. name.Name = "DefineDynamicAssembly11A";
  1435. cattrs = new List<CustomAttributeBuilder> ();
  1436. cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).
  1437. GetConstructor (new Type [] { typeof (string) }),
  1438. new object [] { "1.2.3.4"}));
  1439. cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).
  1440. GetConstructor (new Type [] { typeof (string) }),
  1441. new object [] { "nl-BE"}));
  1442. cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).
  1443. GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }),
  1444. new object [] { AssemblyHashAlgorithm.MD5 }));
  1445. cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).
  1446. GetConstructor (new Type [] { typeof (uint) }),
  1447. new object [] { (uint)0x0100 }));
  1448. cattrs.Add (new CustomAttributeBuilder (typeof (CLSCompliantAttribute).
  1449. GetConstructor (new Type [] { typeof (bool) }),
  1450. new object [] { true }));
  1451. ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  1452. name, AssemblyBuilderAccess.Save, cattrs);
  1453. ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (ComVisibleAttribute).
  1454. GetConstructor (new Type [] { typeof (bool) }),
  1455. new object [] { true }));
  1456. ab.Save ("DefineDynamicAssembly11A.dll");
  1457. assemblyFile = Path.Combine (current_dir, "DefineDynamicAssembly11A.dll");
  1458. try {
  1459. AssemblyName an = AssemblyName.GetAssemblyName (assemblyFile);
  1460. Assert.AreEqual (CultureInfo.InvariantCulture, an.CultureInfo, "#A1");
  1461. Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "#A2");
  1462. Assert.AreEqual ("DefineDynamicAssembly11A, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", an.FullName, "#A3");
  1463. Assert.IsNull (an.GetPublicKey (), "#A4");
  1464. Assert.AreEqual (new byte [0], an.GetPublicKeyToken (), "#A5");
  1465. Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "#A6");
  1466. Assert.IsNull (an.KeyPair, "#A7");
  1467. Assert.AreEqual ("DefineDynamicAssembly11A", an.Name, "#A8");
  1468. //Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "#A9");
  1469. Assert.AreEqual (an.FullName, an.ToString (), "#A10");
  1470. Assert.AreEqual (new Version (0, 0, 0, 0), an.Version, "#A11");
  1471. Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, an.VersionCompatibility, "#A12");
  1472. Assembly a;
  1473. using (FileStream fs = File.OpenRead (assemblyFile)) {
  1474. byte [] buffer = new byte [fs.Length];
  1475. fs.Read (buffer, 0, buffer.Length);
  1476. a = Assembly.Load (buffer);
  1477. }
  1478. attr = Attribute.GetCustomAttribute (a, typeof (AssemblyVersionAttribute));
  1479. Assert.IsNotNull (attr, "#A13a");
  1480. Assert.AreEqual ("1.2.3.4", ((AssemblyVersionAttribute) attr).Version, "#A13b");
  1481. attr = Attribute.GetCustomAttribute (a, typeof (AssemblyCultureAttribute));
  1482. Assert.IsNotNull (attr, "#A14a");
  1483. Assert.AreEqual ("nl-BE", ((AssemblyCultureAttribute) attr).Culture, "#A14b");
  1484. attr = Attribute.GetCustomAttribute (a, typeof (AssemblyAlgorithmIdAttribute));
  1485. Assert.IsNotNull (attr, "#A15a");
  1486. Assert.AreEqual ((uint) AssemblyHashAlgorithm.MD5, ((AssemblyAlgorithmIdAttribute) attr).AlgorithmId, "#A15b");
  1487. attr = Attribute.GetCustomAttribute (a, typeof (AssemblyFlagsAttribute));
  1488. Assert.IsNotNull (attr, "#A16a");
  1489. Assert.AreEqual ((uint) 0x0100, ((AssemblyFlagsAttribute) attr).Flags, "#A16b");
  1490. attr = Attribute.GetCustomAttribute (a, typeof (CLSCompliantAttribute));
  1491. Assert.IsNotNull (attr, "#A17a");
  1492. Assert.IsTrue (((CLSCompliantAttribute) attr).IsCompliant, "#A17b");
  1493. attr = Attribute.GetCustomAttribute (a, typeof (ComVisibleAttribute));
  1494. Assert.IsNotNull (attr, "#A18a");
  1495. Assert.IsTrue (((ComVisibleAttribute) attr).Value, "#A18b");
  1496. } finally {
  1497. File.Delete (assemblyFile);
  1498. }
  1499. name = new AssemblyName ();
  1500. name.CultureInfo = new CultureInfo ("fr-BE");
  1501. name.KeyPair = new StrongNameKeyPair (keyPair);
  1502. name.Name = "DefineDynamicAssembly11B";
  1503. name.Version = new Version (3, 2, 4, 1);
  1504. cattrs = new List<CustomAttributeBuilder> ();
  1505. cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyVersionAttribute).
  1506. GetConstructor (new Type [] { typeof (string) }),
  1507. new object [] { "1.2.3.4"}));
  1508. cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyCultureAttribute).
  1509. GetConstructor (new Type [] { typeof (string) }),
  1510. new object [] { "nl-BE"}));
  1511. cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyAlgorithmIdAttribute).
  1512. GetConstructor (new Type [] { typeof (AssemblyHashAlgorithm) }),
  1513. new object [] { AssemblyHashAlgorithm.MD5 }));
  1514. cattrs.Add (new CustomAttributeBuilder (typeof (AssemblyFlagsAttribute).
  1515. GetConstructor (new Type [] { typeof (uint) }),
  1516. new object [] { (uint)0x0100 }));
  1517. cattrs.Add (new CustomAttributeBuilder (typeof (CLSCompliantAttribute).
  1518. GetConstructor (new Type [] { typeof (bool) }),
  1519. new object [] { true }));
  1520. ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  1521. name, AssemblyBuilderAccess.Save, cattrs);
  1522. ab.SetCustomAttribute (new CustomAttributeBuilder (typeof (ComVisibleAttribute).
  1523. GetConstructor (new Type [] { typeof (bool) }),
  1524. new object [] { true }));
  1525. ab.Save ("DefineDynamicAssembly11B.dll");
  1526. assemblyFile = Path.Combine (current_dir, "DefineDynamicAssembly11B.dll");
  1527. try {
  1528. AssemblyName an = AssemblyName.GetAssemblyName (assemblyFile);
  1529. Assert.AreEqual ("fr-BE", an.CultureInfo.Name, "#B1");
  1530. Assert.AreEqual (AssemblyNameFlags.PublicKey, an.Flags, "#B2");
  1531. Assert.AreEqual ("DefineDynamicAssembly11B, Version=3.2.4.1, Culture=fr-BE, PublicKeyToken=ce5276d8687ec6dc", an.FullName, "#B3");
  1532. Assert.AreEqual (publicKey, an.GetPublicKey (), "#B4");
  1533. Assert.AreEqual (pk_token, an.GetPublicKeyToken (), "#B5");
  1534. Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "#B6");
  1535. Assert.IsNull (an.KeyPair, "#B7");
  1536. Assert.AreEqual ("DefineDynamicAssembly11B", an.Name, "#B8");
  1537. //Assert.AreEqual (ProcessorArchitecture.MSIL, an.ProcessorArchitecture, "#B9");
  1538. Assert.AreEqual (an.FullName, an.ToString (), "#B10");
  1539. Assert.AreEqual (new Version (3, 2, 4, 1), an.Version, "#B11");
  1540. Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, an.VersionCompatibility, "#B12");
  1541. Assembly a;
  1542. using (FileStream fs = File.OpenRead (assemblyFile)) {
  1543. byte [] buffer = new byte [fs.Length];
  1544. fs.Read (buffer, 0, buffer.Length);
  1545. a = Assembly.Load (buffer);
  1546. }
  1547. attr = Attribute.GetCustomAttribute (a, typeof (AssemblyVersionAttribute));
  1548. Assert.IsNotNull (attr, "#B13a");
  1549. Assert.AreEqual ("1.2.3.4", ((AssemblyVersionAttribute) attr).Version, "#B13b");
  1550. attr = Attribute.GetCustomAttribute (a, typeof (AssemblyCultureAttribute));
  1551. Assert.IsNotNull (attr, "#B14a");
  1552. Assert.AreEqual ("nl-BE", ((AssemblyCultureAttribute) attr).Culture, "#B14b");
  1553. attr = Attribute.GetCustomAttribute (a, typeof (AssemblyAlgorithmIdAttribute));
  1554. Assert.IsNotNull (attr, "#B15a");
  1555. Assert.AreEqual ((uint) AssemblyHashAlgorithm.MD5, ((AssemblyAlgorithmIdAttribute) attr).AlgorithmId, "#B15b");
  1556. attr = Attribute.GetCustomAttribute (a, typeof (AssemblyFlagsAttribute));
  1557. Assert.IsNotNull (attr, "#B16a");
  1558. Assert.AreEqual ((uint) 0x0100, ((AssemblyFlagsAttribute) attr).Flags, "#B16b");
  1559. attr = Attribute.GetCustomAttribute (a, typeof (CLSCompliantAttribute));
  1560. Assert.IsNotNull (attr, "#B17a");
  1561. Assert.IsTrue (((CLSCompliantAttribute) attr).IsCompliant, "#B17b");
  1562. attr = Attribute.GetCustomAttribute (a, typeof (ComVisibleAttribute));
  1563. Assert.IsNotNull (attr, "#B18a");
  1564. Assert.IsTrue (((ComVisibleAttribute) attr).Value, "#B18b");
  1565. } finally {
  1566. File.Delete (assemblyFile);
  1567. }
  1568. }
  1569. [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
  1570. public void DefineDynamicAssembly11_Access_Invalid ()
  1571. {
  1572. AssemblyName name = new AssemblyName ();
  1573. name.Name = "DefineDynamicAssembly11";
  1574. #if NET_2_0
  1575. try {
  1576. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1577. name, AssemblyBuilderAccess.Run |
  1578. (AssemblyBuilderAccess) 666,
  1579. new List<CustomAttributeBuilder> ());
  1580. Assert.Fail ("#1");
  1581. } catch (ArgumentException ex) {
  1582. // Illegal enum value: 667
  1583. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  1584. Assert.IsNull (ex.InnerException, "#3");
  1585. Assert.IsNotNull (ex.Message, "#4");
  1586. Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
  1587. Assert.IsNotNull (ex.ParamName, "#6");
  1588. Assert.AreEqual ("access", ex.ParamName, "#7");
  1589. }
  1590. #else
  1591. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  1592. name, AssemblyBuilderAccess.Run |
  1593. (AssemblyBuilderAccess) 666,
  1594. new List<CustomAttributeBuilder> ());
  1595. Assert.IsNotNull (ab, "#1");
  1596. #endif
  1597. }
  1598. [Test] // DefineDynamicAssembly (AssemblyName name, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)
  1599. public void DefineDynamicAssembly11_Name_InvalidChars ()
  1600. {
  1601. string [] invalid_char_names = new string [] {
  1602. "\tAB",
  1603. " AB",
  1604. "\rAB",
  1605. "A/B",
  1606. ":AB",
  1607. "B:A",
  1608. "B\\A",
  1609. "BA\\"};
  1610. AssemblyName name = new AssemblyName ();
  1611. foreach (string invalid_name in invalid_char_names) {
  1612. name.Name = invalid_name;
  1613. try {
  1614. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1615. name,
  1616. AssemblyBuilderAccess.Run,
  1617. new List<CustomAttributeBuilder> ());
  1618. Assert.Fail ("#1:" + invalid_name);
  1619. } catch (ArgumentException ex) {
  1620. // Assembly names may not begin with whitespace
  1621. // or contain the characters '/', '\' or ':'
  1622. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
  1623. Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
  1624. Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
  1625. Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
  1626. Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
  1627. Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
  1628. Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
  1629. }
  1630. }
  1631. }
  1632. [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
  1633. public void DefineDynamicAssembly11_Name_Null ()
  1634. {
  1635. try {
  1636. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1637. (AssemblyName) null,
  1638. AssemblyBuilderAccess.Run,
  1639. new List<CustomAttributeBuilder> ());
  1640. Assert.Fail ("#A1");
  1641. } catch (ArgumentNullException ex) {
  1642. Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
  1643. Assert.IsNull (ex.InnerException, "#A3");
  1644. Assert.IsNotNull (ex.Message, "#A4");
  1645. Assert.IsNotNull (ex.ParamName, "#A5");
  1646. Assert.AreEqual ("name", ex.ParamName, "#A6");
  1647. }
  1648. AssemblyName name = new AssemblyName ();
  1649. try {
  1650. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1651. name,
  1652. AssemblyBuilderAccess.Run,
  1653. new List<CustomAttributeBuilder> ());
  1654. Assert.Fail ("#B1");
  1655. } catch (ArgumentException ex) {
  1656. // AssemblyName.Name cannot be null or an empty string
  1657. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
  1658. Assert.IsNull (ex.InnerException, "#B3");
  1659. Assert.IsNotNull (ex.Message, "#B4");
  1660. Assert.IsNull (ex.ParamName, "#B5");
  1661. }
  1662. name.Name = string.Empty;
  1663. try {
  1664. AppDomain.CurrentDomain.DefineDynamicAssembly (
  1665. name,
  1666. AssemblyBuilderAccess.Run,
  1667. new List<CustomAttributeBuilder> ());
  1668. Assert.Fail ("#C1");
  1669. } catch (ArgumentException ex) {
  1670. // AssemblyName.Name cannot be null or an empty string
  1671. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
  1672. Assert.IsNull (ex.InnerException, "#C3");
  1673. Assert.IsNotNull (ex.Message, "#C4");
  1674. Assert.IsNull (ex.ParamName, "#C5");
  1675. }
  1676. }
  1677. [Test] // ExecuteAssemblyByName (String)
  1678. public void ExecuteAssemblyByName1_NoEntryPoint ()
  1679. {
  1680. try {
  1681. AppDomain.CurrentDomain.ExecuteAssemblyByName ("mscorlib");
  1682. Assert.Fail ("#1");
  1683. } catch (MissingMethodException ex) {
  1684. // Entry point not found in assembly '...'
  1685. Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
  1686. Assert.IsNull (ex.InnerException, "#3");
  1687. Assert.IsNotNull (ex.Message, "#4");
  1688. Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
  1689. }
  1690. }
  1691. [Test] // ExecuteAssemblyByName (String, Evidence)
  1692. public void ExecuteAssemblyByName2_NoEntryPoint ()
  1693. {
  1694. try {
  1695. AppDomain.CurrentDomain.ExecuteAssemblyByName (
  1696. "mscorlib", (Evidence) null);
  1697. Assert.Fail ("#1");
  1698. } catch (MissingMethodException ex) {
  1699. // Entry point not found in assembly '...'
  1700. Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
  1701. Assert.IsNull (ex.InnerException, "#3");
  1702. Assert.IsNotNull (ex.Message, "#4");
  1703. Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
  1704. }
  1705. }
  1706. [Test] // ExecuteAssemblyByName (String, Evidence, String [])
  1707. public void ExecuteAssemblyByName3_NoEntryPoint ()
  1708. {
  1709. try {
  1710. AppDomain.CurrentDomain.ExecuteAssemblyByName (
  1711. "mscorlib", (Evidence) null,
  1712. new string [0]);
  1713. Assert.Fail ("#1");
  1714. } catch (MissingMethodException ex) {
  1715. // Entry point not found in assembly '...'
  1716. Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
  1717. Assert.IsNull (ex.InnerException, "#3");
  1718. Assert.IsNotNull (ex.Message, "#4");
  1719. Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
  1720. }
  1721. }
  1722. [Test] // ExecuteAssemblyByName (AssemblyName, Evidence, String [])
  1723. public void ExecuteAssemblyByName4_NoEntryPoint ()
  1724. {
  1725. AssemblyName aname = new AssemblyName ("mscorlib");
  1726. try {
  1727. AppDomain.CurrentDomain.ExecuteAssemblyByName (
  1728. aname, (Evidence) null, new string [0]);
  1729. Assert.Fail ("#1");
  1730. } catch (MissingMethodException ex) {
  1731. // Entry point not found in assembly '...'
  1732. Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
  1733. Assert.IsNull (ex.InnerException, "#3");
  1734. Assert.IsNotNull (ex.Message, "#4");
  1735. Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5");
  1736. }
  1737. }
  1738. #endif
  1739. [Test]
  1740. public void SetThreadPrincipal ()
  1741. {
  1742. IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
  1743. IPrincipal p = new GenericPrincipal (i, null);
  1744. ad = AppDomain.CreateDomain ("SetThreadPrincipal");
  1745. ad.SetThreadPrincipal (p);
  1746. }
  1747. [Test]
  1748. [ExpectedException (typeof (ArgumentNullException))]
  1749. public void SetThreadPrincipalNull ()
  1750. {
  1751. AppDomain.CurrentDomain.SetThreadPrincipal (null);
  1752. }
  1753. [Test]
  1754. [ExpectedException (typeof (PolicyException))]
  1755. public void SetThreadPrincipalTwice ()
  1756. {
  1757. IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
  1758. IPrincipal p = new GenericPrincipal (i, null);
  1759. ad = AppDomain.CreateDomain ("SetThreadPrincipalTwice");
  1760. ad.SetThreadPrincipal (p);
  1761. // you only live twice (or so James told me ;-)
  1762. ad.SetThreadPrincipal (p);
  1763. }
  1764. [Test]
  1765. [ExpectedException (typeof (AppDomainUnloadedException))]
  1766. public void SetThreadPrincipalUnloaded ()
  1767. {
  1768. ad = AppDomain.CreateDomain ("Ximian");
  1769. AppDomain.Unload (ad);
  1770. IIdentity i = new GenericIdentity ("sebastien@ximian.com", "rfc822");
  1771. IPrincipal p = new GenericPrincipal (i, null);
  1772. ad.SetThreadPrincipal (p);
  1773. }
  1774. [Test]
  1775. public void SetPrincipalPolicy_NoPrincipal ()
  1776. {
  1777. AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
  1778. }
  1779. [Test]
  1780. public void SetPrincipalPolicy_UnauthenticatedPrincipal ()
  1781. {
  1782. AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.UnauthenticatedPrincipal);
  1783. }
  1784. [Test]
  1785. public void SetPrincipalPolicy_WindowsPrincipal ()
  1786. {
  1787. AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.WindowsPrincipal);
  1788. }
  1789. [Test]
  1790. [ExpectedException (typeof (AppDomainUnloadedException))]
  1791. public void SetPrincipalPolicyUnloaded ()
  1792. {
  1793. ad = AppDomain.CreateDomain ("Ximian");
  1794. AppDomain.Unload (ad);
  1795. ad.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
  1796. }
  1797. [Test]
  1798. public void CreateDomain_String ()
  1799. {
  1800. ad = AppDomain.CreateDomain ("CreateDomain_String");
  1801. Assert.IsNotNull (ad.Evidence, "Evidence");
  1802. // Evidence are copied (or referenced?) from default app domain
  1803. // we can't get default so we use the current (which should have copied the default)
  1804. Assert.AreEqual (AppDomain.CurrentDomain.Evidence.Count, ad.Evidence.Count, "Evidence.Count");
  1805. }
  1806. [Test]
  1807. [ExpectedException (typeof (ArgumentNullException))]
  1808. public void CreateDomain_String_Null ()
  1809. {
  1810. ad = AppDomain.CreateDomain (null);
  1811. }
  1812. [Test]
  1813. [Category ("NotDotNet")]
  1814. public void CreateDomain_StringEvidence ()
  1815. {
  1816. Evidence e = new Evidence ();
  1817. ad = AppDomain.CreateDomain ("CreateDomain_StringEvidence", e);
  1818. Assert.IsNotNull (ad.Evidence, "Evidence");
  1819. Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
  1820. e.AddHost (new Zone (SecurityZone.MyComputer));
  1821. Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
  1822. // evidence isn't copied but referenced
  1823. }
  1824. [Test]
  1825. [ExpectedException (typeof (ArgumentNullException))]
  1826. public void CreateDomain_StringNullEvidence ()
  1827. {
  1828. ad = AppDomain.CreateDomain (null, new Evidence ());
  1829. }
  1830. [Test]
  1831. public void CreateDomain_StringEvidenceNull ()
  1832. {
  1833. ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceNull", null);
  1834. Assert.IsNotNull (ad.Evidence, "Evidence");
  1835. // Evidence are copied (or referenced?) from default app domain
  1836. // we can't get default so we use the current (which should have copied the default)
  1837. Evidence e = AppDomain.CurrentDomain.Evidence;
  1838. Assert.AreEqual (e.Count, ad.Evidence.Count, "Evidence.Count-1");
  1839. e.AddHost (new Zone (SecurityZone.MyComputer));
  1840. Assert.AreEqual (e.Count - 1, ad.Evidence.Count, "Evidence.Count-2");
  1841. // evidence are copied
  1842. }
  1843. [Test]
  1844. [Category ("NotDotNet")]
  1845. public void CreateDomain_StringEvidenceAppDomainSetup ()
  1846. {
  1847. Evidence e = new Evidence ();
  1848. AppDomainSetup info = new AppDomainSetup ();
  1849. info.ApplicationName = "ApplicationName";
  1850. ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceAppDomainSetup", e, info);
  1851. Assert.IsNotNull (ad.Evidence, "Evidence");
  1852. Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
  1853. Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
  1854. Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName);
  1855. e.AddHost (new Zone (SecurityZone.MyComputer));
  1856. Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
  1857. // evidence isn't copied but referenced
  1858. }
  1859. [Test]
  1860. [ExpectedException (typeof (ArgumentNullException))]
  1861. public void CreateDomain_StringNullEvidenceAppDomainSetup ()
  1862. {
  1863. AppDomainSetup info = new AppDomainSetup ();
  1864. ad = AppDomain.CreateDomain (null, new Evidence (), info);
  1865. }
  1866. [Test]
  1867. public void CreateDomain_StringEvidenceNullAppDomainSetup ()
  1868. {
  1869. AppDomainSetup info = new AppDomainSetup ();
  1870. info.ApplicationName = "ApplicationName";
  1871. ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceNullAppDomainSetup", null, info);
  1872. Assert.IsNotNull (ad.Evidence, "Evidence");
  1873. // Evidence are copied (or referenced?) from default app domain
  1874. // we can't get default so we use the current (which should have copied the default)
  1875. Assert.AreEqual (AppDomain.CurrentDomain.Evidence.Count, ad.Evidence.Count, "Evidence.Count");
  1876. Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName, "ApplicationName-1");
  1877. info.ApplicationName = "Test";
  1878. Assert.AreEqual ("Test", info.ApplicationName, "ApplicationName-2");
  1879. Assert.AreEqual ("ApplicationName", ad.SetupInformation.ApplicationName, "ApplicationName-3");
  1880. // copied
  1881. }
  1882. [Test]
  1883. [Category ("NotDotNet")]
  1884. public void CreateDomain_StringEvidenceAppDomainSetupNull ()
  1885. {
  1886. Evidence e = new Evidence ();
  1887. ad = AppDomain.CreateDomain ("CreateDomain_StringEvidenceAppDomainSetupNull", e, null);
  1888. Assert.IsNotNull (ad.Evidence, "Evidence");
  1889. Assert.AreEqual (0, ad.Evidence.Count, "Evidence.Count");
  1890. // SetupInformation is copied from default app domain
  1891. Assert.IsNotNull (ad.SetupInformation, "SetupInformation");
  1892. }
  1893. [Test] // ExecuteAssembly (String)
  1894. public void ExecuteAssembly1_NoEntryPoint ()
  1895. {
  1896. Assembly assembly = typeof (AppDomainTest).Assembly;
  1897. try {
  1898. AppDomain.CurrentDomain.ExecuteAssembly (
  1899. assembly.Location);
  1900. Assert.Fail ("#1");
  1901. #if NET_2_0
  1902. } catch (MissingMethodException ex) {
  1903. // Entry point not found in assembly '...'
  1904. Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
  1905. Assert.IsNull (ex.InnerException, "#3");
  1906. Assert.IsNotNull (ex.Message, "#4");
  1907. Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
  1908. }
  1909. #else
  1910. } catch (COMException ex) {
  1911. // Unspecified error
  1912. Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
  1913. Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
  1914. Assert.IsNull (ex.InnerException, "#4");
  1915. Assert.IsNotNull (ex.Message, "#5");
  1916. }
  1917. #endif
  1918. }
  1919. [Test] // ExecuteAssembly (String, Evidence)
  1920. public void ExecuteAssembly2_NoEntryPoint ()
  1921. {
  1922. Assembly assembly = typeof (AppDomainTest).Assembly;
  1923. try {
  1924. AppDomain.CurrentDomain.ExecuteAssembly (
  1925. assembly.Location,
  1926. (Evidence) null);
  1927. Assert.Fail ("#1");
  1928. #if NET_2_0
  1929. } catch (MissingMethodException ex) {
  1930. // Entry point not found in assembly '...'
  1931. Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
  1932. Assert.IsNull (ex.InnerException, "#3");
  1933. Assert.IsNotNull (ex.Message, "#4");
  1934. Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
  1935. }
  1936. #else
  1937. } catch (COMException ex) {
  1938. // Unspecified error
  1939. Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
  1940. Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
  1941. Assert.IsNull (ex.InnerException, "#4");
  1942. Assert.IsNotNull (ex.Message, "#5");
  1943. }
  1944. #endif
  1945. }
  1946. [Test] // ExecuteAssembly (String, Evidence, String [])
  1947. public void ExecuteAssembly3_NoEntryPoint ()
  1948. {
  1949. Assembly assembly = typeof (AppDomainTest).Assembly;
  1950. try {
  1951. AppDomain.CurrentDomain.ExecuteAssembly (
  1952. assembly.Location,
  1953. (Evidence) null,
  1954. new string [0]);
  1955. Assert.Fail ("#1");
  1956. #if NET_2_0
  1957. } catch (MissingMethodException ex) {
  1958. // Entry point not found in assembly '...'
  1959. Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
  1960. Assert.IsNull (ex.InnerException, "#3");
  1961. Assert.IsNotNull (ex.Message, "#4");
  1962. Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
  1963. }
  1964. #else
  1965. } catch (COMException ex) {
  1966. // Unspecified error
  1967. Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
  1968. Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
  1969. Assert.IsNull (ex.InnerException, "#4");
  1970. Assert.IsNotNull (ex.Message, "#5");
  1971. }
  1972. #endif
  1973. }
  1974. [Test] // ExecuteAssembly (String, Evidence, String [], Byte [], AssemblyHashAlgorithm)
  1975. [Category ("NotWorking")] // Not implemented
  1976. public void ExecuteAssembly4_NoEntryPoint ()
  1977. {
  1978. Assembly assembly = typeof (AppDomainTest).Assembly;
  1979. try {
  1980. AppDomain.CurrentDomain.ExecuteAssembly (
  1981. assembly.Location,
  1982. (Evidence) null,
  1983. new string [0],
  1984. (byte []) null,
  1985. AssemblyHashAlgorithm.SHA1);
  1986. Assert.Fail ("#1");
  1987. #if NET_2_0
  1988. } catch (MissingMethodException ex) {
  1989. // Entry point not found in assembly '...'
  1990. Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
  1991. Assert.IsNull (ex.InnerException, "#3");
  1992. Assert.IsNotNull (ex.Message, "#4");
  1993. Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
  1994. }
  1995. #else
  1996. } catch (COMException ex) {
  1997. // Unspecified error
  1998. Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
  1999. Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
  2000. Assert.IsNull (ex.InnerException, "#4");
  2001. Assert.IsNotNull (ex.Message, "#5");
  2002. }
  2003. #endif
  2004. }
  2005. [Test] // bug #79720
  2006. [Category ("NotWorking")]
  2007. public void Load_Loaded_Ignore ()
  2008. {
  2009. int assemblyStartCount = AppDomain.CurrentDomain.GetAssemblies ().Length;
  2010. // PART A
  2011. string assemblyFile = Path.Combine (tempDir, "bug79720A.dll");
  2012. AssemblyName aname = new AssemblyName ();
  2013. aname.Name = "bug79720A";
  2014. aname.Version = new Version (2, 4);
  2015. GenerateAssembly (aname, assemblyFile);
  2016. Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A1");
  2017. aname = new AssemblyName ();
  2018. aname.Name = "bug79720A";
  2019. try {
  2020. AppDomain.CurrentDomain.Load (aname);
  2021. Assert.Fail ("#A2");
  2022. } catch (FileNotFoundException) {
  2023. }
  2024. aname = new AssemblyName ();
  2025. aname.Name = "bug79720A";
  2026. aname.Version = new Version (0, 0, 0, 0);
  2027. try {
  2028. AppDomain.CurrentDomain.Load (aname);
  2029. Assert.Fail ("#A3");
  2030. } catch (FileNotFoundException) {
  2031. }
  2032. aname = new AssemblyName ();
  2033. aname.Name = "bug79720A";
  2034. aname.Version = new Version (2, 4);
  2035. try {
  2036. AppDomain.CurrentDomain.Load (aname);
  2037. Assert.Fail ("#A4");
  2038. } catch (FileNotFoundException) {
  2039. }
  2040. Assert.AreEqual (assemblyStartCount, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A5");
  2041. Assembly.LoadFrom (assemblyFile);
  2042. Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A6");
  2043. aname = new AssemblyName ();
  2044. aname.Name = "bug79720A";
  2045. try {
  2046. AppDomain.CurrentDomain.Load (aname);
  2047. Assert.Fail ("#A7");
  2048. } catch (FileNotFoundException) {
  2049. }
  2050. aname = new AssemblyName ();
  2051. aname.Name = "bug79720A";
  2052. aname.Version = new Version (0, 0, 0, 0);
  2053. try {
  2054. AppDomain.CurrentDomain.Load (aname);
  2055. Assert.Fail ("#A8");
  2056. } catch (FileNotFoundException) {
  2057. }
  2058. aname = new AssemblyName ();
  2059. aname.Name = "bug79720A";
  2060. aname.Version = new Version (2, 4);
  2061. try {
  2062. AppDomain.CurrentDomain.Load (aname);
  2063. Assert.Fail ("#A9");
  2064. } catch (FileNotFoundException) {
  2065. }
  2066. aname = new AssemblyName ();
  2067. aname.Name = "bug79720A";
  2068. aname.Version = new Version (2, 4);
  2069. aname.CultureInfo = CultureInfo.InvariantCulture;
  2070. try {
  2071. AppDomain.CurrentDomain.Load (aname);
  2072. Assert.Fail ("#A10");
  2073. } catch (FileNotFoundException) {
  2074. }
  2075. aname = new AssemblyName ();
  2076. aname.Name = "bug79720A";
  2077. aname.Version = new Version (2, 4, 0, 0);
  2078. aname.CultureInfo = CultureInfo.InvariantCulture;
  2079. try {
  2080. AppDomain.CurrentDomain.Load (aname);
  2081. Assert.Fail ("#A11");
  2082. } catch (FileNotFoundException) {
  2083. }
  2084. Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#A12");
  2085. // PART B
  2086. assemblyFile = Path.Combine (tempDir, "bug79720B.dll");
  2087. aname = new AssemblyName ();
  2088. aname.Name = "bug79720B";
  2089. aname.Version = new Version (2, 4, 1);
  2090. aname.CultureInfo = new CultureInfo ("nl-BE");
  2091. GenerateAssembly (aname, assemblyFile);
  2092. Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B1");
  2093. aname = new AssemblyName ();
  2094. aname.Name = "bug79720B";
  2095. try {
  2096. AppDomain.CurrentDomain.Load (aname);
  2097. Assert.Fail ("#B2");
  2098. } catch (FileNotFoundException) {
  2099. }
  2100. aname = new AssemblyName ();
  2101. aname.Name = "bug79720B";
  2102. aname.Version = new Version (0, 0, 0, 0);
  2103. try {
  2104. AppDomain.CurrentDomain.Load (aname);
  2105. Assert.Fail ("#B3");
  2106. } catch (FileNotFoundException) {
  2107. }
  2108. aname = new AssemblyName ();
  2109. aname.Name = "bug79720B";
  2110. aname.Version = new Version (2, 4, 1);
  2111. try {
  2112. AppDomain.CurrentDomain.Load (aname);
  2113. Assert.Fail ("#B4");
  2114. } catch (FileNotFoundException) {
  2115. }
  2116. aname = new AssemblyName ();
  2117. aname.Name = "bug79720B";
  2118. aname.Version = new Version (2, 4, 1);
  2119. aname.CultureInfo = new CultureInfo ("nl-BE");
  2120. try {
  2121. AppDomain.CurrentDomain.Load (aname);
  2122. Assert.Fail ("#B5");
  2123. } catch (FileNotFoundException) {
  2124. }
  2125. Assert.AreEqual (assemblyStartCount + 1, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B6");
  2126. Assembly.LoadFrom (assemblyFile);
  2127. Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B7");
  2128. aname = new AssemblyName ();
  2129. aname.Name = "bug79720B";
  2130. try {
  2131. AppDomain.CurrentDomain.Load (aname);
  2132. Assert.Fail ("#B8");
  2133. } catch (FileNotFoundException) {
  2134. }
  2135. aname = new AssemblyName ();
  2136. aname.Name = "bug79720B";
  2137. aname.Version = new Version (0, 0, 0, 0);
  2138. try {
  2139. AppDomain.CurrentDomain.Load (aname);
  2140. Assert.Fail ("#B9");
  2141. } catch (FileNotFoundException) {
  2142. }
  2143. aname = new AssemblyName ();
  2144. aname.Name = "bug79720B";
  2145. aname.Version = new Version (2, 4, 1);
  2146. try {
  2147. AppDomain.CurrentDomain.Load (aname);
  2148. Assert.Fail ("#B10");
  2149. } catch (FileNotFoundException) {
  2150. }
  2151. aname = new AssemblyName ();
  2152. aname.Name = "bug79720B";
  2153. aname.Version = new Version (2, 4, 1);
  2154. aname.CultureInfo = new CultureInfo ("nl-BE");
  2155. try {
  2156. AppDomain.CurrentDomain.Load (aname);
  2157. Assert.Fail ("#B11");
  2158. } catch (FileNotFoundException) {
  2159. }
  2160. Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#B12");
  2161. // PART C
  2162. assemblyFile = Path.Combine (tempDir, "bug79720C.dll");
  2163. aname = new AssemblyName ();
  2164. aname.Name = "bug79720C";
  2165. aname.CultureInfo = new CultureInfo ("nl-BE");
  2166. aname.Version = new Version (2, 4);
  2167. aname.KeyPair = new StrongNameKeyPair (keyPair);
  2168. GenerateAssembly (aname, assemblyFile);
  2169. Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C1");
  2170. aname = new AssemblyName ();
  2171. aname.Name = "bug79720C";
  2172. try {
  2173. AppDomain.CurrentDomain.Load (aname);
  2174. Assert.Fail ("#C2");
  2175. } catch (FileNotFoundException) {
  2176. }
  2177. aname = new AssemblyName ();
  2178. aname.Name = "bug79720C";
  2179. aname.Version = new Version (0, 0, 0, 0);
  2180. try {
  2181. AppDomain.CurrentDomain.Load (aname);
  2182. Assert.Fail ("#C3");
  2183. } catch (FileNotFoundException) {
  2184. }
  2185. aname = new AssemblyName ();
  2186. aname.Name = "bug79720C";
  2187. aname.Version = new Version (2, 4, 1);
  2188. try {
  2189. AppDomain.CurrentDomain.Load (aname);
  2190. Assert.Fail ("#C4");
  2191. } catch (FileNotFoundException) {
  2192. }
  2193. aname = new AssemblyName ();
  2194. aname.Name = "bug79720C";
  2195. aname.Version = new Version (2, 4, 1);
  2196. aname.CultureInfo = new CultureInfo ("nl-BE");
  2197. try {
  2198. AppDomain.CurrentDomain.Load (aname);
  2199. Assert.Fail ("#C5");
  2200. } catch (FileNotFoundException) {
  2201. }
  2202. aname = new AssemblyName ();
  2203. aname.Name = "bug79720C";
  2204. aname.Version = new Version (2, 4, 1);
  2205. aname.CultureInfo = new CultureInfo ("nl-BE");
  2206. aname.SetPublicKey (publicKey);
  2207. try {
  2208. AppDomain.CurrentDomain.Load (aname);
  2209. Assert.Fail ("#C6");
  2210. } catch (FileNotFoundException) {
  2211. }
  2212. Assert.AreEqual (assemblyStartCount + 2, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C7");
  2213. Assembly.LoadFrom (assemblyFile);
  2214. Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C8");
  2215. aname = new AssemblyName ();
  2216. aname.Name = "bug79720C";
  2217. try {
  2218. AppDomain.CurrentDomain.Load (aname);
  2219. Assert.Fail ("#C9");
  2220. } catch (FileNotFoundException) {
  2221. }
  2222. aname = new AssemblyName ();
  2223. aname.Name = "bug79720C";
  2224. aname.Version = new Version (0, 0, 0, 0);
  2225. try {
  2226. AppDomain.CurrentDomain.Load (aname);
  2227. Assert.Fail ("#C10");
  2228. } catch (FileNotFoundException) {
  2229. }
  2230. aname = new AssemblyName ();
  2231. aname.Name = "bug79720C";
  2232. aname.Version = new Version (2, 4);
  2233. try {
  2234. AppDomain.CurrentDomain.Load (aname);
  2235. Assert.Fail ("#C11");
  2236. } catch (FileNotFoundException) {
  2237. }
  2238. aname = new AssemblyName ();
  2239. aname.Name = "bug79720C";
  2240. aname.Version = new Version (2, 4);
  2241. aname.CultureInfo = new CultureInfo ("nl-BE");
  2242. try {
  2243. AppDomain.CurrentDomain.Load (aname);
  2244. Assert.Fail ("#C12");
  2245. } catch (FileNotFoundException) {
  2246. }
  2247. aname = new AssemblyName ();
  2248. aname.Name = "bug79720C";
  2249. aname.Version = new Version (2, 4);
  2250. aname.CultureInfo = new CultureInfo ("nl-BE");
  2251. aname.SetPublicKey (publicKey);
  2252. try {
  2253. AppDomain.CurrentDomain.Load (aname);
  2254. Assert.Fail ("#C13");
  2255. } catch (FileNotFoundException) {
  2256. }
  2257. Assert.AreEqual (assemblyStartCount + 3, AppDomain.CurrentDomain.GetAssemblies ().Length, "#C14");
  2258. }
  2259. [Test]
  2260. [Category ("NotWorking")]
  2261. public void Load_Loaded_Multiple ()
  2262. {
  2263. string cultureDir = Path.Combine (tempDir, "nl-BE");
  2264. if (!Directory.Exists (cultureDir))
  2265. Directory.CreateDirectory (cultureDir);
  2266. AppDomain ad = CreateTestDomain (tempDir, true);
  2267. try {
  2268. CrossDomainTester cdt = CreateCrossDomainTester (ad);
  2269. int assemblyCount = cdt.AssemblyCount;
  2270. // PART A
  2271. AssemblyName aname = new AssemblyName ();
  2272. aname.Name = "multipleA";
  2273. aname.Version = new Version (1, 2, 3, 4);
  2274. cdt.GenerateAssembly (aname, Path.Combine (tempDir, "multipleA.dll"));
  2275. Assert.AreEqual (assemblyCount + 1, cdt.AssemblyCount, "#A1");
  2276. aname = new AssemblyName ();
  2277. aname.Name = "multipleA";
  2278. Assert.IsTrue (cdt.AssertLoad (aname), "#A2");
  2279. Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A3");
  2280. aname = new AssemblyName ();
  2281. aname.Name = "multipleA";
  2282. Assert.IsTrue (cdt.AssertLoad (aname), "#A4");
  2283. aname = new AssemblyName ();
  2284. aname.Name = "multipleA";
  2285. aname.CultureInfo = CultureInfo.InvariantCulture;
  2286. Assert.IsTrue (cdt.AssertLoad (aname), "#A5");
  2287. aname = new AssemblyName ();
  2288. aname.Name = "multipleA";
  2289. aname.CultureInfo = CultureInfo.InvariantCulture;
  2290. Assert.IsTrue (cdt.AssertLoad (aname), "#A6");
  2291. aname = new AssemblyName ();
  2292. aname.Name = "multipleA";
  2293. aname.CultureInfo = CultureInfo.InvariantCulture;
  2294. aname.Version = new Version (1, 2, 3, 4);
  2295. Assert.IsTrue (cdt.AssertLoad (aname), "#A7");
  2296. aname = new AssemblyName ();
  2297. aname.Name = "multipleA";
  2298. aname.CultureInfo = CultureInfo.InvariantCulture;
  2299. aname.Version = new Version (1, 2, 3, 4);
  2300. Assert.IsTrue (cdt.AssertLoad (aname), "#A8");
  2301. Assert.AreEqual (assemblyCount + 2, cdt.AssemblyCount, "#A9");
  2302. // PART B
  2303. aname = new AssemblyName ();
  2304. aname.Name = "multipleB";
  2305. aname.CultureInfo = new CultureInfo ("nl-BE");
  2306. aname.Version = new Version (2, 4, 1, 0);
  2307. cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleB.dll"));
  2308. Assert.AreEqual (assemblyCount + 3, cdt.AssemblyCount, "#B1");
  2309. aname = new AssemblyName ();
  2310. aname.Name = "multipleB";
  2311. Assert.IsTrue (cdt.AssertLoad (aname), "#B2");
  2312. Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B3");
  2313. aname = new AssemblyName ();
  2314. aname.Name = "multipleB";
  2315. Assert.IsTrue (cdt.AssertLoad (aname), "#B4");
  2316. aname = new AssemblyName ();
  2317. aname.Name = "multipleB";
  2318. aname.CultureInfo = new CultureInfo ("nl-BE");
  2319. Assert.IsTrue (cdt.AssertLoad (aname), "#B5");
  2320. aname = new AssemblyName ();
  2321. aname.Name = "multipleB";
  2322. aname.CultureInfo = new CultureInfo ("nl-BE");
  2323. Assert.IsTrue (cdt.AssertLoad (aname), "#B6");
  2324. aname = new AssemblyName ();
  2325. aname.Name = "multipleB";
  2326. aname.CultureInfo = new CultureInfo ("nl-BE");
  2327. aname.Version = new Version (2, 4, 1, 0);
  2328. Assert.IsTrue (cdt.AssertLoad (aname), "#B7");
  2329. aname = new AssemblyName ();
  2330. aname.Name = "multipleB";
  2331. aname.CultureInfo = new CultureInfo ("nl-BE");
  2332. aname.Version = new Version (2, 4, 1, 0);
  2333. Assert.IsTrue (cdt.AssertLoad (aname), "#B8");
  2334. Assert.AreEqual (assemblyCount + 4, cdt.AssemblyCount, "#B9");
  2335. // PART C
  2336. aname = new AssemblyName ();
  2337. aname.Name = "multipleC";
  2338. aname.CultureInfo = new CultureInfo ("nl-BE");
  2339. aname.Version = new Version (2, 4, 0, 0);
  2340. aname.KeyPair = new StrongNameKeyPair (keyPair);
  2341. cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/multipleC.dll"));
  2342. Assert.AreEqual (assemblyCount + 5, cdt.AssemblyCount, "#C1");
  2343. aname = new AssemblyName ();
  2344. aname.Name = "multipleC";
  2345. aname.CultureInfo = new CultureInfo ("nl-BE");
  2346. aname.Version = new Version (2, 4, 0, 0);
  2347. aname.SetPublicKey (publicKey);
  2348. Assert.IsTrue (cdt.AssertLoad (aname), "#C2");
  2349. Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C3");
  2350. aname = new AssemblyName ();
  2351. aname.Name = "multipleC";
  2352. aname.CultureInfo = new CultureInfo ("nl-BE");
  2353. aname.Version = new Version (2, 4, 0, 0);
  2354. aname.SetPublicKey (publicKey);
  2355. Assert.IsTrue (cdt.AssertLoad (aname), "#C4");
  2356. Assert.AreEqual (assemblyCount + 6, cdt.AssemblyCount, "#C5");
  2357. } finally {
  2358. AppDomain.Unload (ad);
  2359. }
  2360. }
  2361. [Test] // bug #79522
  2362. [Category ("NotWorking")]
  2363. public void Load_Manifest_Mismatch ()
  2364. {
  2365. string assemblyFile = Path.Combine (tempDir, "bug79522A.dll");
  2366. AssemblyName aname = new AssemblyName ();
  2367. aname.Name = "bug79522A";
  2368. aname.Version = new Version (2, 4);
  2369. GenerateAssembly (aname, assemblyFile);
  2370. aname = new AssemblyName ();
  2371. aname.CodeBase = assemblyFile;
  2372. aname.Name = "whateveryouwant";
  2373. aname.Version = new Version (1, 1);
  2374. // despite the fact that no assembly with the specified name
  2375. // exists, the assembly pointed to by the CodeBase of the
  2376. // AssemblyName will be loaded
  2377. //
  2378. // however the display name of the loaded assembly does not
  2379. // match the display name of the AssemblyName, and as a result
  2380. // a FileLoadException is thrown
  2381. try {
  2382. AppDomain.CurrentDomain.Load (aname);
  2383. Assert.Fail ("#A1");
  2384. } catch (FileLoadException) {
  2385. }
  2386. // if we set CodeBase to some garbage, then we'll get a
  2387. // FileNotFoundException instead
  2388. aname.CodeBase = "whatever";
  2389. try {
  2390. AppDomain.CurrentDomain.Load (aname);
  2391. Assert.Fail ("#A2");
  2392. } catch (FileNotFoundException) {
  2393. }
  2394. aname = new AssemblyName ();
  2395. aname.Name = "bug79522A";
  2396. aname.CodeBase = assemblyFile;
  2397. #if NET_2_0
  2398. AppDomain.CurrentDomain.Load (aname);
  2399. #else
  2400. try {
  2401. AppDomain.CurrentDomain.Load (aname);
  2402. Assert.Fail ("#A3");
  2403. } catch (FileLoadException) {
  2404. }
  2405. #endif
  2406. aname = new AssemblyName ();
  2407. aname.Name = "bug79522A";
  2408. aname.CodeBase = assemblyFile;
  2409. aname.Version = new Version (2, 5);
  2410. #if NET_2_0
  2411. // the version number is not considered when comparing the manifest
  2412. // of the assembly found using codebase
  2413. AppDomain.CurrentDomain.Load (aname);
  2414. #else
  2415. try {
  2416. AppDomain.CurrentDomain.Load (aname);
  2417. Assert.Fail ("#A4");
  2418. } catch (FileLoadException) {
  2419. }
  2420. #endif
  2421. aname = new AssemblyName ();
  2422. aname.Name = "bug79522A";
  2423. aname.CodeBase = assemblyFile;
  2424. aname.Version = new Version (2, 4, 1);
  2425. #if NET_2_0
  2426. // the version number is not considered when comparing the manifest
  2427. // of the assembly found using codebase
  2428. AppDomain.CurrentDomain.Load (aname);
  2429. #else
  2430. try {
  2431. AppDomain.CurrentDomain.Load (aname);
  2432. Assert.Fail ("#A5");
  2433. } catch (FileLoadException) {
  2434. }
  2435. #endif
  2436. // if version is set, then culture must also be set
  2437. aname = new AssemblyName ();
  2438. aname.Name = "bug79522A";
  2439. aname.CodeBase = assemblyFile;
  2440. aname.Version = new Version (2, 4);
  2441. #if NET_2_0
  2442. AppDomain.CurrentDomain.Load (aname);
  2443. #else
  2444. try {
  2445. AppDomain.CurrentDomain.Load (aname);
  2446. Assert.Fail ("#A6");
  2447. } catch (FileLoadException) {
  2448. }
  2449. #endif
  2450. // version number does not need to be set
  2451. aname = new AssemblyName ();
  2452. aname.Name = "bug79522A";
  2453. aname.CodeBase = assemblyFile;
  2454. aname.CultureInfo = CultureInfo.InvariantCulture;
  2455. AppDomain.CurrentDomain.Load (aname);
  2456. // if set, the version number must match exactly
  2457. aname = new AssemblyName ();
  2458. aname.Name = "bug79522A";
  2459. aname.CodeBase = assemblyFile;
  2460. aname.CultureInfo = CultureInfo.InvariantCulture;
  2461. aname.Version = new Version (2, 4);
  2462. AppDomain.CurrentDomain.Load (aname);
  2463. // if both culture and version are set, then the version diff
  2464. // is ignored
  2465. aname = new AssemblyName ();
  2466. aname.Name = "bug79522A";
  2467. aname.CodeBase = assemblyFile;
  2468. aname.CultureInfo = CultureInfo.InvariantCulture;
  2469. aname.Version = new Version (2, 5);
  2470. AppDomain.CurrentDomain.Load (aname);
  2471. // loaded assembly is not signed
  2472. aname = new AssemblyName ();
  2473. aname.Name = "bug79522A";
  2474. aname.CodeBase = assemblyFile;
  2475. aname.CultureInfo = CultureInfo.InvariantCulture;
  2476. aname.Version = new Version (2, 4);
  2477. aname.SetPublicKey (publicKey);
  2478. try {
  2479. AppDomain.CurrentDomain.Load (aname);
  2480. Assert.Fail ("#A7");
  2481. } catch (FileLoadException) {
  2482. }
  2483. // if set, the culture must match
  2484. aname = new AssemblyName ();
  2485. aname.Name = "bug79522A";
  2486. aname.CodeBase = assemblyFile;
  2487. aname.Version = new Version (2, 4);
  2488. aname.CultureInfo = new CultureInfo ("en-US");
  2489. try {
  2490. AppDomain.CurrentDomain.Load (aname);
  2491. Assert.Fail ("#A8");
  2492. } catch (FileLoadException) {
  2493. }
  2494. // PART B
  2495. assemblyFile = Path.Combine (tempDir, "bug79522B.dll");
  2496. aname = new AssemblyName ();
  2497. aname.Name = "bug79522B";
  2498. aname.CultureInfo = new CultureInfo ("nl-BE");
  2499. aname.Version = new Version (2, 4, 1);
  2500. GenerateAssembly (aname, assemblyFile);
  2501. aname = new AssemblyName ();
  2502. aname.CodeBase = assemblyFile;
  2503. aname.Name = "whateveryouwant";
  2504. aname.CultureInfo = new CultureInfo ("nl-BE");
  2505. aname.Version = new Version (1, 1);
  2506. // despite the fact that no assembly with the specified name
  2507. // exists, the assembly pointed to by the CodeBase of the
  2508. // AssemblyName will be loaded
  2509. //
  2510. // however the display name of the loaded assembly does not
  2511. // match the display name of the AssemblyName, and as a result
  2512. // a FileLoadException is thrown
  2513. try {
  2514. AppDomain.CurrentDomain.Load (aname);
  2515. Assert.Fail ("#B1");
  2516. } catch (FileLoadException) {
  2517. }
  2518. // if we set CodeBase to some garbage, then we'll get a
  2519. // FileNotFoundException instead
  2520. aname.CodeBase = "whatever";
  2521. try {
  2522. AppDomain.CurrentDomain.Load (aname);
  2523. Assert.Fail ("#B2");
  2524. } catch (FileNotFoundException) {
  2525. }
  2526. aname = new AssemblyName ();
  2527. aname.Name = "bug79522B";
  2528. aname.CodeBase = assemblyFile;
  2529. #if NET_2_0
  2530. // the version number is not considered when comparing the manifest
  2531. // of the assembly found using codebase
  2532. AppDomain.CurrentDomain.Load (aname);
  2533. #else
  2534. try {
  2535. AppDomain.CurrentDomain.Load (aname);
  2536. Assert.Fail ("#B3");
  2537. } catch (FileLoadException) {
  2538. }
  2539. #endif
  2540. aname = new AssemblyName ();
  2541. aname.Name = "bug79522B";
  2542. aname.CodeBase = assemblyFile;
  2543. aname.Version = new Version (5, 5);
  2544. #if NET_2_0
  2545. // the version number is not considered when comparing the manifest
  2546. // of the assembly found using codebase
  2547. AppDomain.CurrentDomain.Load (aname);
  2548. #else
  2549. try {
  2550. AppDomain.CurrentDomain.Load (aname);
  2551. Assert.Fail ("#B3");
  2552. } catch (FileLoadException) {
  2553. }
  2554. #endif
  2555. aname = new AssemblyName ();
  2556. aname.Name = "bug79522B";
  2557. aname.CodeBase = assemblyFile;
  2558. aname.Version = new Version (2, 4, 1);
  2559. #if NET_2_0
  2560. AppDomain.CurrentDomain.Load (aname);
  2561. #else
  2562. // when the loaded assembly has a specific culture, then that
  2563. // culture must be set if you set the Version on the aname
  2564. try {
  2565. AppDomain.CurrentDomain.Load (aname);
  2566. Assert.Fail ("#B4");
  2567. } catch (FileLoadException) {
  2568. }
  2569. #endif
  2570. // version does not need to be set
  2571. aname = new AssemblyName ();
  2572. aname.Name = "bug79522B";
  2573. aname.CodeBase = assemblyFile;
  2574. aname.CultureInfo = new CultureInfo ("nl-BE");
  2575. AppDomain.CurrentDomain.Load (aname);
  2576. // if both culture and version are set, then the version diff
  2577. // is ignored
  2578. aname = new AssemblyName ();
  2579. aname.Name = "bug79522B";
  2580. aname.CodeBase = assemblyFile;
  2581. aname.CultureInfo = new CultureInfo ("nl-BE");
  2582. aname.Version = new Version (6, 5);
  2583. AppDomain.CurrentDomain.Load (aname);
  2584. // loaded assembly is not signed
  2585. aname = new AssemblyName ();
  2586. aname.Name = "bug79522B";
  2587. aname.CodeBase = assemblyFile;
  2588. aname.CultureInfo = new CultureInfo ("nl-BE");
  2589. aname.SetPublicKey (publicKey);
  2590. try {
  2591. AppDomain.CurrentDomain.Load (aname);
  2592. Assert.Fail ("#B5");
  2593. } catch (FileLoadException) {
  2594. }
  2595. // if set, the culture must match
  2596. aname = new AssemblyName ();
  2597. aname.Name = "bug79522B";
  2598. aname.CodeBase = assemblyFile;
  2599. aname.Version = new Version (2, 4, 1);
  2600. aname.CultureInfo = new CultureInfo ("en-US");
  2601. try {
  2602. AppDomain.CurrentDomain.Load (aname);
  2603. Assert.Fail ("#B6");
  2604. } catch (FileLoadException) {
  2605. }
  2606. // PART C
  2607. assemblyFile = Path.Combine (tempDir, "bug79522C.dll");
  2608. aname = new AssemblyName ();
  2609. aname.Name = "bug79522C";
  2610. aname.CultureInfo = new CultureInfo ("nl-BE");
  2611. aname.Version = new Version (2, 4);
  2612. aname.KeyPair = new StrongNameKeyPair (keyPair);
  2613. GenerateAssembly (aname, assemblyFile);
  2614. aname = new AssemblyName ();
  2615. aname.CodeBase = assemblyFile;
  2616. aname.Name = "whateveryouwant";
  2617. aname.CultureInfo = new CultureInfo ("nl-BE");
  2618. aname.Version = new Version (1, 1);
  2619. aname.SetPublicKey (publicKey);
  2620. // despite the fact that no assembly with the specified name
  2621. // exists, the assembly pointed to by the CodeBase of the
  2622. // AssemblyName will be loaded
  2623. //
  2624. // however the display name of the loaded assembly does not
  2625. // match the display name of the AssemblyName, and as a result
  2626. // a FileLoadException is thrown
  2627. try {
  2628. AppDomain.CurrentDomain.Load (aname);
  2629. Assert.Fail ("#C1");
  2630. } catch (FileLoadException) {
  2631. }
  2632. // if we set CodeBase to some garbage, then we'll get a
  2633. // FileNotFoundException instead
  2634. aname.CodeBase = "whatever";
  2635. try {
  2636. AppDomain.CurrentDomain.Load (aname);
  2637. Assert.Fail ("#C2");
  2638. } catch (FileNotFoundException) {
  2639. }
  2640. aname = new AssemblyName ();
  2641. aname.Name = "bug79522C";
  2642. aname.CodeBase = assemblyFile;
  2643. #if NET_2_0
  2644. AppDomain.CurrentDomain.Load (aname);
  2645. #else
  2646. try {
  2647. AppDomain.CurrentDomain.Load (aname);
  2648. Assert.Fail ("#C3");
  2649. } catch (FileLoadException) {
  2650. }
  2651. #endif
  2652. aname = new AssemblyName ();
  2653. aname.Name = "bug79522C";
  2654. aname.CodeBase = assemblyFile;
  2655. aname.Version = new Version (5, 5);
  2656. try {
  2657. AppDomain.CurrentDomain.Load (aname);
  2658. Assert.Fail ("#C3");
  2659. } catch (FileLoadException) {
  2660. }
  2661. aname = new AssemblyName ();
  2662. aname.Name = "bug79522C";
  2663. aname.CodeBase = assemblyFile;
  2664. aname.Version = new Version (2, 4);
  2665. #if NET_2_0
  2666. AppDomain.CurrentDomain.Load (aname);
  2667. #else
  2668. // when the loaded assembly has a specific culture/publickey,
  2669. // then that culture/publickey must be set if you set the
  2670. // Version on the aname
  2671. try {
  2672. AppDomain.CurrentDomain.Load (aname);
  2673. Assert.Fail ("#C4");
  2674. } catch (FileLoadException) {
  2675. }
  2676. #endif
  2677. aname = new AssemblyName ();
  2678. aname.Name = "bug79522C";
  2679. aname.CodeBase = assemblyFile;
  2680. aname.CultureInfo = new CultureInfo ("nl-BE");
  2681. aname.Version = new Version (2, 4);
  2682. #if NET_2_0
  2683. AppDomain.CurrentDomain.Load (aname);
  2684. #else
  2685. // if loaded assembly is signed, then the public key must be set
  2686. try {
  2687. AppDomain.CurrentDomain.Load (aname);
  2688. Assert.Fail ("#C5");
  2689. } catch (FileLoadException) {
  2690. }
  2691. #endif
  2692. aname = new AssemblyName ();
  2693. aname.Name = "bug79522C";
  2694. aname.CodeBase = assemblyFile;
  2695. aname.CultureInfo = new CultureInfo ("nl-BE");
  2696. aname.SetPublicKey (publicKey);
  2697. #if NET_2_0
  2698. AppDomain.CurrentDomain.Load (aname);
  2699. #else
  2700. // if public key is set, then version must be set
  2701. try {
  2702. AppDomain.CurrentDomain.Load (aname);
  2703. Assert.Fail ("#C6");
  2704. } catch (FileLoadException) {
  2705. }
  2706. #endif
  2707. aname = new AssemblyName ();
  2708. aname.Name = "bug79522C";
  2709. aname.CodeBase = assemblyFile;
  2710. aname.CultureInfo = new CultureInfo ("nl-BE");
  2711. #if NET_2_0
  2712. AppDomain.CurrentDomain.Load (aname);
  2713. #else
  2714. try {
  2715. AppDomain.CurrentDomain.Load (aname);
  2716. Assert.Fail ("#C7");
  2717. } catch (FileLoadException) {
  2718. }
  2719. #endif
  2720. // if culture and version are set, then the version must match
  2721. aname = new AssemblyName ();
  2722. aname.Name = "bug79522C";
  2723. aname.CodeBase = assemblyFile;
  2724. aname.CultureInfo = new CultureInfo ("nl-BE");
  2725. aname.SetPublicKey (publicKey);
  2726. aname.Version = new Version (5, 6);
  2727. try {
  2728. AppDomain.CurrentDomain.Load (aname);
  2729. Assert.Fail ("#C8");
  2730. } catch (FileLoadException) {
  2731. }
  2732. // publickey must match
  2733. aname = new AssemblyName ();
  2734. aname.Name = "bug79522C";
  2735. aname.CodeBase = assemblyFile;
  2736. aname.CultureInfo = new CultureInfo ("nl-BE");
  2737. aname.Version = new Version (2, 4);
  2738. aname.SetPublicKey (publicKey2);
  2739. try {
  2740. AppDomain.CurrentDomain.Load (aname);
  2741. Assert.Fail ("#C9");
  2742. #if NET_2_0
  2743. } catch (SecurityException) {
  2744. // Invalid assembly public key
  2745. }
  2746. #else
  2747. } catch (FileLoadException) {
  2748. }
  2749. #endif
  2750. aname = new AssemblyName ();
  2751. aname.Name = "bug79522C";
  2752. aname.CodeBase = assemblyFile;
  2753. aname.SetPublicKey (publicKey);
  2754. aname.CultureInfo = new CultureInfo ("nl-BE");
  2755. aname.Version = new Version (2, 4);
  2756. AppDomain.CurrentDomain.Load (aname);
  2757. }
  2758. [Test] // bug #79715
  2759. public void Load_PartialVersion ()
  2760. {
  2761. AppDomain ad = CreateTestDomain (tempDir, true);
  2762. try {
  2763. CrossDomainTester cdt = CreateCrossDomainTester (ad);
  2764. AssemblyName aname = new AssemblyName ();
  2765. aname.Name = "bug79715";
  2766. aname.Version = new Version (1, 2, 3, 4);
  2767. cdt.GenerateAssembly (aname, Path.Combine (tempDir, "bug79715.dll"));
  2768. aname = new AssemblyName ();
  2769. aname.Name = "bug79715";
  2770. aname.Version = new Version (1, 2);
  2771. Assert.IsTrue (cdt.AssertLoad (aname), "#A1");
  2772. Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#A2");
  2773. aname = new AssemblyName ();
  2774. aname.Name = "bug79715";
  2775. aname.Version = new Version (1, 2, 3);
  2776. Assert.IsTrue (cdt.AssertLoad (aname), "#B1");
  2777. Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#B2");
  2778. aname = new AssemblyName ();
  2779. aname.Name = "bug79715";
  2780. aname.Version = new Version (1, 2, 3, 4);
  2781. Assert.IsTrue (cdt.AssertLoad (aname), "#C1");
  2782. Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#C2");
  2783. } finally {
  2784. AppDomain.Unload (ad);
  2785. }
  2786. }
  2787. [Test]
  2788. [ExpectedException (typeof (ArgumentException))]
  2789. public void Load_EmptyString ()
  2790. {
  2791. AppDomain.CurrentDomain.Load ("");
  2792. }
  2793. [Test]
  2794. public void SetAppDomainPolicy ()
  2795. {
  2796. ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
  2797. ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
  2798. // not much to see
  2799. }
  2800. [Test]
  2801. [ExpectedException (typeof (ArgumentNullException))]
  2802. public void SetAppDomainPolicy_Null ()
  2803. {
  2804. ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Null");
  2805. ad.SetAppDomainPolicy (null);
  2806. }
  2807. [Test]
  2808. [ExpectedException (typeof (PolicyException))]
  2809. public void SetAppDomainPolicy_Dual ()
  2810. {
  2811. ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Dual");
  2812. PolicyLevel pl = PolicyLevel.CreateAppDomainLevel ();
  2813. PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
  2814. pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
  2815. ad.SetAppDomainPolicy (pl);
  2816. // only one time!
  2817. pl = PolicyLevel.CreateAppDomainLevel ();
  2818. ps = new PermissionSet (PermissionState.None);
  2819. pl.RootCodeGroup.PolicyStatement = new PolicyStatement (ps);
  2820. ad.SetAppDomainPolicy (pl);
  2821. }
  2822. [Test]
  2823. [ExpectedException (typeof (AppDomainUnloadedException))]
  2824. public void SetAppDomainPolicy_Unloaded ()
  2825. {
  2826. ad = AppDomain.CreateDomain ("SetAppDomainPolicy_Unloaded");
  2827. AppDomain.Unload (ad);
  2828. ad.SetAppDomainPolicy (PolicyLevel.CreateAppDomainLevel ());
  2829. }
  2830. [Test]
  2831. [ExpectedException (typeof (ArgumentNullException))]
  2832. public void GetData_Null ()
  2833. {
  2834. AppDomain.CurrentDomain.GetData (null);
  2835. }
  2836. [Test]
  2837. public void SetData ()
  2838. {
  2839. AppDomain.CurrentDomain.SetData ("data", "data");
  2840. Assert.AreEqual ("data", AppDomain.CurrentDomain.GetData ("data"), "GetData");
  2841. AppDomain.CurrentDomain.SetData ("data", null);
  2842. Assert.IsNull (AppDomain.CurrentDomain.GetData ("data"), "GetData-Null");
  2843. }
  2844. [Test]
  2845. [ExpectedException (typeof (ArgumentNullException))]
  2846. public void SetData_Null ()
  2847. {
  2848. AppDomain.CurrentDomain.SetData (null, "data");
  2849. }
  2850. #if NET_2_0
  2851. [Test]
  2852. public void ApplyPolicy ()
  2853. {
  2854. ad = AppDomain.CreateDomain ("ApplyPolicy");
  2855. string fullname = Assembly.GetExecutingAssembly ().FullName;
  2856. string result = ad.ApplyPolicy (fullname);
  2857. Assert.AreEqual (fullname, result, "ApplyPolicy");
  2858. // doesn't even requires an assembly name
  2859. Assert.AreEqual ("123", ad.ApplyPolicy ("123"), "Invalid FullName");
  2860. }
  2861. [Test]
  2862. [ExpectedException (typeof (ArgumentException))]
  2863. public void ApplyPolicy_Empty ()
  2864. {
  2865. ad = AppDomain.CreateDomain ("ApplyPolicy_Empty");
  2866. ad.ApplyPolicy (String.Empty);
  2867. }
  2868. [Test]
  2869. [ExpectedException (typeof (ArgumentNullException))]
  2870. public void ApplyPolicy_Null ()
  2871. {
  2872. ad = AppDomain.CreateDomain ("ApplyPolicy_Null");
  2873. ad.ApplyPolicy (null);
  2874. }
  2875. [Test]
  2876. public void DomainManager ()
  2877. {
  2878. Assert.IsNull (AppDomain.CurrentDomain.DomainManager, "CurrentDomain.DomainManager");
  2879. ad = AppDomain.CreateDomain ("DomainManager");
  2880. Assert.IsNull (ad.DomainManager, "ad.DomainManager");
  2881. }
  2882. [Test]
  2883. public void IsDefaultAppDomain ()
  2884. {
  2885. ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
  2886. Assert.IsFalse (ad.IsDefaultAppDomain (), "IsDefaultAppDomain");
  2887. // we have no public way to get the default appdomain
  2888. }
  2889. [Test]
  2890. public void ReflectionOnlyGetAssemblies ()
  2891. {
  2892. ad = AppDomain.CreateDomain ("ReflectionOnlyGetAssemblies");
  2893. Assembly [] a = ad.ReflectionOnlyGetAssemblies ();
  2894. Assert.IsNotNull (a, "ReflectionOnlyGetAssemblies");
  2895. Assert.AreEqual (0, a.Length, "Count");
  2896. string assemblyFile = Path.Combine (tempDir, "bug499013.dll");
  2897. AssemblyName aname = new AssemblyName ();
  2898. aname.Name = "bug499013";
  2899. aname.Version = new Version (2, 4);
  2900. GenerateAssembly (aname, assemblyFile);
  2901. Assembly.ReflectionOnlyLoadFrom (assemblyFile);
  2902. foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies ())
  2903. Assert.IsTrue (assembly.GetName ().Name != "bug499013");
  2904. }
  2905. [Test]
  2906. public void ReflectionOnlyAssemblyResolve ()
  2907. {
  2908. AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
  2909. Assembly asm = Assembly.ReflectionOnlyLoad(Assembly.LoadWithPartialName("System").FullName);
  2910. asm.GetTypes();
  2911. }
  2912. [Test]
  2913. public void ResourceResolve ()
  2914. {
  2915. bool called = false;
  2916. ResolveEventHandler del = delegate (object sender, ResolveEventArgs args) {
  2917. called = true;
  2918. return null;
  2919. };
  2920. AppDomain.CurrentDomain.ResourceResolve += del;
  2921. Stream st = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("NOT_EXISTING");
  2922. Assert.IsTrue (called);
  2923. AppDomain.CurrentDomain.ResourceResolve -= del;
  2924. }
  2925. private static Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
  2926. {
  2927. return Assembly.ReflectionOnlyLoad(args.Name);
  2928. }
  2929. #endif
  2930. private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
  2931. {
  2932. AppDomainSetup setup = new AppDomainSetup ();
  2933. setup.ApplicationBase = baseDirectory;
  2934. setup.ApplicationName = "testdomain";
  2935. return CreateTestDomain (setup, assemblyResolver);
  2936. }
  2937. private static AppDomain CreateTestDomain (AppDomainSetup setup, bool assemblyResolver)
  2938. {
  2939. AppDomain ad = AppDomain.CreateDomain ("testdomain",
  2940. AppDomain.CurrentDomain.Evidence, setup);
  2941. if (assemblyResolver) {
  2942. Assembly ea = Assembly.GetExecutingAssembly ();
  2943. ad.CreateInstanceFrom (ea.CodeBase,
  2944. typeof (AssemblyResolveHandler).FullName,
  2945. false,
  2946. BindingFlags.Public | BindingFlags.Instance,
  2947. null,
  2948. new object [] { ea.Location, ea.FullName },
  2949. CultureInfo.InvariantCulture,
  2950. null,
  2951. null);
  2952. }
  2953. return ad;
  2954. }
  2955. private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
  2956. {
  2957. Type testerType = typeof (CrossDomainTester);
  2958. return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
  2959. testerType.Assembly.FullName, testerType.FullName, false,
  2960. BindingFlags.Public | BindingFlags.Instance, null, new object [0],
  2961. CultureInfo.InvariantCulture, new object [0], null);
  2962. }
  2963. private static void GenerateAssembly (AssemblyName aname, string path)
  2964. {
  2965. AppDomain ad = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory,
  2966. false);
  2967. try {
  2968. CrossDomainTester cdt = CreateCrossDomainTester (ad);
  2969. cdt.GenerateAssembly (aname, path);
  2970. } finally {
  2971. AppDomain.Unload (ad);
  2972. }
  2973. }
  2974. private bool RunningOnUnix {
  2975. get {
  2976. // check for Unix platforms - see FAQ for more details
  2977. // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
  2978. int platform = (int) Environment.OSVersion.Platform;
  2979. return ((platform == 4) || (platform == 128) || (platform == 6));
  2980. }
  2981. }
  2982. private class CrossDomainTester : MarshalByRefObject
  2983. {
  2984. public void GenerateAssembly (AssemblyName aname, string path)
  2985. {
  2986. AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
  2987. aname, AssemblyBuilderAccess.Save, Path.GetDirectoryName (path));
  2988. ab.Save (Path.GetFileName (path));
  2989. }
  2990. public int AssemblyCount {
  2991. get {
  2992. return AppDomain.CurrentDomain.GetAssemblies ().Length;
  2993. }
  2994. }
  2995. public string GetApplicationBase ()
  2996. {
  2997. return AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
  2998. }
  2999. public string GetConfigurationFile ()
  3000. {
  3001. return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
  3002. }
  3003. public void Load (AssemblyName assemblyRef)
  3004. {
  3005. AppDomain.CurrentDomain.Load (assemblyRef);
  3006. }
  3007. public void LoadFrom (string assemblyFile)
  3008. {
  3009. Assembly.LoadFrom (assemblyFile);
  3010. }
  3011. public bool AssertLoad (AssemblyName assemblyRef)
  3012. {
  3013. try {
  3014. AppDomain.CurrentDomain.Load (assemblyRef);
  3015. return true;
  3016. } catch {
  3017. return false;
  3018. }
  3019. }
  3020. public bool AssertLoad (string assemblyString)
  3021. {
  3022. try {
  3023. AppDomain.CurrentDomain.Load (assemblyString);
  3024. return true;
  3025. } catch {
  3026. return false;
  3027. }
  3028. }
  3029. public bool AssertFileLoadException (AssemblyName assemblyRef)
  3030. {
  3031. try {
  3032. AppDomain.CurrentDomain.Load (assemblyRef);
  3033. return false;
  3034. } catch (FileLoadException) {
  3035. return true;
  3036. }
  3037. }
  3038. public bool AssertFileNotFoundException (AssemblyName assemblyRef)
  3039. {
  3040. try {
  3041. AppDomain.CurrentDomain.Load (assemblyRef);
  3042. return false;
  3043. } catch (FileNotFoundException) {
  3044. return true;
  3045. }
  3046. }
  3047. }
  3048. [Serializable ()]
  3049. private class AssemblyResolveHandler
  3050. {
  3051. public AssemblyResolveHandler (string assemblyFile, string assemblyName)
  3052. {
  3053. _assemblyFile = assemblyFile;
  3054. _assemblyName = assemblyName;
  3055. AppDomain.CurrentDomain.AssemblyResolve +=
  3056. new ResolveEventHandler (ResolveAssembly);
  3057. }
  3058. private Assembly ResolveAssembly (object sender, ResolveEventArgs args)
  3059. {
  3060. if (args.Name == _assemblyName)
  3061. return Assembly.LoadFrom (_assemblyFile);
  3062. return null;
  3063. }
  3064. private readonly string _assemblyFile;
  3065. private readonly string _assemblyName;
  3066. }
  3067. static byte [] keyPair = {
  3068. 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
  3069. 0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3D, 0xBD,
  3070. 0x72, 0x08, 0xC6, 0x2B, 0x0E, 0xA8, 0xC1, 0xC0, 0x58, 0x07, 0x2B,
  3071. 0x63, 0x5F, 0x7C, 0x9A, 0xBD, 0xCB, 0x22, 0xDB, 0x20, 0xB2, 0xA9,
  3072. 0xDA, 0xDA, 0xEF, 0xE8, 0x00, 0x64, 0x2F, 0x5D, 0x8D, 0xEB, 0x78,
  3073. 0x02, 0xF7, 0xA5, 0x36, 0x77, 0x28, 0xD7, 0x55, 0x8D, 0x14, 0x68,
  3074. 0xDB, 0xEB, 0x24, 0x09, 0xD0, 0x2B, 0x13, 0x1B, 0x92, 0x6E, 0x2E,
  3075. 0x59, 0x54, 0x4A, 0xAC, 0x18, 0xCF, 0xC9, 0x09, 0x02, 0x3F, 0x4F,
  3076. 0xA8, 0x3E, 0x94, 0x00, 0x1F, 0xC2, 0xF1, 0x1A, 0x27, 0x47, 0x7D,
  3077. 0x10, 0x84, 0xF5, 0x14, 0xB8, 0x61, 0x62, 0x1A, 0x0C, 0x66, 0xAB,
  3078. 0xD2, 0x4C, 0x4B, 0x9F, 0xC9, 0x0F, 0x3C, 0xD8, 0x92, 0x0F, 0xF5,
  3079. 0xFF, 0xCE, 0xD7, 0x6E, 0x5C, 0x6F, 0xB1, 0xF5, 0x7D, 0xD3, 0x56,
  3080. 0xF9, 0x67, 0x27, 0xA4, 0xA5, 0x48, 0x5B, 0x07, 0x93, 0x44, 0x00,
  3081. 0x4A, 0xF8, 0xFF, 0xA4, 0xCB, 0x73, 0xC0, 0x6A, 0x62, 0xB4, 0xB7,
  3082. 0xC8, 0x92, 0x58, 0x87, 0xCD, 0x07, 0x0C, 0x7D, 0x6C, 0xC1, 0x4A,
  3083. 0xFC, 0x82, 0x57, 0x0E, 0x43, 0x85, 0x09, 0x75, 0x98, 0x51, 0xBB,
  3084. 0x35, 0xF5, 0x64, 0x83, 0xC7, 0x79, 0x89, 0x5C, 0x55, 0x36, 0x66,
  3085. 0xAB, 0x27, 0xA4, 0xD9, 0xD4, 0x7E, 0x6B, 0x67, 0x64, 0xC1, 0x54,
  3086. 0x4E, 0x37, 0xF1, 0x4E, 0xCA, 0xB3, 0xE5, 0x63, 0x91, 0x57, 0x12,
  3087. 0x14, 0xA6, 0xEA, 0x8F, 0x8F, 0x2B, 0xFE, 0xF3, 0xE9, 0x16, 0x08,
  3088. 0x2B, 0x86, 0xBC, 0x26, 0x0D, 0xD0, 0xC6, 0xC4, 0x1A, 0x72, 0x43,
  3089. 0x76, 0xDC, 0xFF, 0x28, 0x52, 0xA1, 0xDE, 0x8D, 0xFA, 0xD5, 0x1F,
  3090. 0x0B, 0xB5, 0x4F, 0xAF, 0x06, 0x79, 0x11, 0xEE, 0xA8, 0xEC, 0xD3,
  3091. 0x74, 0x55, 0xA2, 0x80, 0xFC, 0xF8, 0xD9, 0x50, 0x69, 0x48, 0x01,
  3092. 0xC2, 0x5A, 0x04, 0x56, 0xB4, 0x3E, 0x24, 0x32, 0x20, 0xB5, 0x2C,
  3093. 0xDE, 0xBB, 0xBD, 0x13, 0xFD, 0x13, 0xF7, 0x03, 0x3E, 0xE3, 0x37,
  3094. 0x84, 0x74, 0xE7, 0xD0, 0x5E, 0x9E, 0xB6, 0x26, 0xAE, 0x6E, 0xB0,
  3095. 0x55, 0x6A, 0x52, 0x63, 0x6F, 0x5A, 0x9D, 0xF2, 0x67, 0xD6, 0x61,
  3096. 0x4F, 0x7A, 0x45, 0xEE, 0x5C, 0x3D, 0x2B, 0x7C, 0xB2, 0x40, 0x79,
  3097. 0x54, 0x84, 0xD1, 0xBE, 0x61, 0x3E, 0x5E, 0xD6, 0x18, 0x8E, 0x14,
  3098. 0x98, 0xFC, 0x35, 0xBF, 0x5F, 0x1A, 0x20, 0x2E, 0x1A, 0xD8, 0xFF,
  3099. 0xC4, 0x6B, 0xC0, 0xC9, 0x7D, 0x06, 0xEF, 0x09, 0xF9, 0xF3, 0x69,
  3100. 0xFC, 0xBC, 0xA2, 0xE6, 0x80, 0x22, 0xB9, 0x79, 0x7E, 0xEF, 0x57,
  3101. 0x9F, 0x49, 0xE1, 0xBC, 0x0D, 0xB6, 0xA1, 0xFE, 0x8D, 0xBC, 0xBB,
  3102. 0xA3, 0x05, 0x02, 0x6B, 0x04, 0x45, 0xF7, 0x5D, 0xEE, 0x43, 0x06,
  3103. 0xD6, 0x9C, 0x94, 0x48, 0x1A, 0x0B, 0x9C, 0xBC, 0xB4, 0x4E, 0x93,
  3104. 0x60, 0x87, 0xCD, 0x58, 0xD6, 0x9A, 0x39, 0xA6, 0xC0, 0x7F, 0x8E,
  3105. 0xFF, 0x25, 0xC1, 0xD7, 0x2C, 0xF6, 0xF4, 0x6F, 0x24, 0x52, 0x0B,
  3106. 0x39, 0x42, 0x1B, 0x0D, 0x04, 0xC1, 0x93, 0x2A, 0x19, 0x1C, 0xF0,
  3107. 0xB1, 0x9B, 0xC1, 0x24, 0x6D, 0x1B, 0x0B, 0xDA, 0x1C, 0x8B, 0x72,
  3108. 0x48, 0xF0, 0x3E, 0x52, 0xBF, 0x0A, 0x84, 0x3A, 0x9B, 0xC8, 0x6D,
  3109. 0x13, 0x1E, 0x72, 0xF4, 0x46, 0x93, 0x88, 0x1A, 0x5F, 0x4C, 0x3C,
  3110. 0xE5, 0x9D, 0x6E, 0xBB, 0x4E, 0xDD, 0x5D, 0x1F, 0x11, 0x40, 0xF4,
  3111. 0xD7, 0xAF, 0xB3, 0xAB, 0x9A, 0x99, 0x15, 0xF0, 0xDC, 0xAA, 0xFF,
  3112. 0x9F, 0x2D, 0x9E, 0x56, 0x4F, 0x35, 0x5B, 0xBA, 0x06, 0x99, 0xEA,
  3113. 0xC6, 0xB4, 0x48, 0x51, 0x17, 0x1E, 0xD1, 0x95, 0x84, 0x81, 0x18,
  3114. 0xC0, 0xF1, 0x71, 0xDE, 0x44, 0x42, 0x02, 0x06, 0xAC, 0x0E, 0xA8,
  3115. 0xE2, 0xF3, 0x1F, 0x96, 0x1F, 0xBE, 0xB6, 0x1F, 0xB5, 0x3E, 0xF6,
  3116. 0x81, 0x05, 0x20, 0xFA, 0x2E, 0x40, 0x2E, 0x4D, 0xA0, 0x0E, 0xDA,
  3117. 0x42, 0x9C, 0x05, 0xAA, 0x9E, 0xAF, 0x5C, 0xF7, 0x3A, 0x3F, 0xBB,
  3118. 0x91, 0x73, 0x45, 0x27, 0xA8, 0xA2, 0x07, 0x4A, 0xEF, 0x59, 0x1E,
  3119. 0x97, 0x9D, 0xE0, 0x30, 0x5A, 0x83, 0xCE, 0x1E, 0x57, 0x32, 0x89,
  3120. 0x43, 0x41, 0x28, 0x7D, 0x14, 0x8D, 0x8B, 0x41, 0x1A, 0x56, 0x76,
  3121. 0x43, 0xDB, 0x64, 0x86, 0x41, 0x64, 0x8D, 0x4C, 0x91, 0x83, 0x4E,
  3122. 0xF5, 0x6C };
  3123. static byte [] publicKey2 = {
  3124. 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41,
  3125. 0x32, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x7F, 0x7C,
  3126. 0xEA, 0x4A, 0x28, 0x33, 0xD8, 0x3C, 0x86, 0x90, 0x86, 0x91, 0x11,
  3127. 0xBB, 0x30, 0x0D, 0x3D, 0x69, 0x04, 0x4C, 0x48, 0xF5, 0x4F, 0xE7,
  3128. 0x64, 0xA5, 0x82, 0x72, 0x5A, 0x92, 0xC4, 0x3D, 0xC5, 0x90, 0x93,
  3129. 0x41, 0xC9, 0x1D, 0x34, 0x16, 0x72, 0x2B, 0x85, 0xC1, 0xF3, 0x99,
  3130. 0x62, 0x07, 0x32, 0x98, 0xB7, 0xE4, 0xFA, 0x75, 0x81, 0x8D, 0x08,
  3131. 0xB9, 0xFD, 0xDB, 0x00, 0x25, 0x30, 0xC4, 0x89, 0x13, 0xB6, 0x43,
  3132. 0xE8, 0xCC, 0xBE, 0x03, 0x2E, 0x1A, 0x6A, 0x4D, 0x36, 0xB1, 0xEB,
  3133. 0x49, 0x26, 0x6C, 0xAB, 0xC4, 0x29, 0xD7, 0x8F, 0x25, 0x11, 0xA4,
  3134. 0x7C, 0x81, 0x61, 0x97, 0xCB, 0x44, 0x2D, 0x80, 0x49, 0x93, 0x48,
  3135. 0xA7, 0xC9, 0xAB, 0xDB, 0xCF, 0xA3, 0x34, 0xCB, 0x6B, 0x86, 0xE0,
  3136. 0x4D, 0x27, 0xFC, 0xA7, 0x4F, 0x36, 0xCA, 0x13, 0x42, 0xD3, 0x83,
  3137. 0xC4, 0x06, 0x6E, 0x12, 0xE0, 0xA1, 0x3D, 0x9F, 0xA9, 0xEC, 0xD1,
  3138. 0xC6, 0x08, 0x1B, 0x3D, 0xF5, 0xDB, 0x4C, 0xD4, 0xF0, 0x2C, 0xAA,
  3139. 0xFC, 0xBA, 0x18, 0x6F, 0x48, 0x7E, 0xB9, 0x47, 0x68, 0x2E, 0xF6,
  3140. 0x1E, 0x67, 0x1C, 0x7E, 0x0A, 0xCE, 0x10, 0x07, 0xC0, 0x0C, 0xAD,
  3141. 0x5E, 0xC1, 0x53, 0x70, 0xD5, 0xE7, 0x25, 0xCA, 0x37, 0x5E, 0x49,
  3142. 0x59, 0xD0, 0x67, 0x2A, 0xBE, 0x92, 0x36, 0x86, 0x8A, 0xBF, 0x3E,
  3143. 0x17, 0x04, 0xFB, 0x1F, 0x46, 0xC8, 0x10, 0x5C, 0x93, 0x02, 0x43,
  3144. 0x14, 0x96, 0x6A, 0xD9, 0x87, 0x17, 0x62, 0x7D, 0x3A, 0x45, 0xBE,
  3145. 0x35, 0xDE, 0x75, 0x0B, 0x2A, 0xCE, 0x7D, 0xF3, 0x19, 0x85, 0x4B,
  3146. 0x0D, 0x6F, 0x8D, 0x15, 0xA3, 0x60, 0x61, 0x28, 0x55, 0x46, 0xCE,
  3147. 0x78, 0x31, 0x04, 0x18, 0x3C, 0x56, 0x4A, 0x3F, 0xA4, 0xC9, 0xB1,
  3148. 0x41, 0xED, 0x22, 0x80, 0xA1, 0xB3, 0xE2, 0xC7, 0x1B, 0x62, 0x85,
  3149. 0xE4, 0x81, 0x39, 0xCB, 0x1F, 0x95, 0xCC, 0x61, 0x61, 0xDF, 0xDE,
  3150. 0xF3, 0x05, 0x68, 0xB9, 0x7D, 0x4F, 0xFF, 0xF3, 0xC0, 0x0A, 0x25,
  3151. 0x62, 0xD9, 0x8A, 0x8A, 0x9E, 0x99, 0x0B, 0xFB, 0x85, 0x27, 0x8D,
  3152. 0xF6, 0xD4, 0xE1, 0xB9, 0xDE, 0xB4, 0x16, 0xBD, 0xDF, 0x6A, 0x25,
  3153. 0x9C, 0xAC, 0xCD, 0x91, 0xF7, 0xCB, 0xC1, 0x81, 0x22, 0x0D, 0xF4,
  3154. 0x7E, 0xEC, 0x0C, 0x84, 0x13, 0x5A, 0x74, 0x59, 0x3F, 0x3E, 0x61,
  3155. 0x00, 0xD6, 0xB5, 0x4A, 0xA1, 0x04, 0xB5, 0xA7, 0x1C, 0x29, 0xD0,
  3156. 0xE1, 0x11, 0x19, 0xD7, 0x80, 0x5C, 0xEE, 0x08, 0x15, 0xEB, 0xC9,
  3157. 0xA8, 0x98, 0xF5, 0xA0, 0xF0, 0x92, 0x2A, 0xB0, 0xD3, 0xC7, 0x8C,
  3158. 0x8D, 0xBB, 0x88, 0x96, 0x4F, 0x18, 0xF0, 0x8A, 0xF9, 0x31, 0x9E,
  3159. 0x44, 0x94, 0x75, 0x6F, 0x78, 0x04, 0x10, 0xEC, 0xF3, 0xB0, 0xCE,
  3160. 0xA0, 0xBE, 0x7B, 0x25, 0xE1, 0xF7, 0x8A, 0xA8, 0xD4, 0x63, 0xC2,
  3161. 0x65, 0x47, 0xCC, 0x5C, 0xED, 0x7D, 0x8B, 0x07, 0x4D, 0x76, 0x29,
  3162. 0x53, 0xAC, 0x27, 0x8F, 0x5D, 0x78, 0x56, 0xFA, 0x99, 0x45, 0xA2,
  3163. 0xCC, 0x65, 0xC4, 0x54, 0x13, 0x9F, 0x38, 0x41, 0x7A, 0x61, 0x0E,
  3164. 0x0D, 0x34, 0xBC, 0x11, 0xAF, 0xE2, 0xF1, 0x8B, 0xFA, 0x2B, 0x54,
  3165. 0x6C, 0xA3, 0x6C, 0x09, 0x1F, 0x0B, 0x43, 0x9B, 0x07, 0x95, 0x83,
  3166. 0x3F, 0x97, 0x99, 0x89, 0xF5, 0x51, 0x41, 0xF6, 0x8E, 0x5D, 0xEF,
  3167. 0x6D, 0x24, 0x71, 0x41, 0x7A, 0xAF, 0xBE, 0x81, 0x71, 0xAB, 0x76,
  3168. 0x2F, 0x1A, 0x5A, 0xBA, 0xF3, 0xA6, 0x65, 0x7A, 0x80, 0x50, 0xCE,
  3169. 0x23, 0xC3, 0xC7, 0x53, 0xB0, 0x7C, 0x97, 0x77, 0x27, 0x70, 0x98,
  3170. 0xAE, 0xB5, 0x24, 0x66, 0xE1, 0x60, 0x39, 0x41, 0xDA, 0x54, 0x01,
  3171. 0x64, 0xFB, 0x10, 0x33, 0xCE, 0x8B, 0xBE, 0x27, 0xD4, 0x21, 0x57,
  3172. 0xCC, 0x0F, 0x1A, 0xC1, 0x3D, 0xF3, 0xCC, 0x39, 0xF0, 0x2F, 0xAE,
  3173. 0xF1, 0xC0, 0xCD, 0x3B, 0x23, 0x87, 0x49, 0x7E, 0x40, 0x32, 0x6A,
  3174. 0xD3, 0x96, 0x4A, 0xE5, 0x5E, 0x6E, 0x26, 0xFD, 0x8A, 0xCF, 0x7E,
  3175. 0xFC, 0x37, 0xDE, 0x39, 0x0C, 0x53, 0x81, 0x75, 0x08, 0xAF, 0x6B,
  3176. 0x39, 0x6C, 0xFB, 0xC9, 0x79, 0xC0, 0x9B, 0x5F, 0x34, 0x86, 0xB2,
  3177. 0xDE, 0xC4, 0x19, 0x84, 0x5F, 0x0E, 0xED, 0x9B, 0xB8, 0xD3, 0x17,
  3178. 0xDA, 0x78 };
  3179. static byte [] publicKey = {
  3180. 0x00, 0x24, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x94, 0x00, 0x00,
  3181. 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53,
  3182. 0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x3d,
  3183. 0xbd, 0x72, 0x08, 0xc6, 0x2b, 0x0e, 0xa8, 0xc1, 0xc0, 0x58, 0x07,
  3184. 0x2b, 0x63, 0x5f, 0x7c, 0x9a, 0xbd, 0xcb, 0x22, 0xdb, 0x20, 0xb2,
  3185. 0xa9, 0xda, 0xda, 0xef, 0xe8, 0x00, 0x64, 0x2f, 0x5d, 0x8d, 0xeb,
  3186. 0x78, 0x02, 0xf7, 0xa5, 0x36, 0x77, 0x28, 0xd7, 0x55, 0x8d, 0x14,
  3187. 0x68, 0xdb, 0xeb, 0x24, 0x09, 0xd0, 0x2b, 0x13, 0x1b, 0x92, 0x6e,
  3188. 0x2e, 0x59, 0x54, 0x4a, 0xac, 0x18, 0xcf, 0xc9, 0x09, 0x02, 0x3f,
  3189. 0x4f, 0xa8, 0x3e, 0x94, 0x00, 0x1f, 0xc2, 0xf1, 0x1a, 0x27, 0x47,
  3190. 0x7d, 0x10, 0x84, 0xf5, 0x14, 0xb8, 0x61, 0x62, 0x1a, 0x0c, 0x66,
  3191. 0xab, 0xd2, 0x4c, 0x4b, 0x9f, 0xc9, 0x0f, 0x3c, 0xd8, 0x92, 0x0f,
  3192. 0xf5, 0xff, 0xce, 0xd7, 0x6e, 0x5c, 0x6f, 0xb1, 0xf5, 0x7d, 0xd3,
  3193. 0x56, 0xf9, 0x67, 0x27, 0xa4, 0xa5, 0x48, 0x5b, 0x07, 0x93, 0x44,
  3194. 0x00, 0x4a, 0xf8, 0xff, 0xa4, 0xcb };
  3195. static byte [] pk_token = { 0xce, 0x52, 0x76, 0xd8, 0x68, 0x7e, 0Xc6, 0xdc };
  3196. }
  3197. }
  3198. #endif