New test.
[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                         Assert.AreEqual (0, corlib_test.HostContext, "HostContext");
220 #if NET_4_0
221                         Assert.AreEqual ("v4.0.30128", corlib_test.ImageRuntimeVersion, "ImageRuntimeVersion");
222 #else
223                         Assert.AreEqual ("v2.0.50727", corlib_test.ImageRuntimeVersion, "ImageRuntimeVersion");
224 #endif
225
226                         Assert.IsNotNull (corlib_test.ManifestModule, "ManifestModule");
227                         Assert.IsFalse (corlib_test.ReflectionOnly, "ReflectionOnly");
228                 }
229 #endif
230
231                 [Test]
232                 public void GetAssembly ()
233                 {
234                         Assert.IsTrue (Assembly.GetAssembly (typeof (int)).FullName.StartsWith ("mscorlib"), "GetAssembly(int)");
235                         Assert.AreEqual (this.GetType ().Assembly.FullName, Assembly.GetAssembly (this.GetType ()).FullName, "GetAssembly(this)");
236                 }
237
238                 [Test]
239                 [Category("TargetJvmNotWorking")] // Not yet supported for TARGET_JVM
240                 public void GetFile_Null ()
241                 {
242                         try {
243                                 Assembly.GetExecutingAssembly ().GetFile (null);
244                                 Assert.Fail ("#1");
245                         } catch (ArgumentNullException ex) {
246                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
247                                 Assert.IsNull (ex.InnerException, "#3");
248                                 Assert.IsNotNull (ex.Message, "#4");
249                                 Assert.IsNull (ex.ParamName, "#5");
250                         }
251                 }
252
253                 [Test]
254                 [Category("TargetJvmNotWorking")] // Not yet supported for TARGET_JVM
255                 public void GetFile_Empty ()
256                 {
257                         try {
258                                 Assembly.GetExecutingAssembly ().GetFile (
259                                         String.Empty);
260                                 Assert.Fail ("#1");
261                         } catch (ArgumentException ex) {
262                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
263                                 Assert.IsNull (ex.InnerException, "#3");
264                                 Assert.IsNotNull (ex.Message, "#4");
265                                 Assert.IsNull (ex.ParamName, "#5");
266                         }
267                 }
268
269                 [Test]
270                 [Category("TargetJvmNotWorking")] // Not yet supported for TARGET_JVM
271                 public void GetFiles_False ()
272                 {
273                         Assembly corlib = typeof (int).Assembly;
274                         FileStream[] fss = corlib.GetFiles ();
275                         Assert.AreEqual (fss.Length, corlib.GetFiles (false).Length, "corlib.GetFiles (false)");
276
277                         Assembly corlib_test = Assembly.GetExecutingAssembly ();
278                         fss = corlib_test.GetFiles ();
279                         Assert.AreEqual (fss.Length, corlib_test.GetFiles (false).Length, "test.GetFiles (false)");
280                 }
281
282                 [Test]
283                 [Category("TargetJvmNotWorking")] // Not yet supported for TARGET_JVM
284                 public void GetFiles_True ()
285                 {
286                         Assembly corlib = typeof (int).Assembly;
287                         FileStream[] fss = corlib.GetFiles ();
288                         Assert.IsTrue (fss.Length <= corlib.GetFiles (true).Length, "corlib.GetFiles (true)");
289
290                         Assembly corlib_test = Assembly.GetExecutingAssembly ();
291                         fss = corlib_test.GetFiles ();
292                         Assert.IsTrue (fss.Length <= corlib_test.GetFiles (true).Length, "test.GetFiles (true)");
293                 }
294
295                 [Test]
296                 public void GetManifestResourceStream_Name_Empty ()
297                 {
298                         Assembly corlib = typeof (int).Assembly;
299
300                         try {
301                                 corlib.GetManifestResourceStream (string.Empty);
302                                 Assert.Fail ("#A1");
303                         } catch (ArgumentException ex) {
304                                 // String cannot have zero length
305                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
306                                 Assert.IsNull (ex.InnerException, "#A3");
307                                 Assert.IsNotNull (ex.Message, "#A4");
308                         }
309
310                         corlib.GetManifestResourceStream (typeof (int), string.Empty);
311
312                         try {
313                                 corlib.GetManifestResourceStream ((Type) null, string.Empty);
314                                 Assert.Fail ("#B1");
315                         } catch (ArgumentException ex) {
316                                 // String cannot have zero length
317                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
318                                 Assert.IsNull (ex.InnerException, "#B3");
319                                 Assert.IsNotNull (ex.Message, "#B4");
320                         }
321                 }
322
323                 [Test]
324                 public void GetManifestResourceStream_Name_Null ()
325                 {
326                         Assembly corlib = typeof (int).Assembly;
327
328                         try {
329                                 corlib.GetManifestResourceStream ((string) null);
330                                 Assert.Fail ("#A1");
331                         } catch (ArgumentNullException ex) {
332                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
333                                 Assert.IsNull (ex.InnerException, "#A3");
334                                 Assert.IsNotNull (ex.Message, "#A4");
335                         }
336
337                         corlib.GetManifestResourceStream (typeof (int), (string) null);
338
339                         try {
340                                 corlib.GetManifestResourceStream ((Type) null, (string) null);
341                                 Assert.Fail ("#B1");
342                         } catch (ArgumentNullException ex) {
343                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
344                                 Assert.IsNull (ex.InnerException, "#B3");
345                                 Assert.IsNotNull (ex.Message, "#B4");
346                                 Assert.IsNotNull (ex.ParamName, "#B5");
347                                 Assert.AreEqual ("type", ex.ParamName, "#B6");
348                         }
349                 }
350
351                 [Test]
352                 public void IsDefined_AttributeType_Null ()
353                 {
354                         Assembly corlib = typeof (int).Assembly;
355
356                         try {
357                                 corlib.IsDefined ((Type) null, false);
358                                 Assert.Fail ("#1");
359                         } catch (ArgumentNullException ex) {
360                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
361                                 Assert.IsNull (ex.InnerException, "#3");
362                                 Assert.IsNotNull (ex.Message, "#4");
363                                 Assert.IsNotNull (ex.ParamName, "#5");
364                                 Assert.AreEqual ("attributeType", ex.ParamName, "#6");
365                         }
366                 }
367
368                 [Test] // bug #78517
369 #if ONLY_1_1
370                 [Category ("NotDotNet")] // MS.NET 1.x throws FileLoadException
371 #endif
372                 public void LoadFrom_Empty_Assembly ()
373                 {
374                         string tempFile = Path.GetTempFileName ();
375
376                         try {
377                                 Assembly.LoadFrom (tempFile);
378                                 Assert.Fail ("#1");
379                         } catch (BadImageFormatException ex) {
380                                 Assert.IsNull (ex.InnerException, "#2");
381                         } finally {
382                                 File.Delete (tempFile);
383                         }
384                 }
385
386                 [Test] // bug #78517
387                 public void LoadFrom_Invalid_Assembly ()
388                 {
389                         string tempFile = Path.GetTempFileName ();
390                         using (StreamWriter sw = File.CreateText (tempFile)) {
391                                 sw.WriteLine ("foo");
392                                 sw.Close ();
393                         }
394
395                         try {
396                                 Assembly.LoadFrom (tempFile);
397                                 Assert.Fail ("#1");
398                         } catch (BadImageFormatException ex) {
399                                 Assert.IsNull (ex.InnerException, "#2");
400                         } finally {
401                                 File.Delete (tempFile);
402                         }
403                 }
404
405                 [Test]
406                 public void LoadFrom_NonExisting_Assembly ()
407                 {
408                         string tempFile = Path.GetTempFileName ();
409                         File.Delete (tempFile);
410
411                         try {
412                                 Assembly.LoadFrom (tempFile);
413                                 Assert.Fail ("#1");
414                         } catch (FileNotFoundException ex) {
415                                 Assert.IsNull (ex.InnerException, "#2");
416                         } finally {
417                                 File.Delete (tempFile);
418                         }
419                 }
420
421                 [Test]
422                 public void LoadWithPartialName ()
423                 {
424                         string [] names = { "corlib_test_net_1_1", "corlib_test_net_2_0", "corlib_test_net_4_0", "corlib_plattest" };
425
426                         foreach (string s in names)
427                                 if (Assembly.LoadWithPartialName (s) != null)
428                                         return;
429                         Assert.Fail ("Was not able to load any corlib test");
430                 }
431
432 #if !TARGET_JVM // GetObjectData currently not implemented for Assembly.
433                 [Test]
434                 public void GetObjectData_Info_Null ()
435                 {
436                         Assembly corlib = typeof (int).Assembly;
437                         try {
438                                 corlib.GetObjectData (null, new StreamingContext (
439                                         StreamingContextStates.All));
440                                 Assert.Fail ("#1");
441                         } catch (ArgumentNullException ex) {
442                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
443                                 Assert.IsNull (ex.InnerException, "#3");
444                                 Assert.IsNotNull (ex.Message, "#4");
445                                 Assert.IsNotNull (ex.ParamName, "#5");
446                                 Assert.AreEqual ("info", ex.ParamName, "#6");
447                         }
448                 }
449 #endif // TARGET_JVM
450
451                 [Test]
452                 public void GetReferencedAssemblies ()
453                 {
454                         Assembly corlib_test = Assembly.GetExecutingAssembly ();
455                         AssemblyName[] names = corlib_test.GetReferencedAssemblies ();
456                         foreach (AssemblyName an in names) {
457                                 Assert.IsNull (an.CodeBase, "CodeBase");
458                                 Assert.IsNotNull (an.CultureInfo, "CultureInfo");
459                                 Assert.IsNull (an.EscapedCodeBase, "EscapedCodeBase");
460                                 Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "Flags");
461                                 Assert.IsNotNull (an.FullName, "FullName");
462                                 Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "HashAlgorithm");
463                                 Assert.IsNull (an.KeyPair, "KeyPair");
464                                 Assert.IsNotNull (an.Name, "Name");
465                                 Assert.IsNotNull (an.Version, "Version");
466                                 Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, 
467                                         an.VersionCompatibility, "VersionCompatibility");
468                         }
469                 }
470
471 #if !TARGET_JVM // Reflection.Emit is not supported.
472                 [Test]
473                 public void Location_Empty() {
474                         string assemblyFileName = Path.Combine (
475                                 Path.GetTempPath (), "AssemblyLocation.dll");
476
477                         try {
478                                 AssemblyName assemblyName = new AssemblyName ();
479                                 assemblyName.Name = "AssemblyLocation";
480
481                                 AssemblyBuilder ab = AppDomain.CurrentDomain
482                                         .DefineDynamicAssembly (assemblyName,
483                                         AssemblyBuilderAccess.Save,
484                                         Path.GetTempPath (),
485                                         AppDomain.CurrentDomain.Evidence);
486                                 ab.Save (Path.GetFileName (assemblyFileName));
487
488                                 using (FileStream fs = File.OpenRead (assemblyFileName)) {
489                                         byte[] buffer = new byte[fs.Length];
490                                         fs.Read (buffer, 0, buffer.Length);
491                                         Assembly assembly = Assembly.Load (buffer);
492                                         Assert.AreEqual (string.Empty, assembly.Location);
493                                         fs.Close ();
494                                 }
495                         } finally {
496                                 File.Delete (assemblyFileName);
497                         }
498                 }
499
500                 [Test]
501                 [Category ("NotWorking")]
502                 public void bug78464 ()
503                 {
504                         string assemblyFileName = Path.Combine (
505                                 Path.GetTempPath (), "bug78464.dll");
506
507                         try {
508                                 // execute test in separate appdomain to allow assembly to be unloaded
509                                 AppDomain testDomain = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory, false);
510                                 CrossDomainTester crossDomainTester = CreateCrossDomainTester (testDomain);
511                                 try {
512                                         crossDomainTester.bug78464 (assemblyFileName);
513                                 } finally {
514                                         AppDomain.Unload (testDomain);
515                                 }
516                         } finally {
517                                 File.Delete (assemblyFileName);
518                         }
519                 }
520
521                 [Test]
522                 public void bug78465 ()
523                 {
524                         string assemblyFileName = Path.Combine (
525                                 Path.GetTempPath (), "bug78465.dll");
526
527                         try {
528                                 AssemblyName assemblyName = new AssemblyName ();
529                                 assemblyName.Name = "bug78465";
530
531                                 AssemblyBuilder ab = AppDomain.CurrentDomain
532                                         .DefineDynamicAssembly (assemblyName,
533                                         AssemblyBuilderAccess.Save,
534                                         Path.GetDirectoryName (assemblyFileName),
535                                         AppDomain.CurrentDomain.Evidence);
536                                 ab.Save (Path.GetFileName (assemblyFileName));
537
538                                 using (FileStream fs = File.OpenRead (assemblyFileName)) {
539                                         byte[] buffer = new byte[fs.Length];
540                                         fs.Read (buffer, 0, buffer.Length);
541                                         Assembly assembly = Assembly.Load (buffer);
542                                         Assert.AreEqual (string.Empty, assembly.Location, "#1");
543                                         fs.Close ();
544                                 }
545
546                                 AppDomain testDomain = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory, false);
547                                 CrossDomainTester crossDomainTester = CreateCrossDomainTester (testDomain);
548                                 try {
549                                         crossDomainTester.bug78465 (assemblyFileName);
550                                 } finally {
551                                         AppDomain.Unload (testDomain);
552                                 }
553                         } finally {
554                                 File.Delete (assemblyFileName);
555                         }
556                 }
557
558                 [Test]
559                 public void bug78468 ()
560                 {
561                         string assemblyFileNameA = Path.Combine (Path.GetTempPath (),
562                                 "bug78468a.dll");
563                         string resourceFileName = Path.Combine (Path.GetTempPath (),
564                                 "readme.txt");
565
566                         using (StreamWriter sw = File.CreateText (resourceFileName)) {
567                                 sw.WriteLine ("FOO");
568                                 sw.Close ();
569                         }
570
571                         try {
572                                 AssemblyName assemblyName = new AssemblyName ();
573                                 assemblyName.Name = "bug78468a";
574
575                                 AssemblyBuilder ab = AppDomain.CurrentDomain
576                                         .DefineDynamicAssembly (assemblyName,
577                                         AssemblyBuilderAccess.Save,
578                                         Path.GetTempPath (),
579                                         AppDomain.CurrentDomain.Evidence);
580                                 ab.AddResourceFile ("read", "readme.txt");
581                                 ab.Save (Path.GetFileName (assemblyFileNameA));
582
583                                 Assembly assembly;
584
585                                 using (FileStream fs = File.OpenRead (assemblyFileNameA)) {
586                                         byte[] buffer = new byte[fs.Length];
587                                         fs.Read (buffer, 0, buffer.Length);
588                                         assembly = Assembly.Load (buffer);
589                                         fs.Close ();
590                                 }
591
592                                 Assert.AreEqual (string.Empty, assembly.Location, "#A1");
593                                 string[] resNames = assembly.GetManifestResourceNames ();
594                                 Assert.IsNotNull (resNames, "#A2");
595                                 Assert.AreEqual (1, resNames.Length, "#A3");
596                                 Assert.AreEqual ("read", resNames[0], "#A4");
597                                 ManifestResourceInfo resInfo = assembly.GetManifestResourceInfo ("read");
598                                 Assert.IsNotNull (resInfo, "#A5");
599                                 Assert.AreEqual ("readme.txt", resInfo.FileName, "#A6");
600                                 Assert.IsNull (resInfo.ReferencedAssembly, "#A7");
601                                 Assert.AreEqual ((ResourceLocation) 0, resInfo.ResourceLocation, "#A8");
602 #if NET_2_0
603                                 try {
604                                         assembly.GetManifestResourceStream ("read");
605                                         Assert.Fail ("#A9");
606                                 } catch (FileNotFoundException) {
607                                 }
608 #else
609                                 Assert.IsNull (assembly.GetManifestResourceStream ("read"), "#A9");
610 #endif
611                                 try {
612                                         assembly.GetFile ("readme.txt");
613                                         Assert.Fail ("#A10");
614                                 } catch (FileNotFoundException) {
615                                 }
616
617                                 string assemblyFileNameB = Path.Combine (Path.GetTempPath (),
618                                         "bug78468b.dll");
619
620                                 AppDomain testDomain = CreateTestDomain (AppDomain.CurrentDomain.BaseDirectory, false);
621                                 CrossDomainTester crossDomainTester = CreateCrossDomainTester (testDomain);
622                                 try {
623                                         crossDomainTester.bug78468 (assemblyFileNameB);
624                                 } finally {
625                                         AppDomain.Unload (testDomain);
626                                         File.Delete (assemblyFileNameB);
627                                 }
628                         } finally {
629                                 File.Delete (assemblyFileNameA);
630                                 File.Delete (resourceFileName);
631                         }
632                 }
633
634 #if NET_2_0
635                 [Test]
636                 [Category ("NotWorking")]
637                 public void ReflectionOnlyLoad ()
638                 {
639                         Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (AssemblyTest).Assembly.FullName);
640                         
641                         Assert.IsNotNull (assembly);
642                         Assert.IsTrue (assembly.ReflectionOnly);
643                 }
644
645                 [Test]
646                 public void ReflectionOnlyLoadFrom ()
647                 {
648                         string loc = typeof (AssemblyTest).Assembly.Location;
649                         string filename = Path.GetFileName (loc);
650                         Assembly assembly = Assembly.ReflectionOnlyLoadFrom (filename);
651
652                         Assert.IsNotNull (assembly);
653                         Assert.IsTrue (assembly.ReflectionOnly);
654                 }
655
656                 [Test]
657                 [ExpectedException (typeof (ArgumentException))]
658                 public void CreateInstanceOnRefOnly ()
659                 {
660                         Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (AssemblyTest).Assembly.FullName);
661                         assembly.CreateInstance ("MonoTests.System.Reflection.AssemblyTest");
662                 }
663 #endif
664
665                 [Test]
666                 [Category ("NotWorking")] // patch for bug #79720 must be committed first
667                 public void Load_Culture ()
668                 {
669                         string tempDir = Path.Combine (Path.GetTempPath (),
670                                 "MonoTests.System.Reflection.AssemblyTest");
671                         string cultureTempDir = Path.Combine (tempDir, "nl-BE");
672                         if (!Directory.Exists (cultureTempDir))
673                                 Directory.CreateDirectory (cultureTempDir);
674                         cultureTempDir = Path.Combine (tempDir, "en-US");
675                         if (!Directory.Exists (cultureTempDir))
676                                 Directory.CreateDirectory (cultureTempDir);
677
678
679                         AppDomain ad = CreateTestDomain (tempDir, true);
680                         try {
681                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
682
683                                 // PART A
684
685                                 AssemblyName aname = new AssemblyName ();
686                                 aname.Name = "culturea";
687                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "culturea.dll"));
688
689                                 aname = new AssemblyName ();
690                                 aname.Name = "culturea";
691                                 Assert.IsTrue (cdt.AssertLoad(aname), "#A1");
692
693                                 aname = new AssemblyName ();
694                                 aname.Name = "culturea";
695                                 aname.CultureInfo = new CultureInfo ("nl-BE");
696                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#A2");
697
698                                 aname = new AssemblyName ();
699                                 aname.Name = "culturea";
700                                 aname.CultureInfo = CultureInfo.InvariantCulture;
701                                 Assert.IsTrue (cdt.AssertLoad(aname), "#A3");
702
703                                 // PART B
704
705                                 aname = new AssemblyName ();
706                                 aname.Name = "cultureb";
707                                 aname.CultureInfo = new CultureInfo ("nl-BE");
708                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "cultureb.dll"));
709
710                                 aname = new AssemblyName ();
711                                 aname.Name = "cultureb";
712                                 aname.CultureInfo = new CultureInfo ("nl-BE");
713                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#B1");
714
715                                 aname = new AssemblyName ();
716                                 aname.Name = "cultureb";
717                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B2");
718
719                                 aname = new AssemblyName ();
720                                 aname.Name = "cultureb";
721                                 aname.CultureInfo = new CultureInfo ("en-US");
722                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#B3");
723
724                                 // PART C
725
726                                 aname = new AssemblyName ();
727                                 aname.Name = "culturec";
728                                 aname.CultureInfo = new CultureInfo ("nl-BE");
729                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "nl-BE/culturec.dll"));
730
731                                 aname = new AssemblyName ();
732                                 aname.Name = "culturec";
733                                 aname.CultureInfo = new CultureInfo ("nl-BE");
734                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C1");
735
736                                 aname = new AssemblyName ();
737                                 aname.Name = "culturec";
738                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#C2");
739
740                                 aname = new AssemblyName ();
741                                 aname.Name = "culturec";
742                                 aname.CultureInfo = CultureInfo.InvariantCulture;
743                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#C3");
744
745                                 // PART D
746
747                                 aname = new AssemblyName ();
748                                 aname.Name = "cultured";
749                                 aname.CultureInfo = new CultureInfo ("nl-BE");
750                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "en-US/cultured.dll"));
751
752                                 aname = new AssemblyName ();
753                                 aname.Name = "cultured";
754                                 aname.CultureInfo = new CultureInfo ("nl-BE");
755                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#D1");
756
757                                 aname = new AssemblyName ();
758                                 aname.Name = "cultured";
759                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#D2");
760
761                                 aname = new AssemblyName ();
762                                 aname.Name = "cultured";
763                                 aname.CultureInfo = CultureInfo.InvariantCulture;
764                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#D3");
765                         } finally {
766                                 AppDomain.Unload (ad);
767                                 if (Directory.Exists (tempDir))
768                                         Directory.Delete (tempDir, true);
769                         }
770                 }
771
772                 [Test] // bug #79712
773 #if NET_2_0
774                 [Category ("NotWorking")] // in non-default domain, MS throws FileNotFoundException
775 #else
776                 [Category ("NotWorking")]
777 #endif
778                 public void Load_Culture_Mismatch ()
779                 {
780                         string tempDir = Path.Combine (Path.GetTempPath (),
781                                 "MonoTests.System.Reflection.AssemblyTest");
782                         string cultureTempDir = Path.Combine (tempDir, "en-US");
783                         if (!Directory.Exists (cultureTempDir))
784                                 Directory.CreateDirectory (cultureTempDir);
785
786                         AppDomain ad = CreateTestDomain (tempDir, true);
787                         try {
788                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
789
790                                 // PART A
791
792                                 AssemblyName aname = new AssemblyName ();
793                                 aname.Name = "bug79712a";
794                                 aname.CultureInfo = new CultureInfo ("nl-BE");
795                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "bug79712a.dll"));
796
797                                 aname = new AssemblyName ();
798                                 aname.Name = "bug79712a";
799                                 aname.CultureInfo = CultureInfo.InvariantCulture;
800 #if NET_2_0
801                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#A1");
802 #else
803                                 Assert.IsTrue (cdt.AssertFileLoadException (aname), "#A2");
804 #endif
805
806                                 // PART B
807
808                                 aname = new AssemblyName ();
809                                 aname.Name = "bug79712b";
810                                 aname.CultureInfo = new CultureInfo ("nl-BE");
811                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "en-US/bug79712b.dll"));
812
813                                 aname = new AssemblyName ();
814                                 aname.Name = "bug79712b";
815                                 aname.CultureInfo = new CultureInfo ("en-US");
816 #if NET_2_0
817                                 Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#B1");
818 #else
819                                 Assert.IsTrue (cdt.AssertFileLoadException (aname), "#B2");
820 #endif
821                         } finally {
822                                 AppDomain.Unload (ad);
823                                 if (Directory.Exists (tempDir))
824                                         Directory.Delete (tempDir, true);
825                         }
826                 }
827
828
829                 [Test] // bug #79715
830                 public void Load_PartialVersion ()
831                 {
832                         string tempDir = Path.Combine (Path.GetTempPath (),
833                                 "MonoTests.System.Reflection.AssemblyTest");
834                         if (!Directory.Exists (tempDir))
835                                 Directory.CreateDirectory (tempDir);
836
837                         AppDomain ad = CreateTestDomain (tempDir, true);
838                         try {
839                                 CrossDomainTester cdt = CreateCrossDomainTester (ad);
840
841                                 AssemblyName aname = new AssemblyName ();
842                                 aname.Name = "bug79715";
843                                 aname.Version = new Version (1, 2, 3, 4);
844                                 cdt.GenerateAssembly (aname, Path.Combine (tempDir, "bug79715.dll"));
845
846                                 aname = new AssemblyName ();
847                                 aname.Name = "bug79715";
848                                 aname.Version = new Version (1, 2);
849                                 Assert.IsTrue (cdt.AssertLoad (aname), "#A1");
850                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#A2");
851
852                                 aname = new AssemblyName ();
853                                 aname.Name = "bug79715";
854                                 aname.Version = new Version (1, 2, 3);
855                                 Assert.IsTrue (cdt.AssertLoad (aname), "#B1");
856                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#B2");
857
858                                 aname = new AssemblyName ();
859                                 aname.Name = "bug79715";
860                                 aname.Version = new Version (1, 2, 3, 4);
861                                 Assert.IsTrue (cdt.AssertLoad (aname), "#C1");
862                                 Assert.IsTrue (cdt.AssertLoad (aname.FullName), "#C2");
863                         } finally {
864                                 AppDomain.Unload (ad);
865                                 if (Directory.Exists (tempDir))
866                                         Directory.Delete (tempDir, true);
867                         }
868                 }
869
870                 private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver)
871                 {
872                         AppDomainSetup setup = new AppDomainSetup ();
873                         setup.ApplicationBase = baseDirectory;
874                         setup.ApplicationName = "testdomain";
875
876                         AppDomain ad = AppDomain.CreateDomain ("testdomain", 
877                                 AppDomain.CurrentDomain.Evidence, setup);
878
879                         if (assemblyResolver) {
880                                 Assembly ea = Assembly.GetExecutingAssembly ();
881                                 ad.CreateInstanceFrom (ea.CodeBase,
882                                         typeof (AssemblyResolveHandler).FullName,
883                                         false,
884                                         BindingFlags.Public | BindingFlags.Instance,
885                                         null,
886                                         new object [] { ea.Location, ea.FullName },
887                                         CultureInfo.InvariantCulture,
888                                         null,
889                                         null);
890                         }
891
892                         return ad;
893                 }
894
895                 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
896                 {
897                         Type testerType = typeof (CrossDomainTester);
898                         return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
899                                 testerType.Assembly.FullName, testerType.FullName, false,
900                                 BindingFlags.Public | BindingFlags.Instance, null, new object[0],
901                                 CultureInfo.InvariantCulture, new object[0], null);
902                 }
903
904                 private class CrossDomainTester : MarshalByRefObject
905                 {
906                         public void GenerateAssembly (AssemblyName aname, string path)
907                         {
908                                 AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
909                                         aname, AssemblyBuilderAccess.Save, Path.GetDirectoryName (path));
910                                 ab.Save (Path.GetFileName (path));
911                         }
912
913                         public void Load (AssemblyName assemblyRef)
914                         {
915                                 Assembly.Load (assemblyRef);
916                         }
917
918                         public void LoadFrom (string assemblyFile)
919                         {
920                                 Assembly.LoadFrom (assemblyFile);
921                         }
922
923                         public bool AssertLoad (AssemblyName assemblyRef)
924                         {
925                                 try {
926                                         Assembly.Load (assemblyRef);
927                                         return true;
928                                 } catch {
929                                         return false;
930                                 }
931                         }
932
933                         public bool AssertLoad (string assemblyString)
934                         {
935                                 try {
936                                         Assembly.Load (assemblyString);
937                                         return true;
938                                 } catch {
939                                         return false;
940                                 }
941                         }
942
943                         public bool AssertFileLoadException (AssemblyName assemblyRef)
944                         {
945                                 try {
946                                         Assembly.Load (assemblyRef);
947                                         return false;
948                                 } catch (FileLoadException) {
949                                         return true;
950                                 }
951                         }
952
953                         public bool AssertFileNotFoundException (AssemblyName assemblyRef)
954                         {
955                                 try {
956                                         Assembly.Load (assemblyRef);
957                                         return false;
958                                 } catch (FileNotFoundException) {
959                                         return true;
960                                 }
961                         }
962
963                         public void bug78464 (string assemblyFileName)
964                         {
965                                 AssemblyName assemblyName = new AssemblyName ();
966                                 assemblyName.Name = "bug78464";
967
968                                 AssemblyBuilder ab = AppDomain.CurrentDomain
969                                         .DefineDynamicAssembly (assemblyName,
970                                         AssemblyBuilderAccess.Save,
971                                         Path.GetDirectoryName (assemblyFileName),
972                                         AppDomain.CurrentDomain.Evidence);
973                                 ab.Save (Path.GetFileName (assemblyFileName));
974
975                                 Assembly assembly;
976
977                                 using (FileStream fs = File.OpenRead (assemblyFileName)) {
978                                         byte[] buffer = new byte[fs.Length];
979                                         fs.Read (buffer, 0, buffer.Length);
980                                         assembly = Assembly.Load (buffer);
981                                         fs.Close ();
982                                 }
983
984                                 Assert.AreEqual (string.Empty, assembly.Location, "#1");
985
986                                 assembly = Assembly.LoadFrom (assemblyFileName, AppDomain.CurrentDomain.Evidence);
987                                 Assert.IsFalse (assembly.Location == string.Empty, "#2");
988                                 Assert.AreEqual (Path.GetFileName (assemblyFileName), Path.GetFileName(assembly.Location), "#3");
989                                 // note: we cannot check if directory names match, as MS.NET seems to 
990                                 // convert directory part of assembly location to lowercase
991                                 Assert.IsFalse (Path.GetDirectoryName(assembly.Location) == string.Empty, "#4");
992                         }
993
994                         public void bug78465 (string assemblyFileName)
995                         {
996                                 Assembly assembly = Assembly.LoadFrom (assemblyFileName, AppDomain.CurrentDomain.Evidence);
997                                 Assert.IsFalse (assembly.Location == string.Empty, "#2");
998                                 Assert.AreEqual (Path.GetFileName (assemblyFileName), Path.GetFileName (assembly.Location), "#3");
999                                 // note: we cannot check if directory names match, as MS.NET seems to 
1000                                 // convert directory part of assembly location to lowercase
1001                                 Assert.IsFalse (Path.GetDirectoryName (assembly.Location) == string.Empty, "#4");
1002                         }
1003
1004                         public void bug78468 (string assemblyFileName)
1005                         {
1006                                 AssemblyName assemblyName = new AssemblyName ();
1007                                 assemblyName.Name = "bug78468b";
1008
1009                                 AssemblyBuilder ab = AppDomain.CurrentDomain
1010                                         .DefineDynamicAssembly (assemblyName,
1011                                         AssemblyBuilderAccess.Save,
1012                                         Path.GetDirectoryName (assemblyFileName),
1013                                         AppDomain.CurrentDomain.Evidence);
1014                                 ab.AddResourceFile ("read", "readme.txt");
1015                                 ab.Save (Path.GetFileName (assemblyFileName));
1016
1017                                 Assembly assembly = Assembly.LoadFrom (assemblyFileName, AppDomain.CurrentDomain.Evidence);
1018                                 Assert.IsTrue (assembly.Location != string.Empty, "#B1");
1019                                 string[] resNames = assembly.GetManifestResourceNames ();
1020                                 Assert.IsNotNull (resNames, "#B2");
1021                                 Assert.AreEqual (1, resNames.Length, "#B3");
1022                                 Assert.AreEqual ("read", resNames[0], "#B4");
1023                                 ManifestResourceInfo resInfo = assembly.GetManifestResourceInfo ("read");
1024                                 Assert.IsNotNull (resInfo, "#B5");
1025                                 Assert.AreEqual ("readme.txt", resInfo.FileName, "#B6");
1026                                 Assert.IsNull (resInfo.ReferencedAssembly, "#B7");
1027                                 Assert.AreEqual ((ResourceLocation) 0, resInfo.ResourceLocation, "#B8");
1028                                 Stream s = assembly.GetManifestResourceStream ("read");
1029                                 Assert.IsNotNull (s, "#B9");
1030                                 s.Close ();
1031                                 s = assembly.GetFile ("readme.txt");
1032                                 Assert.IsNotNull (s, "#B10");
1033                                 s.Close ();
1034                         }
1035                 }
1036
1037                 [Test]
1038                 public void bug79872 ()
1039                 {
1040                         Random rnd = new Random ();
1041                         string outdir;
1042                         int tries = 0;
1043
1044                 retry:
1045                         outdir = Path.Combine (Path.GetTempPath (), "bug79872-" + rnd.Next (10000, 99999));
1046                         if (Directory.Exists (outdir)) {
1047                                 try {
1048                                         Directory.Delete (outdir, true);
1049                                 } catch {
1050                                         if (++tries <= 100)
1051                                                 goto retry;
1052                                 }
1053                         }
1054
1055                         Directory.CreateDirectory (outdir);
1056
1057                         AssemblyName an = new AssemblyName ();
1058                         an.Name = "bug79872";
1059                         AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Save, outdir);
1060                         string dllname = "bug79872.dll";
1061                         ModuleBuilder mb1 = ab.DefineDynamicModule ("bug79872", dllname);
1062                         string netmodule = "bug79872.netmodule";
1063                         ModuleBuilder mb2 = ab.DefineDynamicModule (netmodule, netmodule);
1064                         TypeBuilder a1 = mb2.DefineType ("A");
1065                         a1.CreateType ();
1066                         ab.Save (dllname);
1067
1068                         bool ok = true;
1069                         try {
1070                                 Assembly.LoadFrom (Path.Combine (outdir, dllname));
1071                         } catch {
1072                                 ok = false;
1073                         }
1074                         Assert.IsTrue (ok, "Should load a .NET metadata file with an assembly manifest");
1075
1076                         ok = false;
1077                         try {
1078                                 Assembly.LoadFrom (Path.Combine (outdir, netmodule));
1079                         } catch (BadImageFormatException) {
1080                                 ok = true; // mono and .net 2.0 throw this
1081                         } catch (FileLoadException) {
1082                                 ok = true; // .net 1.1 throws this
1083                         } catch {
1084                                 // swallow the rest
1085                         }
1086                         Assert.IsTrue (ok, "Complain on loading a .NET metadata file without an assembly manifest");
1087
1088                         Directory.Delete (outdir, true);
1089                 }
1090 #endif // TARGET_JVM
1091
1092 #if NET_2_0
1093                 [Test]
1094                 public void ManifestModule ()
1095                 {
1096                         Assembly assembly = typeof (int).Assembly;
1097                         Module module = assembly.ManifestModule;
1098                         Assert.IsNotNull (module, "#1");
1099                         Assert.AreEqual (typeof (Module), module.GetType (), "#2");
1100                         Assert.AreEqual ("mscorlib.dll", module.Name, "#3");
1101                         Assert.IsFalse (module.IsResource (), "#4");
1102                         Assert.IsTrue (assembly.GetModules ().Length > 0, "#5");
1103                         Assert.AreSame (module, assembly.GetModules () [0], "#6");
1104                         Assert.AreSame (module, assembly.ManifestModule, "#7");
1105                 }
1106 #endif
1107
1108                 [Serializable ()]
1109                 private class AssemblyResolveHandler
1110                 {
1111                         public AssemblyResolveHandler (string assemblyFile, string assemblyName)
1112                         {
1113                                 _assemblyFile = assemblyFile;
1114                                 _assemblyName = assemblyName;
1115
1116                                 AppDomain.CurrentDomain.AssemblyResolve +=
1117                                         new ResolveEventHandler (ResolveAssembly);
1118                         }
1119
1120                         private Assembly ResolveAssembly (Object sender, ResolveEventArgs args)
1121                         {
1122                                 if (args.Name == _assemblyName)
1123                                         return Assembly.LoadFrom (_assemblyFile);
1124
1125                                 return null;
1126                         }
1127
1128                         private readonly string _assemblyFile;
1129                         private readonly string _assemblyName;
1130                 }
1131
1132                 protected internal class Bug328812_NestedFamORAssem { };
1133
1134                 [Test]
1135                 public void bug328812 ()
1136                 {
1137                         Assembly corlib_test = Assembly.GetExecutingAssembly ();
1138                         Assert.IsNull (corlib_test.GetType ("Bug328812_NestedFamORAssem"));
1139                         // Just a sanity check, in case the above passed for some other reason
1140                         Assert.IsNotNull (corlib_test.GetType ("MonoTests.System.Reflection.AssemblyTest+Bug328812_NestedFamORAssem"));
1141                 }
1142                 
1143                 [Test]
1144                 public void GetCustomAttributes_AttributeType_Null ()
1145                 {
1146                         Assembly a = typeof (int).Assembly;
1147                         try {
1148                                 a.GetCustomAttributes (null, false);
1149                                 Assert.Fail ("#1");
1150                         } catch (ArgumentNullException ex) {
1151                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1152                                 Assert.IsNull (ex.InnerException, "#3");
1153                                 Assert.IsNotNull (ex.Message, "#4");
1154                                 Assert.IsNotNull (ex.ParamName, "#5");
1155                                 Assert.AreEqual ("attributeType", ex.ParamName, "#6");
1156                         }
1157                 }
1158
1159                 [Test]
1160                 public void GetTypeWithEmptyStringShouldThrow ()
1161                 {
1162                         try {
1163                                 typeof (string).Assembly.GetType ("");
1164                                 Assert.Fail ("#1");
1165                         } catch (ArgumentException) {}
1166                 }
1167
1168         }
1169 }