2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / class / corlib / Test / System.Reflection / AssemblyTest.cs
1 //
2 // System.Reflection.Assembly Test Cases
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //      Philippe Lavoie (philippe.lavoie@cactus.ca)
7 //      Sebastien Pouliot (sebastien@ximian.com)
8 //
9 // (c) 2003 Ximian, Inc. (http://www.ximian.com)
10 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using NUnit.Framework;
33 using System;
34 using System.Configuration.Assemblies;
35 using System.Globalization;
36 using System.IO;
37 using System.Reflection;
38 #if !TARGET_JVM
39 using System.Reflection.Emit;
40 #endif
41 using System.Threading;
42 using System.Runtime.Serialization;
43 using System.Security;
44
45 namespace MonoTests.System.Reflection
46 {
47         [TestFixture]
48         public class AssemblyTest
49         {
50                 static string TempFolder = Path.Combine (Path.GetTempPath (),
51                         "MonoTests.System.Reflection.AssemblyTest");
52
53                 [SetUp]
54                 public void SetUp ()
55                 {
56                         while (Directory.Exists (TempFolder))
57                                 TempFolder = Path.Combine (TempFolder, "2");
58                         Directory.CreateDirectory (TempFolder);
59                 }
60
61                 [TearDown]
62                 public void TearDown ()
63                 {
64                         try {
65                                 // This throws an exception under MS.NET, since the directory contains loaded
66                                 // assemblies.
67                                 Directory.Delete (TempFolder, true);
68                         } catch (Exception) {
69                         }
70                 }
71
72                 [Test] 
73                 public void CreateInstance() 
74                 {
75                         Type type = typeof (AssemblyTest);
76                         Object obj = type.Assembly.CreateInstance ("MonoTests.System.Reflection.AssemblyTest");
77                         Assert.IsNotNull (obj, "#01");
78                         Assert.AreEqual (GetType (), obj.GetType (), "#02");
79                 }
80
81                 [Test] 
82                 public void CreateInvalidInstance() 
83                 {
84                         Type type = typeof (AssemblyTest);
85                         Object obj = type.Assembly.CreateInstance("NunitTests.ThisTypeDoesNotExist");
86                         Assert.IsNull (obj, "#03");
87                 }
88
89                 [Test] // bug #49114
90 #if NET_2_0
91                 [Category ("NotWorking")]
92                 [ExpectedException (typeof (ArgumentException))]
93 #else
94                 [ExpectedException (typeof (TypeLoadException))]
95 #endif
96                 public void GetType_TypeName_Invalid () 
97                 {
98                         typeof (int).Assembly.GetType ("&blabla", true, true);
99                 }
100
101                 [Test] // bug #334203
102                 public void GetType_TypeName_AssemblyName ()
103                 {
104                         Assembly a = typeof (int).Assembly;
105                         string typeName = typeof (string).AssemblyQualifiedName;
106 #if NET_2_0
107                         try {
108                                 a.GetType (typeName, true, false);
109                                 Assert.Fail ("#A1");
110                         } catch (ArgumentException ex) {
111                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
112                                 Assert.IsNull (ex.InnerException, "#A3");
113                                 Assert.IsNotNull (ex.Message, "#A4");
114                                 Assert.IsNull (ex.ParamName, "#A5");
115                         }
116 #else
117                         try {
118                                 a.GetType (typeName, true, false);
119                                 Assert.Fail ("#A1");
120                         } catch (TypeLoadException ex) {
121                                 Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A2");
122                                 Assert.IsNull (ex.InnerException, "#A3");
123                                 Assert.IsNotNull (ex.Message, "#A4");
124                                 Assert.IsTrue (ex.Message.IndexOf (typeName) != -1, "#A5");
125                         }
126 #endif
127
128                         Type type = a.GetType (typeName, false);
129                         Assert.IsNull (type, "#B1");
130                         type = a.GetType (typeName, false, true);
131                         Assert.IsNull (type, "#B2");
132                 }
133
134                 [Test]
135                 public void GetEntryAssembly ()
136                 {
137                         // note: only available in default appdomain
138                         // http://weblogs.asp.net/asanto/archive/2003/09/08/26710.aspx
139                         // Not sure we should emulate this behavior.
140                         string fname = AppDomain.CurrentDomain.FriendlyName;
141                         if (fname.EndsWith (".dll")) { // nunit-console
142                                 Assert.IsNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
143 #if NET_2_0 && !TARGET_JVM // IsDefaultAppDomain not supported for TARGET_JVM
144                                 Assert.IsFalse (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
145 #endif
146                         } else { // gnunit
147                                 Assert.IsNotNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
148 #if NET_2_0 && !TARGET_JVM // IsDefaultAppDomain not supported for TARGET_JVM
149                                 Assert.IsTrue (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
150 #endif
151                         }
152                 }
153
154 #if !TARGET_JVM // Reflection.Emit is not supported.
155                 [Test]
156                 public void GetModules_MissingFile ()
157                 {
158                         AssemblyName newName = new AssemblyName ();
159                         newName.Name = "AssemblyTest";
160
161                         AssemblyBuilder ab = Thread.GetDomain().DefineDynamicAssembly (newName, AssemblyBuilderAccess.RunAndSave, TempFolder);
162
163                         ModuleBuilder mb = ab.DefineDynamicModule ("myDynamicModule1", "myDynamicModule.dll", true);
164
165                         ab.Save ("test_assembly.dll");
166
167                         File.Delete (Path.Combine (TempFolder, "myDynamicModule.dll"));
168
169                         Assembly ass = Assembly.LoadFrom (Path.Combine (TempFolder, "test_assembly.dll"));
170                         try {
171                                 ass.GetModules ();
172                                 Assert.Fail ();
173                         } catch (FileNotFoundException ex) {
174                                 Assert.AreEqual ("myDynamicModule.dll", ex.FileName);
175                         }
176                 }
177 #endif
178
179 #if !TARGET_JVM // ManifestModule not supported under TARGET_JVM.
180 #if NET_2_0
181                 [Category ("NotWorking")]
182 #endif
183                 [Test]
184                 public void Corlib () 
185                 {
186                         Assembly corlib = typeof (int).Assembly;
187                         Assert.IsTrue (corlib.CodeBase.EndsWith ("mscorlib.dll"), "CodeBase");
188                         Assert.IsNull (corlib.EntryPoint, "EntryPoint");
189                         Assert.IsTrue (corlib.EscapedCodeBase.EndsWith ("mscorlib.dll"), "EscapedCodeBase");
190                         Assert.IsNotNull (corlib.Evidence, "Evidence");
191                         Assert.IsTrue (corlib.Location.EndsWith ("mscorlib.dll"), "Location");
192
193                         // corlib doesn't reference anything
194                         Assert.AreEqual (0, corlib.GetReferencedAssemblies ().Length, "GetReferencedAssemblies");
195 #if NET_2_0
196                         Assert.AreEqual ("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", corlib.FullName, "FullName");
197                         // not really "true" but it's even more trusted so...
198                         Assert.IsTrue (corlib.GlobalAssemblyCache, "GlobalAssemblyCache");
199                         Assert.AreEqual (0, corlib.HostContext, "HostContext");
200                         Assert.AreEqual ("v2.0.50727", corlib.ImageRuntimeVersion, "ImageRuntimeVersion");
201                         Assert.IsFalse (corlib.ReflectionOnly, "ReflectionOnly");
202                         Assert.AreEqual (0x1, corlib.ManifestModule.MetadataToken);
203 #elif NET_1_1
204                         Assert.IsFalse (corlib.GlobalAssemblyCache, "GlobalAssemblyCache");
205                         Assert.AreEqual ("mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", corlib.FullName, "FullName");
206                         Assert.AreEqual ("v1.1.4322", corlib.ImageRuntimeVersion, "ImageRuntimeVersion");
207 #endif
208                 }
209
210                 [Test]
211                 public void Corlib_test ()
212                 {
213                         Assembly corlib_test = Assembly.GetExecutingAssembly ();
214                         Assert.IsNull (corlib_test.EntryPoint, "EntryPoint");
215                         Assert.IsNotNull (corlib_test.Evidence, "Evidence");
216                         Assert.IsFalse (corlib_test.GlobalAssemblyCache, "GlobalAssemblyCache");
217
218                         Assert.IsTrue (corlib_test.GetReferencedAssemblies ().Length > 0, "GetReferencedAssemblies");
219 #if NET_2_0
220                         Assert.AreEqual (0, corlib_test.HostContext, "HostContext");
221                         Assert.AreEqual ("v2.0.50727", corlib_test.ImageRuntimeVersion, "ImageRuntimeVersion");
222                         Assert.IsNotNull (corlib_test.ManifestModule, "ManifestModule");
223                         Assert.IsFalse (corlib_test.ReflectionOnly, "ReflectionOnly");
224 #elif NET_1_1
225                         Assert.AreEqual ("v1.1.4322", corlib_test.ImageRuntimeVersion, "ImageRuntimeVersion");
226 #endif
227                 }
228 #endif
229
230                 [Test]
231                 public void GetAssembly ()
232                 {
233                         Assert.IsTrue (Assembly.GetAssembly (typeof (int)).FullName.StartsWith ("mscorlib"), "GetAssembly(int)");
234                         Assert.AreEqual (this.GetType ().Assembly.FullName, Assembly.GetAssembly (this.GetType ()).FullName, "GetAssembly(this)");
235                 }
236
237                 [Test]
238                 [Category("TargetJvmNotWorking")] // Not yet supported for TARGET_JVM
239                 public void GetFile_Null ()
240                 {
241                         try {
242                                 Assembly.GetExecutingAssembly ().GetFile (null);
243                                 Assert.Fail ("#1");
244                         } catch (ArgumentNullException ex) {
245                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
246                                 Assert.IsNull (ex.InnerException, "#3");
247                                 Assert.IsNotNull (ex.Message, "#4");
248                                 Assert.IsNull (ex.ParamName, "#5");
249                         }
250                 }
251
252                 [Test]
253                 [Category("TargetJvmNotWorking")] // Not yet supported for TARGET_JVM
254                 public void GetFile_Empty ()
255                 {
256                         try {
257                                 Assembly.GetExecutingAssembly ().GetFile (
258                                         String.Empty);
259                                 Assert.Fail ("#1");
260                         } catch (ArgumentException ex) {
261                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
262                                 Assert.IsNull (ex.InnerException, "#3");
263                                 Assert.IsNotNull (ex.Message, "#4");
264                                 Assert.IsNull (ex.ParamName, "#5");
265                         }
266                 }
267
268                 [Test]
269                 [Category("TargetJvmNotWorking")] // Not yet supported for TARGET_JVM
270                 public void GetFiles_False ()
271                 {
272                         Assembly corlib = typeof (int).Assembly;
273                         FileStream[] fss = corlib.GetFiles ();
274                         Assert.AreEqual (fss.Length, corlib.GetFiles (false).Length, "corlib.GetFiles (false)");
275
276                         Assembly corlib_test = Assembly.GetExecutingAssembly ();
277                         fss = corlib_test.GetFiles ();
278                         Assert.AreEqual (fss.Length, corlib_test.GetFiles (false).Length, "test.GetFiles (false)");
279                 }
280
281                 [Test]
282                 [Category("TargetJvmNotWorking")] // Not yet supported for TARGET_JVM
283                 public void GetFiles_True ()
284                 {
285                         Assembly corlib = typeof (int).Assembly;
286                         FileStream[] fss = corlib.GetFiles ();
287                         Assert.IsTrue (fss.Length <= corlib.GetFiles (true).Length, "corlib.GetFiles (true)");
288
289                         Assembly corlib_test = Assembly.GetExecutingAssembly ();
290                         fss = corlib_test.GetFiles ();
291                         Assert.IsTrue (fss.Length <= corlib_test.GetFiles (true).Length, "test.GetFiles (true)");
292                 }
293
294                 [Test]
295                 public void GetManifestResourceStream_Name_Empty ()
296                 {
297                         Assembly corlib = typeof (int).Assembly;
298
299                         try {
300                                 corlib.GetManifestResourceStream (string.Empty);
301                                 Assert.Fail ("#A1");
302                         } catch (ArgumentException ex) {
303                                 // String cannot have zero length
304                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
305                                 Assert.IsNull (ex.InnerException, "#A3");
306                                 Assert.IsNotNull (ex.Message, "#A4");
307                         }
308
309                         corlib.GetManifestResourceStream (typeof (int), string.Empty);
310
311                         try {
312                                 corlib.GetManifestResourceStream ((Type) null, string.Empty);
313                                 Assert.Fail ("#B1");
314                         } catch (ArgumentException ex) {
315                                 // String cannot have zero length
316                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
317                                 Assert.IsNull (ex.InnerException, "#B3");
318                                 Assert.IsNotNull (ex.Message, "#B4");
319                         }
320                 }
321
322                 [Test]
323                 public void GetManifestResourceStream_Name_Null ()
324                 {
325                         Assembly corlib = typeof (int).Assembly;
326
327                         try {
328                                 corlib.GetManifestResourceStream ((string) null);
329                                 Assert.Fail ("#A1");
330                         } catch (ArgumentNullException ex) {
331                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
332                                 Assert.IsNull (ex.InnerException, "#A3");
333                                 Assert.IsNotNull (ex.Message, "#A4");
334                         }
335
336                         corlib.GetManifestResourceStream (typeof (int), (string) null);
337
338                         try {
339                                 corlib.GetManifestResourceStream ((Type) null, (string) null);
340                                 Assert.Fail ("#B1");
341                         } catch (ArgumentNullException ex) {
342                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
343                                 Assert.IsNull (ex.InnerException, "#B3");
344                                 Assert.IsNotNull (ex.Message, "#B4");
345                                 Assert.IsNotNull (ex.ParamName, "#B5");
346                                 Assert.AreEqual ("type", ex.ParamName, "#B6");
347                         }
348                 }
349
350                 [Test]
351                 public void IsDefined_AttributeType_Null ()
352                 {
353                         Assembly corlib = typeof (int).Assembly;
354
355                         try {
356                                 corlib.IsDefined ((Type) null, false);
357                                 Assert.Fail ("#1");
358                         } catch (ArgumentNullException ex) {
359                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
360                                 Assert.IsNull (ex.InnerException, "#3");
361                                 Assert.IsNotNull (ex.Message, "#4");
362                                 Assert.IsNotNull (ex.ParamName, "#5");
363                                 Assert.AreEqual ("attributeType", ex.ParamName, "#6");
364                         }
365                 }
366
367                 [Test] // bug #78517
368 #if ONLY_1_1
369                 [Category ("NotDotNet")] // MS.NET 1.x throws FileLoadException
370 #endif
371                 public void LoadFrom_Empty_Assembly ()
372                 {
373                         string tempFile = Path.GetTempFileName ();
374
375                         try {
376                                 Assembly.LoadFrom (tempFile);
377                                 Assert.Fail ("#1");
378                         } catch (BadImageFormatException ex) {
379                                 Assert.IsNull (ex.InnerException, "#2");
380                         } finally {
381                                 File.Delete (tempFile);
382                         }
383                 }
384
385                 [Test] // bug #78517
386                 public void LoadFrom_Invalid_Assembly ()
387                 {
388                         string tempFile = Path.GetTempFileName ();
389                         using (StreamWriter sw = File.CreateText (tempFile)) {
390                                 sw.WriteLine ("foo");
391                                 sw.Close ();
392                         }
393
394                         try {
395                                 Assembly.LoadFrom (tempFile);
396                                 Assert.Fail ("#1");
397                         } catch (BadImageFormatException ex) {
398                                 Assert.IsNull (ex.InnerException, "#2");
399                         } finally {
400                                 File.Delete (tempFile);
401                         }
402                 }
403
404                 [Test]
405                 public void LoadFrom_NonExisting_Assembly ()
406                 {
407                         string tempFile = Path.GetTempFileName ();
408                         File.Delete (tempFile);
409
410                         try {
411                                 Assembly.LoadFrom (tempFile);
412                                 Assert.Fail ("#1");
413                         } catch (FileNotFoundException ex) {
414                                 Assert.IsNull (ex.InnerException, "#2");
415                         } finally {
416                                 File.Delete (tempFile);
417                         }
418                 }
419
420                 [Test]
421                 public void LoadWithPartialName ()
422                 {
423                         string [] names = { "corlib_test_net_1_1", "corlib_test_net_2_0", "corlib_plattest" };
424
425                         foreach (string s in names)
426                                 if (Assembly.LoadWithPartialName (s) != null)
427                                         return;
428                         Assertion.Fail ("Was not able to load any corlib test");
429                 }
430
431 #if !TARGET_JVM // GetObjectData currently not implemented for Assembly.
432                 [Test]
433                 public void GetObjectData_Info_Null ()
434                 {
435                         Assembly corlib = typeof (int).Assembly;
436                         try {
437                                 corlib.GetObjectData (null, new StreamingContext (
438                                         StreamingContextStates.All));
439                                 Assert.Fail ("#1");
440                         } catch (ArgumentNullException ex) {
441                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
442                                 Assert.IsNull (ex.InnerException, "#3");
443                                 Assert.IsNotNull (ex.Message, "#4");
444                                 Assert.IsNotNull (ex.ParamName, "#5");
445                                 Assert.AreEqual ("info", ex.ParamName, "#6");
446                         }
447                 }
448 #endif // TARGET_JVM
449
450                 [Test]
451                 public void GetReferencedAssemblies ()
452                 {
453                         Assembly corlib_test = Assembly.GetExecutingAssembly ();
454                         AssemblyName[] names = corlib_test.GetReferencedAssemblies ();
455                         foreach (AssemblyName an in names) {
456                                 Assert.IsNull (an.CodeBase, "CodeBase");
457                                 Assert.IsNotNull (an.CultureInfo, "CultureInfo");
458                                 Assert.IsNull (an.EscapedCodeBase, "EscapedCodeBase");
459                                 Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "Flags");
460                                 Assert.IsNotNull (an.FullName, "FullName");
461                                 Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "HashAlgorithm");
462                                 Assert.IsNull (an.KeyPair, "KeyPair");
463                                 Assert.IsNotNull (an.Name, "Name");
464                                 Assert.IsNotNull (an.Version, "Version");
465                                 Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
466                                         an.VersionCompatibility, "VersionCompatibility");
467                         }
468                 }
469
470 #if !TARGET_JVM // Reflection.Emit is not supported.
471                 [Test]
472                 public void Location_Empty() {
473                         string assemblyFileName = Path.Combine (
474                                 Path.GetTempPath (), "AssemblyLocation.dll");
475
476                         try {
477                                 AssemblyName assemblyName = new AssemblyName ();
478                                 assemblyName.Name = "AssemblyLocation";
479
480                                 AssemblyBuilder ab = AppDomain.CurrentDomain
481                                         .DefineDynamicAssembly (assemblyName,
482                                         AssemblyBuilderAccess.Save,
483                                         Path.GetTempPath (),
484                                         AppDomain.CurrentDomain.Evidence);
485                                 ab.Save (Path.GetFileName (assemblyFileName));
486
487                                 using (FileStream fs = File.OpenRead (assemblyFileName)) {
488                                         byte[] buffer = new byte[fs.Length];
489                                         fs.Read (buffer, 0, buffer.Length);
490                                         Assembly assembly = Assembly.Load (buffer);
491                                         Assert.AreEqual (string.Empty, assembly.Location);
492                                         fs.Close ();
493                                 }
494                         } finally {
495                                 File.Delete (assemblyFileName);
496                         }
497                 }
498
499                 [Test]
500                 [Category ("NotWorking")]
501                 public void bug78464 ()
502                 {
503                         string assemblyFileName = Path.Combine (
504                                 Path.GetTempPath (), "bug78464.dll");
505
506                         try {
507                                 // execute test in separate appdomain to allow assembly to be unloaded
508                                 AppDomain testDomain = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory, false);
509                                 CrossDomainTester crossDomainTester = CreateCrossDomainTester (testDomain);
510                                 try {
511                                         crossDomainTester.bug78464 (assemblyFileName);
512                                 } finally {
513                                         AppDomain.Unload (testDomain);
514                                 }
515                         } finally {
516                                 File.Delete (assemblyFileName);
517                         }
518                 }
519
520                 [Test]
521                 public void bug78465 ()
522                 {
523                         string assemblyFileName = Path.Combine (
524                                 Path.GetTempPath (), "bug78465.dll");
525
526                         try {
527                                 AssemblyName assemblyName = new AssemblyName ();
528                                 assemblyName.Name = "bug78465";
529
530                                 AssemblyBuilder ab = AppDomain.CurrentDomain
531                                         .DefineDynamicAssembly (assemblyName,
532                                         AssemblyBuilderAccess.Save,
533                                         Path.GetDirectoryName (assemblyFileName),
534                                         AppDomain.CurrentDomain.Evidence);
535                                 ab.Save (Path.GetFileName (assemblyFileName));
536
537                                 using (FileStream fs = File.OpenRead (assemblyFileName)) {
538                                         byte[] buffer = new byte[fs.Length];
539                                         fs.Read (buffer, 0, buffer.Length);
540                                         Assembly assembly = Assembly.Load (buffer);
541                                         Assert.AreEqual (string.Empty, assembly.Location, "#1");
542                                         fs.Close ();
543                                 }
544
545                                 AppDomain testDomain = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory, false);
546                                 CrossDomainTester crossDomainTester = CreateCrossDomainTester (testDomain);
547                                 try {
548                                         crossDomainTester.bug78465 (assemblyFileName);
549                                 } finally {
550                                         AppDomain.Unload (testDomain);
551                                 }
552                         } finally {
553                                 File.Delete (assemblyFileName);
554                         }
555                 }
556
557                 [Test]
558                 public void bug78468 ()
559                 {
560                         string assemblyFileNameA = Path.Combine (Path.GetTempPath (),
561                                 "bug78468a.dll");
562                         string resourceFileName = Path.Combine (Path.GetTempPath (),
563                                 "readme.txt");
564
565                         using (StreamWriter sw = File.CreateText (resourceFileName)) {
566                                 sw.WriteLine ("FOO");
567                                 sw.Close ();
568                         }
569
570                         try {
571                                 AssemblyName assemblyName = new AssemblyName ();
572                                 assemblyName.Name = "bug78468a";
573
574                                 AssemblyBuilder ab = AppDomain.CurrentDomain
575                                         .DefineDynamicAssembly (assemblyName,
576                                         AssemblyBuilderAccess.Save,
577                                         Path.GetTempPath (),
578                                         AppDomain.CurrentDomain.Evidence);
579                                 ab.AddResourceFile ("read", "readme.txt");
580                                 ab.Save (Path.GetFileName (assemblyFileNameA));
581
582                                 Assembly assembly;
583
584                                 using (FileStream fs = File.OpenRead (assemblyFileNameA)) {
585                                         byte[] buffer = new byte[fs.Length];
586                                         fs.Read (buffer, 0, buffer.Length);
587                                         assembly = Assembly.Load (buffer);
588                                         fs.Close ();
589                                 }
590
591                                 Assert.AreEqual (string.Empty, assembly.Location, "#A1");
592                                 string[] resNames = assembly.GetManifestResourceNames ();
593                                 Assert.IsNotNull (resNames, "#A2");
594                                 Assert.AreEqual (1, resNames.Length, "#A3");
595                                 Assert.AreEqual ("read", resNames[0], "#A4");
596                                 ManifestResourceInfo resInfo = assembly.GetManifestResourceInfo ("read");
597                                 Assert.IsNotNull (resInfo, "#A5");
598                                 Assert.AreEqual ("readme.txt", resInfo.FileName, "#A6");
599                                 Assert.IsNull (resInfo.ReferencedAssembly, "#A7");
600                                 Assert.AreEqual ((ResourceLocation) 0, resInfo.ResourceLocation, "#A8");
601 #if NET_2_0
602                                 try {
603                                         assembly.GetManifestResourceStream ("read");
604                                         Assert.Fail ("#A9");
605                                 } catch (FileNotFoundException) {
606                                 }
607 #else
608                                 Assert.IsNull (assembly.GetManifestResourceStream ("read"), "#A9");
609 #endif
610                                 try {
611                                         assembly.GetFile ("readme.txt");
612                                         Assert.Fail ("#A10");
613                                 } catch (FileNotFoundException) {
614                                 }
615
616                                 string assemblyFileNameB = Path.Combine (Path.GetTempPath (),
617                                         "bug78468b.dll");
618
619                                 AppDomain testDomain = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory, false);
620                                 CrossDomainTester crossDomainTester = CreateCrossDomainTester (testDomain);
621                                 try {
622                                         crossDomainTester.bug78468 (assemblyFileNameB);
623                                 } finally {
624                                         AppDomain.Unload (testDomain);
625                                         File.Delete (assemblyFileNameB);
626                                 }
627                         } finally {
628                                 File.Delete (assemblyFileNameA);
629                                 File.Delete (resourceFileName);
630                         }
631                 }
632
633 #if NET_2_0
634                 [Test]
635                 [Category ("NotWorking")]
636                 public void ReflectionOnlyLoad ()
637                 {
638                         Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (AssemblyTest).Assembly.FullName);
639                         
640                         Assert.IsNotNull (assembly);
641                         Assert.IsTrue (assembly.ReflectionOnly);
642                 }
643
644                 [Test]
645                 public void ReflectionOnlyLoadFrom ()
646                 {
647                         string loc = typeof (AssemblyTest).Assembly.Location;
648                         string filename = Path.GetFileName (loc);
649                         Assembly assembly = Assembly.ReflectionOnlyLoadFrom (filename);
650
651                         Assert.IsNotNull (assembly);
652                         Assert.IsTrue (assembly.ReflectionOnly);
653                 }
654
655                 [Test]
656                 [ExpectedException (typeof (ArgumentException))]
657                 public void CreateInstanceOnRefOnly ()
658                 {
659                         Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (AssemblyTest).Assembly.FullName);
660                         assembly.CreateInstance ("MonoTests.System.Reflection.AssemblyTest");
661                 }
662 #endif
663
664                 [Test]
665                 [Category ("NotWorking")] // patch for bug #79720 must be committed first
666                 public void Load_Culture ()
667                 {
668                         string tempDir = Path.Combine (Path.GetTempPath (),
669                                 "MonoTests.System.Reflection.AssemblyTest");
670                         string cultureTempDir = Path.Combine (tempDir, "nl-BE");
671                         if (!Directory.Exists (cultureTempDir))
672                                 Directory.CreateDirectory (cultureTempDir);
673                         cultureTempDir = Path.Combine (tempDir, "en-US");
674                         if (!Directory.Exists (cultureTempDir))
675                                 Directory.CreateDirectory (cultureTempDir);
676
677
678                         AppDomain ad = CreateTestDomain (tempDir, true);
679                         try {
680                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
681
682                                 // PART A
683
684                                 AssemblyName aname = new AssemblyName ();
685                                 aname.Name = "culturea";
686                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "culturea.dll"));
687
688                                 aname = new AssemblyName ();
689                                 aname.Name = "culturea";
690                                 Assert.IsTrue (cdt.AssertLoad(aname), "#A1");
691
692                                 aname = new AssemblyName ();
693                                 aname.Name = "culturea";
694                                 aname.CultureInfo = new CultureInfo ("nl-BE");
695                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#A2");
696
697                                 aname = new AssemblyName ();
698                                 aname.Name = "culturea";
699                                 aname.CultureInfo = CultureInfo.InvariantCulture;
700                                 Assert.IsTrue (cdt.AssertLoad(aname), "#A3");
701
702                                 // PART B
703
704                                 aname = new AssemblyName ();
705                                 aname.Name = "cultureb";
706                                 aname.CultureInfo = new CultureInfo ("nl-BE");
707                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "cultureb.dll"));
708
709                                 aname = new AssemblyName ();
710                                 aname.Name = "cultureb";
711                                 aname.CultureInfo = new CultureInfo ("nl-BE");
712                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#B1");
713
714                                 aname = new AssemblyName ();
715                                 aname.Name = "cultureb";
716                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B2");
717
718                                 aname = new AssemblyName ();
719                                 aname.Name = "cultureb";
720                                 aname.CultureInfo = new CultureInfo ("en-US");
721                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#B3");
722
723                                 // PART C
724
725                                 aname = new AssemblyName ();
726                                 aname.Name = "culturec";
727                                 aname.CultureInfo = new CultureInfo ("nl-BE");
728                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/culturec.dll"));
729
730                                 aname = new AssemblyName ();
731                                 aname.Name = "culturec";
732                                 aname.CultureInfo = new CultureInfo ("nl-BE");
733                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C1");
734
735                                 aname = new AssemblyName ();
736                                 aname.Name = "culturec";
737                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#C2");
738
739                                 aname = new AssemblyName ();
740                                 aname.Name = "culturec";
741                                 aname.CultureInfo = CultureInfo.InvariantCulture;
742                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#C3");
743
744                                 // PART D
745
746                                 aname = new AssemblyName ();
747                                 aname.Name = "cultured";
748                                 aname.CultureInfo = new CultureInfo ("nl-BE");
749                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "en-US/cultured.dll"));
750
751                                 aname = new AssemblyName ();
752                                 aname.Name = "cultured";
753                                 aname.CultureInfo = new CultureInfo ("nl-BE");
754                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#D1");
755
756                                 aname = new AssemblyName ();
757                                 aname.Name = "cultured";
758                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#D2");
759
760                                 aname = new AssemblyName ();
761                                 aname.Name = "cultured";
762                                 aname.CultureInfo = CultureInfo.InvariantCulture;
763                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#D3");
764                         } finally {
765                                 AppDomain.Unload (ad);
766                                 if (Directory.Exists (tempDir))
767                                         Directory.Delete (tempDir, true);
768                         }
769                 }
770
771                 [Test] // bug #79712
772 #if NET_2_0
773                 [Category ("NotWorking")] // in non-default domain, MS throws FileNotFoundException
774 #else
775                 [Category ("NotWorking")]
776 #endif
777                 public void Load_Culture_Mismatch ()
778                 {
779                         string tempDir = Path.Combine (Path.GetTempPath (),
780                                 "MonoTests.System.Reflection.AssemblyTest");
781                         string cultureTempDir = Path.Combine (tempDir, "en-US");
782                         if (!Directory.Exists (cultureTempDir))
783                                 Directory.CreateDirectory (cultureTempDir);
784
785                         AppDomain ad = CreateTestDomain (tempDir, true);
786                         try {
787                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
788
789                                 // PART A
790
791                                 AssemblyName aname = new AssemblyName ();
792                                 aname.Name = "bug79712a";
793                                 aname.CultureInfo = new CultureInfo ("nl-BE");
794                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "bug79712a.dll"));
795
796                                 aname = new AssemblyName ();
797                                 aname.Name = "bug79712a";
798                                 aname.CultureInfo = CultureInfo.InvariantCulture;
799 #if NET_2_0
800                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#A1");
801 #else
802                                 Assert.IsTrue (cdt.AssertFileLoadException (aname), "#A2");
803 #endif
804
805                                 // PART B
806
807                                 aname = new AssemblyName ();
808                                 aname.Name = "bug79712b";
809                                 aname.CultureInfo = new CultureInfo ("nl-BE");
810                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "en-US/bug79712b.dll"));
811
812                                 aname = new AssemblyName ();
813                                 aname.Name = "bug79712b";
814                                 aname.CultureInfo = new CultureInfo ("en-US");
815 #if NET_2_0
816                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#B1");
817 #else
818                                 Assert.IsTrue (cdt.AssertFileLoadException (aname), "#B2");
819 #endif
820                         } finally {
821                                 AppDomain.Unload (ad);
822                                 if (Directory.Exists (tempDir))
823                                         Directory.Delete (tempDir, true);
824                         }
825                 }
826
827
828                 [Test] // bug #79715
829                 public void Load_PartialVersion ()
830                 {
831                         string tempDir = Path.Combine (Path.GetTempPath (),
832                                 "MonoTests.System.Reflection.AssemblyTest");
833                         if (!Directory.Exists (tempDir))
834                                 Directory.CreateDirectory (tempDir);
835
836                         AppDomain ad = CreateTestDomain (tempDir, true);
837                         try {
838                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
839
840                                 AssemblyName aname = new AssemblyName ();
841                                 aname.Name = "bug79715";
842                                 aname.Version = new Version (1, 2, 3, 4);
843                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "bug79715.dll"));
844
845                                 aname = new AssemblyName ();
846                                 aname.Name = "bug79715";
847                                 aname.Version = new Version (1, 2);
848                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A1");
849                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#A2");
850
851                                 aname = new AssemblyName ();
852                                 aname.Name = "bug79715";
853                                 aname.Version = new Version (1, 2, 3);
854                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B1");
855                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#B2");
856
857                                 aname = new AssemblyName ();
858                                 aname.Name = "bug79715";
859                                 aname.Version = new Version (1, 2, 3, 4);
860                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C1");
861                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#C2");
862                         } finally {
863                                 AppDomain.Unload (ad);
864                                 if (Directory.Exists (tempDir))
865                                         Directory.Delete (tempDir, true);
866                         }
867                 }
868
869                 private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
870                 {
871                         AppDomainSetup setup = new AppDomainSetup ();
872                         setup.ApplicationBase = baseDirectory;
873                         setup.ApplicationName = "testdomain";
874
875                         AppDomain ad = AppDomain.CreateDomain ("testdomain", 
876                                 AppDomain.CurrentDomain.Evidence, setup);
877
878                         if (assemblyResolver) {
879                                 Assembly ea = Assembly.GetExecutingAssembly ();
880                                 ad.CreateInstanceFrom (ea.CodeBase,
881                                         typeof (AssemblyResolveHandler).FullName,
882                                         false,
883                                         BindingFlags.Public | BindingFlags.Instance,
884                                         null,
885                                         new object [] { ea.Location, ea.FullName },
886                                         CultureInfo.InvariantCulture,
887                                         null,
888                                         null);
889                         }
890
891                         return ad;
892                 }
893
894                 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
895                 {
896                         Type testerType = typeof (CrossDomainTester);
897                         return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
898                                 testerType.Assembly.FullName, testerType.FullName, false,
899                                 BindingFlags.Public | BindingFlags.Instance, null, new object[0],
900                                 CultureInfo.InvariantCulture, new object[0], null);
901                 }
902
903                 private class CrossDomainTester : MarshalByRefObject
904                 {
905                         public void GenerateAssembly (AssemblyName aname, string path)
906                         {
907                                 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
908                                         aname, AssemblyBuilderAccess.Save, Path.GetDirectoryName (path));
909                                 ab.Save (Path.GetFileName (path));
910                         }
911
912                         public void Load (AssemblyName assemblyRef)
913                         {
914                                 Assembly.Load (assemblyRef);
915                         }
916
917                         public void LoadFrom (string assemblyFile)
918                         {
919                                 Assembly.LoadFrom (assemblyFile);
920                         }
921
922                         public bool AssertLoad (AssemblyName assemblyRef)
923                         {
924                                 try {
925                                         Assembly.Load (assemblyRef);
926                                         return true;
927                                 } catch {
928                                         return false;
929                                 }
930                         }
931
932                         public bool AssertLoad (string assemblyString)
933                         {
934                                 try {
935                                         Assembly.Load (assemblyString);
936                                         return true;
937                                 } catch {
938                                         return false;
939                                 }
940                         }
941
942                         public bool AssertFileLoadException (AssemblyName assemblyRef)
943                         {
944                                 try {
945                                         Assembly.Load (assemblyRef);
946                                         return false;
947                                 } catch (FileLoadException) {
948                                         return true;
949                                 }
950                         }
951
952                         public bool AssertFileNotFoundException (AssemblyName assemblyRef)
953                         {
954                                 try {
955                                         Assembly.Load (assemblyRef);
956                                         return false;
957                                 } catch (FileNotFoundException) {
958                                         return true;
959                                 }
960                         }
961
962                         public void bug78464 (string assemblyFileName)
963                         {
964                                 AssemblyName assemblyName = new AssemblyName ();
965                                 assemblyName.Name = "bug78464";
966
967                                 AssemblyBuilder ab = AppDomain.CurrentDomain
968                                         .DefineDynamicAssembly (assemblyName,
969                                         AssemblyBuilderAccess.Save,
970                                         Path.GetDirectoryName (assemblyFileName),
971                                         AppDomain.CurrentDomain.Evidence);
972                                 ab.Save (Path.GetFileName (assemblyFileName));
973
974                                 Assembly assembly;
975
976                                 using (FileStream fs = File.OpenRead (assemblyFileName)) {
977                                         byte[] buffer = new byte[fs.Length];
978                                         fs.Read (buffer, 0, buffer.Length);
979                                         assembly = Assembly.Load (buffer);
980                                         fs.Close ();
981                                 }
982
983                                 Assert.AreEqual (string.Empty, assembly.Location, "#1");
984
985                                 assembly = Assembly.LoadFrom (assemblyFileName, AppDomain.CurrentDomain.Evidence);
986                                 Assert.IsFalse (assembly.Location == string.Empty, "#2");
987                                 Assert.AreEqual (Path.GetFileName (assemblyFileName), Path.GetFileName(assembly.Location), "#3");
988                                 // note: we cannot check if directory names match, as MS.NET seems to 
989                                 // convert directory part of assembly location to lowercase
990                                 Assert.IsFalse (Path.GetDirectoryName(assembly.Location) == string.Empty, "#4");
991                         }
992
993                         public void bug78465 (string assemblyFileName)
994                         {
995                                 Assembly assembly = Assembly.LoadFrom (assemblyFileName, AppDomain.CurrentDomain.Evidence);
996                                 Assert.IsFalse (assembly.Location == string.Empty, "#2");
997                                 Assert.AreEqual (Path.GetFileName (assemblyFileName), Path.GetFileName (assembly.Location), "#3");
998                                 // note: we cannot check if directory names match, as MS.NET seems to 
999                                 // convert directory part of assembly location to lowercase
1000                                 Assert.IsFalse (Path.GetDirectoryName (assembly.Location) == string.Empty, "#4");
1001                         }
1002
1003                         public void bug78468 (string assemblyFileName)
1004                         {
1005                                 AssemblyName assemblyName = new AssemblyName ();
1006                                 assemblyName.Name = "bug78468b";
1007
1008                                 AssemblyBuilder ab = AppDomain.CurrentDomain
1009                                         .DefineDynamicAssembly (assemblyName,
1010                                         AssemblyBuilderAccess.Save,
1011                                         Path.GetDirectoryName (assemblyFileName),
1012                                         AppDomain.CurrentDomain.Evidence);
1013                                 ab.AddResourceFile ("read", "readme.txt");
1014                                 ab.Save (Path.GetFileName (assemblyFileName));
1015
1016                                 Assembly assembly = Assembly.LoadFrom (assemblyFileName, AppDomain.CurrentDomain.Evidence);
1017                                 Assert.IsTrue (assembly.Location != string.Empty, "#B1");
1018                                 string[] resNames = assembly.GetManifestResourceNames ();
1019                                 Assert.IsNotNull (resNames, "#B2");
1020                                 Assert.AreEqual (1, resNames.Length, "#B3");
1021                                 Assert.AreEqual ("read", resNames[0], "#B4");
1022                                 ManifestResourceInfo resInfo = assembly.GetManifestResourceInfo ("read");
1023                                 Assert.IsNotNull (resInfo, "#B5");
1024                                 Assert.AreEqual ("readme.txt", resInfo.FileName, "#B6");
1025                                 Assert.IsNull (resInfo.ReferencedAssembly, "#B7");
1026                                 Assert.AreEqual ((ResourceLocation) 0, resInfo.ResourceLocation, "#B8");
1027                                 Stream s = assembly.GetManifestResourceStream ("read");
1028                                 Assert.IsNotNull (s, "#B9");
1029                                 s.Close ();
1030                                 s = assembly.GetFile ("readme.txt");
1031                                 Assert.IsNotNull (s, "#B10");
1032                                 s.Close ();
1033                         }
1034                 }
1035
1036                 [Test]
1037                 public void bug79872 ()
1038                 {
1039                         Random rnd = new Random ();
1040                         string outdir;
1041                         int tries = 0;
1042
1043                 retry:
1044                         outdir = Path.Combine (Path.GetTempPath (), "bug79872-" + rnd.Next (10000, 99999));
1045                         if (Directory.Exists (outdir)) {
1046                                 try {
1047                                         Directory.Delete (outdir, true);
1048                                 } catch {
1049                                         if (++tries <= 100)
1050                                                 goto retry;
1051                                 }
1052                         }
1053
1054                         Directory.CreateDirectory (outdir);
1055
1056                         AssemblyName an = new AssemblyName ();
1057                         an.Name = "bug79872";
1058                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Save, outdir);
1059                         string dllname = "bug79872.dll";
1060                         ModuleBuilder mb1 = ab.DefineDynamicModule ("bug79872", dllname);
1061                         string netmodule = "bug79872.netmodule";
1062                         ModuleBuilder mb2 = ab.DefineDynamicModule (netmodule, netmodule);
1063                         TypeBuilder a1 = mb2.DefineType ("A");
1064                         a1.CreateType ();
1065                         ab.Save (dllname);
1066
1067                         bool ok = true;
1068                         try {
1069                                 Assembly.LoadFrom (Path.Combine (outdir, dllname));
1070                         } catch {
1071                                 ok = false;
1072                         }
1073                         Assert.IsTrue (ok, "Should load a .NET metadata file with an assembly manifest");
1074
1075                         ok = false;
1076                         try {
1077                                 Assembly.LoadFrom (Path.Combine (outdir, netmodule));
1078                         } catch (BadImageFormatException) {
1079                                 ok = true; // mono and .net 2.0 throw this
1080                         } catch (FileLoadException) {
1081                                 ok = true; // .net 1.1 throws this
1082                         } catch {
1083                                 // swallow the rest
1084                         }
1085                         Assert.IsTrue (ok, "Complain on loading a .NET metadata file without an assembly manifest");
1086
1087                         Directory.Delete (outdir, true);
1088                 }
1089 #endif // TARGET_JVM
1090
1091 #if NET_2_0
1092                 [Test]
1093                 public void ManifestModule ()
1094                 {
1095                         Assembly assembly = typeof (int).Assembly;
1096                         Module module = assembly.ManifestModule;
1097                         Assert.IsNotNull (module, "#1");
1098                         Assert.AreEqual (typeof (Module), module.GetType (), "#2");
1099                         Assert.AreEqual ("mscorlib.dll", module.Name, "#3");
1100                         Assert.IsFalse (module.IsResource (), "#4");
1101                         Assert.IsTrue (assembly.GetModules ().Length > 0, "#5");
1102                         Assert.AreSame (module, assembly.GetModules () [0], "#6");
1103                         Assert.AreSame (module, assembly.ManifestModule, "#7");
1104                 }
1105 #endif
1106
1107                 [Serializable ()]
1108                 private class AssemblyResolveHandler
1109                 {
1110                         public AssemblyResolveHandler (string assemblyFile, string assemblyName)
1111                         {
1112                                 _assemblyFile = assemblyFile;
1113                                 _assemblyName = assemblyName;
1114
1115                                 AppDomain.CurrentDomain.AssemblyResolve +=
1116                                         new ResolveEventHandler (ResolveAssembly);
1117                         }
1118
1119                         private Assembly ResolveAssembly (Object sender, ResolveEventArgs args)
1120                         {
1121                                 if (args.Name == _assemblyName)
1122                                         return Assembly.LoadFrom (_assemblyFile);
1123
1124                                 return null;
1125                         }
1126
1127                         private readonly string _assemblyFile;
1128                         private readonly string _assemblyName;
1129                 }
1130
1131                 protected internal class Bug328812_NestedFamORAssem { };
1132
1133                 [Test]
1134                 public void bug328812 ()
1135                 {
1136                         Assembly corlib_test = Assembly.GetExecutingAssembly ();
1137                         Assert.IsNull (corlib_test.GetType ("Bug328812_NestedFamORAssem"));
1138                         // Just a sanity check, in case the above passed for some other reason
1139                         Assert.IsNotNull (corlib_test.GetType ("MonoTests.System.Reflection.AssemblyTest+Bug328812_NestedFamORAssem"));
1140                 }
1141                 
1142                 [Test]
1143                 public void GetCustomAttributes_AttributeType_Null ()
1144                 {
1145                         Assembly a = typeof (int).Assembly;
1146                         try {
1147                                 a.GetCustomAttributes (null, false);
1148                                 Assert.Fail ("#1");
1149                         } catch (ArgumentNullException ex) {
1150                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1151                                 Assert.IsNull (ex.InnerException, "#3");
1152                                 Assert.IsNotNull (ex.Message, "#4");
1153                                 Assert.IsNotNull (ex.ParamName, "#5");
1154                                 Assert.AreEqual ("attributeType", ex.ParamName, "#6");
1155                         }
1156                 }
1157         }
1158 }