Merge branch 'sgen-android'
[mono.git] / mcs / class / IKVM.Reflection / Emit / AssemblyBuilder.cs
1 /*
2   Copyright (C) 2008-2011 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24 using System;
25 using System.Collections.Generic;
26 using System.Configuration.Assemblies;
27 using System.IO;
28 using System.Diagnostics;
29 using System.Globalization;
30 using System.Security.Cryptography;
31 using System.Security;
32 using IKVM.Reflection.Metadata;
33 using IKVM.Reflection.Impl;
34 using IKVM.Reflection.Writer;
35
36 namespace IKVM.Reflection.Emit
37 {
38         public sealed class AssemblyBuilder : Assembly
39         {
40                 private readonly string name;
41                 private ushort majorVersion;
42                 private ushort minorVersion;
43                 private ushort buildVersion;
44                 private ushort revisionVersion;
45                 private string culture;
46                 private AssemblyNameFlags flags;
47                 private AssemblyHashAlgorithm hashAlgorithm;
48                 private StrongNameKeyPair keyPair;
49                 private byte[] publicKey;
50                 internal readonly string dir;
51                 private readonly PermissionSet requiredPermissions;
52                 private readonly PermissionSet optionalPermissions;
53                 private readonly PermissionSet refusedPermissions;
54                 private PEFileKinds fileKind = PEFileKinds.Dll;
55                 private MethodInfo entryPoint;
56                 private VersionInfo versionInfo;
57                 private ResourceSection unmanagedResources;
58                 private string imageRuntimeVersion;
59                 internal int mdStreamVersion = 0x20000;
60                 private Module pseudoManifestModule;
61                 private readonly List<ResourceFile> resourceFiles = new List<ResourceFile>();
62                 private readonly List<ModuleBuilder> modules = new List<ModuleBuilder>();
63                 private readonly List<Module> addedModules = new List<Module>();
64                 private readonly List<CustomAttributeBuilder> customAttributes = new List<CustomAttributeBuilder>();
65                 private readonly List<CustomAttributeBuilder> declarativeSecurity = new List<CustomAttributeBuilder>();
66                 private readonly List<Type> typeForwarders = new List<Type>();
67
68                 private struct ResourceFile
69                 {
70                         internal string Name;
71                         internal string FileName;
72                         internal ResourceAttributes Attributes;
73                 }
74
75                 internal AssemblyBuilder(Universe universe, AssemblyName name, string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
76                         : base(universe)
77                 {
78                         this.name = name.Name;
79                         SetVersionHelper(name.Version);
80                         if (name.CultureInfo != null && !string.IsNullOrEmpty(name.CultureInfo.Name))
81                         {
82                                 this.culture = name.CultureInfo.Name;
83                         }
84                         this.flags = name.Flags;
85                         this.hashAlgorithm = name.HashAlgorithm;
86                         if (this.hashAlgorithm == AssemblyHashAlgorithm.None)
87                         {
88                                 this.hashAlgorithm = AssemblyHashAlgorithm.SHA1;
89                         }
90                         this.keyPair = name.KeyPair;
91                         if (this.keyPair != null)
92                         {
93                                 this.publicKey = this.keyPair.PublicKey;
94                         }
95                         else
96                         {
97                                 byte[] publicKey = name.GetPublicKey();
98                                 if (publicKey != null && publicKey.Length != 0)
99                                 {
100                                         this.publicKey = (byte[])publicKey.Clone();
101                                 }
102                         }
103                         this.dir = dir ?? ".";
104                         this.requiredPermissions = requiredPermissions;
105                         this.optionalPermissions = optionalPermissions;
106                         this.refusedPermissions = refusedPermissions;
107                         if (universe.HasMscorlib && universe.Mscorlib.ImageRuntimeVersion != null)
108                         {
109                                 this.imageRuntimeVersion = universe.Mscorlib.ImageRuntimeVersion;
110                         }
111                         else
112                         {
113                                 this.imageRuntimeVersion = typeof(object).Assembly.ImageRuntimeVersion;
114                         }
115                 }
116
117                 private void SetVersionHelper(Version version)
118                 {
119                         if (version == null)
120                         {
121                                 majorVersion = 0;
122                                 minorVersion = 0;
123                                 buildVersion = 0;
124                                 revisionVersion = 0;
125                         }
126                         else
127                         {
128                                 majorVersion = (ushort)version.Major;
129                                 minorVersion = (ushort)version.Minor;
130                                 buildVersion = version.Build == -1 ? (ushort)0 : (ushort)version.Build;
131                                 revisionVersion = version.Revision == -1 ? (ushort)0 : (ushort)version.Revision;
132                         }
133                 }
134
135                 public void __SetAssemblyVersion(Version version)
136                 {
137                         AssemblyName oldName = GetName();
138                         SetVersionHelper(version);
139                         universe.RenameAssembly(this, oldName);
140                 }
141
142                 public void __SetAssemblyCulture(string cultureName)
143                 {
144                         AssemblyName oldName = GetName();
145                         this.culture = cultureName;
146                         universe.RenameAssembly(this, oldName);
147                 }
148
149                 public void __SetAssemblyKeyPair(StrongNameKeyPair keyPair)
150                 {
151                         AssemblyName oldName = GetName();
152                         this.keyPair = keyPair;
153                         if (keyPair != null)
154                         {
155                                 this.publicKey = keyPair.PublicKey;
156                         }
157                         universe.RenameAssembly(this, oldName);
158                 }
159
160                 // this is used in combination with delay signing
161                 public void __SetAssemblyPublicKey(byte[] publicKey)
162                 {
163                         AssemblyName oldName = GetName();
164                         this.publicKey = publicKey == null ? null : (byte[])publicKey.Clone();
165                         universe.RenameAssembly(this, oldName);
166                 }
167
168                 public void __SetAssemblyAlgorithmId(AssemblyHashAlgorithm hashAlgorithm)
169                 {
170                         this.hashAlgorithm = hashAlgorithm;
171                 }
172
173                 public void __SetAssemblyFlags(AssemblyNameFlags flags)
174                 {
175                         this.flags = flags;
176                 }
177
178                 public override AssemblyName GetName()
179                 {
180                         AssemblyName n = new AssemblyName();
181                         n.Name = name;
182                         n.Version = new Version(majorVersion, minorVersion, buildVersion, revisionVersion);
183                         n.Culture = culture;
184                         n.HashAlgorithm = hashAlgorithm;
185                         n.Flags = flags;
186                         n.SetPublicKey(publicKey != null ? (byte[])publicKey.Clone() : Empty<byte>.Array);
187                         n.KeyPair = keyPair;
188                         return n;
189                 }
190
191                 public override string FullName
192                 {
193                         get { return GetName().FullName; }
194                 }
195
196                 public override string Location
197                 {
198                         get { throw new NotSupportedException(); }
199                 }
200
201                 public ModuleBuilder DefineDynamicModule(string name, string fileName)
202                 {
203                         return DefineDynamicModule(name, fileName, false);
204                 }
205
206                 public ModuleBuilder DefineDynamicModule(string name, string fileName, bool emitSymbolInfo)
207                 {
208                         ModuleBuilder module = new ModuleBuilder(this, name, fileName, emitSymbolInfo);
209                         modules.Add(module);
210                         return module;
211                 }
212
213                 public ModuleBuilder GetDynamicModule(string name)
214                 {
215                         foreach (ModuleBuilder module in modules)
216                         {
217                                 if (module.Name == name)
218                                 {
219                                         return module;
220                                 }
221                         }
222                         return null;
223                 }
224
225                 public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
226                 {
227                         SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
228                 }
229
230                 public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
231                 {
232                         customAttributes.Add(customBuilder);
233                 }
234
235                 public void __AddDeclarativeSecurity(CustomAttributeBuilder customBuilder)
236                 {
237                         declarativeSecurity.Add(customBuilder);
238                 }
239
240                 public void __AddTypeForwarder(Type type)
241                 {
242                         typeForwarders.Add(type);
243                 }
244
245                 public void SetEntryPoint(MethodInfo entryMethod)
246                 {
247                         SetEntryPoint(entryMethod, PEFileKinds.ConsoleApplication);
248                 }
249
250                 public void SetEntryPoint(MethodInfo entryMethod, PEFileKinds fileKind)
251                 {
252                         this.entryPoint = entryMethod;
253                         this.fileKind = fileKind;
254                 }
255
256                 public void __Save(Stream stream, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
257                 {
258                         if (!stream.CanRead || !stream.CanWrite || !stream.CanSeek || stream.Position != 0)
259                         {
260                                 throw new ArgumentException("Stream must support read/write/seek and current position must be zero.", "stream");
261                         }
262                         if (modules.Count != 1)
263                         {
264                                 throw new NotSupportedException("Saving to a stream is only supported for single module assemblies.");
265                         }
266                         SaveImpl(modules[0].fileName, stream, portableExecutableKind, imageFileMachine);
267                 }
268
269                 public void Save(string assemblyFileName)
270                 {
271                         Save(assemblyFileName, PortableExecutableKinds.ILOnly, ImageFileMachine.I386);
272                 }
273
274                 public void Save(string assemblyFileName, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
275                 {
276                         SaveImpl(assemblyFileName, null, portableExecutableKind, imageFileMachine);
277                 }
278
279                 private void SaveImpl(string assemblyFileName, Stream streamOrNull, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
280                 {
281                         ModuleBuilder manifestModule = null;
282
283                         foreach (ModuleBuilder moduleBuilder in modules)
284                         {
285                                 moduleBuilder.PopulatePropertyAndEventTables();
286
287                                 if (manifestModule == null
288                                         && string.Compare(moduleBuilder.fileName, assemblyFileName, StringComparison.OrdinalIgnoreCase) == 0)
289                                 {
290                                         manifestModule = moduleBuilder;
291                                 }
292                         }
293
294                         if (manifestModule == null)
295                         {
296                                 manifestModule = DefineDynamicModule("RefEmit_OnDiskManifestModule", assemblyFileName, false);
297                         }
298
299                         AssemblyTable.Record assemblyRecord = new AssemblyTable.Record();
300                         assemblyRecord.HashAlgId = (int)hashAlgorithm;
301                         assemblyRecord.Name = manifestModule.Strings.Add(name);
302                         assemblyRecord.MajorVersion = majorVersion;
303                         assemblyRecord.MinorVersion = minorVersion;
304                         assemblyRecord.BuildNumber = buildVersion;
305                         assemblyRecord.RevisionNumber = revisionVersion;
306                         if (publicKey != null)
307                         {
308                                 assemblyRecord.PublicKey = manifestModule.Blobs.Add(ByteBuffer.Wrap(publicKey));
309                                 assemblyRecord.Flags = (int)(flags | AssemblyNameFlags.PublicKey);
310                         }
311                         else
312                         {
313                                 assemblyRecord.Flags = (int)(flags & ~AssemblyNameFlags.PublicKey);
314                         }
315                         if (culture != null)
316                         {
317                                 assemblyRecord.Culture = manifestModule.Strings.Add(culture);
318                         }
319                         int token = 0x20000000 + manifestModule.AssemblyTable.AddRecord(assemblyRecord);
320
321 #pragma warning disable 618
322                         // this values are obsolete, but we already know that so we disable the warning
323                         System.Security.Permissions.SecurityAction requestMinimum = System.Security.Permissions.SecurityAction.RequestMinimum;
324                         System.Security.Permissions.SecurityAction requestOptional = System.Security.Permissions.SecurityAction.RequestOptional;
325                         System.Security.Permissions.SecurityAction requestRefuse = System.Security.Permissions.SecurityAction.RequestRefuse;
326 #pragma warning restore 618
327                         if (requiredPermissions != null)
328                         {
329                                 manifestModule.AddDeclarativeSecurity(token, requestMinimum, requiredPermissions);
330                         }
331                         if (optionalPermissions != null)
332                         {
333                                 manifestModule.AddDeclarativeSecurity(token, requestOptional, optionalPermissions);
334                         }
335                         if (refusedPermissions != null)
336                         {
337                                 manifestModule.AddDeclarativeSecurity(token, requestRefuse, refusedPermissions);
338                         }
339
340                         if (versionInfo != null)
341                         {
342                                 versionInfo.SetName(GetName());
343                                 versionInfo.SetFileName(assemblyFileName);
344                                 foreach (CustomAttributeBuilder cab in customAttributes)
345                                 {
346                                         // .NET doesn't support copying blob custom attributes into the version info
347                                         if (!cab.HasBlob)
348                                         {
349                                                 versionInfo.SetAttribute(cab);
350                                         }
351                                 }
352                                 ByteBuffer versionInfoData = new ByteBuffer(512);
353                                 versionInfo.Write(versionInfoData);
354                                 if (unmanagedResources == null)
355                                 {
356                                         unmanagedResources = new ResourceSection();
357                                 }
358                                 unmanagedResources.AddVersionInfo(versionInfoData);
359                         }
360
361                         foreach (CustomAttributeBuilder cab in customAttributes)
362                         {
363                                 // we intentionally don't filter out the version info (pseudo) custom attributes (to be compatible with .NET)
364                                 manifestModule.SetCustomAttribute(0x20000001, cab);
365                         }
366
367                         manifestModule.AddDeclarativeSecurity(0x20000001, declarativeSecurity);
368
369                         foreach (Type type in typeForwarders)
370                         {
371                                 manifestModule.AddTypeForwarder(type);
372                         }
373
374                         foreach (ResourceFile resfile in resourceFiles)
375                         {
376                                 int fileToken = AddFile(manifestModule, resfile.FileName, 1 /*ContainsNoMetaData*/);
377                                 ManifestResourceTable.Record rec = new ManifestResourceTable.Record();
378                                 rec.Offset = 0;
379                                 rec.Flags = (int)resfile.Attributes;
380                                 rec.Name = manifestModule.Strings.Add(resfile.Name);
381                                 rec.Implementation = fileToken;
382                                 manifestModule.ManifestResource.AddRecord(rec);
383                         }
384
385                         int entryPointToken = 0;
386
387                         foreach (ModuleBuilder moduleBuilder in modules)
388                         {
389                                 moduleBuilder.FillAssemblyRefTable();
390                                 if (moduleBuilder != manifestModule)
391                                 {
392                                         int fileToken;
393                                         if (entryPoint != null && entryPoint.Module == moduleBuilder)
394                                         {
395                                                 ModuleWriter.WriteModule(null, null, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, moduleBuilder.unmanagedResources, entryPoint.MetadataToken);
396                                                 entryPointToken = fileToken = AddFile(manifestModule, moduleBuilder.fileName, 0 /*ContainsMetaData*/);
397                                         }
398                                         else
399                                         {
400                                                 ModuleWriter.WriteModule(null, null, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, moduleBuilder.unmanagedResources, 0);
401                                                 fileToken = AddFile(manifestModule, moduleBuilder.fileName, 0 /*ContainsMetaData*/);
402                                         }
403                                         moduleBuilder.ExportTypes(fileToken, manifestModule);
404                                 }
405                         }
406
407                         foreach (Module module in addedModules)
408                         {
409                                 int fileToken = AddFile(manifestModule, module.FullyQualifiedName, 0 /*ContainsMetaData*/);
410                                 module.ExportTypes(fileToken, manifestModule);
411                         }
412
413                         if (entryPointToken == 0 && entryPoint != null)
414                         {
415                                 entryPointToken = entryPoint.MetadataToken;
416                         }
417
418                         // finally, write the manifest module
419                         ModuleWriter.WriteModule(keyPair, publicKey, manifestModule, fileKind, portableExecutableKind, imageFileMachine, unmanagedResources ?? manifestModule.unmanagedResources, entryPointToken, streamOrNull);
420                 }
421
422                 private int AddFile(ModuleBuilder manifestModule, string fileName, int flags)
423                 {
424                         SHA1Managed hash = new SHA1Managed();
425                         string fullPath = fileName;
426                         if (dir != null)
427                         {
428                                 fullPath = Path.Combine(dir, fileName);
429                         }
430                         using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
431                         {
432                                 using (CryptoStream cs = new CryptoStream(Stream.Null, hash, CryptoStreamMode.Write))
433                                 {
434                                         byte[] buf = new byte[8192];
435                                         ModuleWriter.HashChunk(fs, cs, buf, (int)fs.Length);
436                                 }
437                         }
438                         FileTable.Record file = new FileTable.Record();
439                         file.Flags = flags;
440                         file.Name = manifestModule.Strings.Add(Path.GetFileName(fileName));
441                         file.HashValue = manifestModule.Blobs.Add(ByteBuffer.Wrap(hash.Hash));
442                         return 0x26000000 + manifestModule.File.AddRecord(file);
443                 }
444
445                 public void AddResourceFile(string name, string fileName)
446                 {
447                         AddResourceFile(name, fileName, ResourceAttributes.Public);
448                 }
449
450                 public void AddResourceFile(string name, string fileName, ResourceAttributes attribs)
451                 {
452                         ResourceFile resfile = new ResourceFile();
453                         resfile.Name = name;
454                         resfile.FileName = fileName;
455                         resfile.Attributes = attribs;
456                         resourceFiles.Add(resfile);
457                 }
458
459                 public void DefineVersionInfoResource()
460                 {
461                         versionInfo = new VersionInfo();
462                 }
463
464                 public void DefineVersionInfoResource(string product, string productVersion, string company, string copyright, string trademark)
465                 {
466                         versionInfo = new VersionInfo();
467                         versionInfo.product = product;
468                         versionInfo.informationalVersion = productVersion;
469                         versionInfo.company = company;
470                         versionInfo.copyright = copyright;
471                         versionInfo.trademark = trademark;
472                 }
473
474                 public void __DefineIconResource(byte[] iconFile)
475                 {
476                         unmanagedResources = new ResourceSection();
477                         unmanagedResources.AddIcon(iconFile);
478                 }
479
480                 public void __DefineUnmanagedResource(byte[] resource)
481                 {
482                         // The standard .NET DefineUnmanagedResource(byte[]) is useless, because it embeds "resource" (as-is) as the .rsrc section,
483                         // but it doesn't set the PE file Resource Directory entry to point to it. That's why we have a renamed version, which behaves
484                         // like DefineUnmanagedResource(string).
485                         unmanagedResources = new ResourceSection();
486                         unmanagedResources.ExtractResources(resource);
487                 }
488
489                 public void DefineUnmanagedResource(string resourceFileName)
490                 {
491                         // This method reads the specified resource file (Win32 .res file) and converts it into the appropriate format and embeds it in the .rsrc section,
492                         // also setting the Resource Directory entry.
493                         __DefineUnmanagedResource(File.ReadAllBytes(resourceFileName));
494                 }
495
496                 public override Type[] GetTypes()
497                 {
498                         List<Type> list = new List<Type>();
499                         foreach (ModuleBuilder module in modules)
500                         {
501                                 module.GetTypesImpl(list);
502                         }
503                         foreach (Module module in addedModules)
504                         {
505                                 module.GetTypesImpl(list);
506                         }
507                         return list.ToArray();
508                 }
509
510                 internal override Type FindType(TypeName typeName)
511                 {
512                         foreach (ModuleBuilder mb in modules)
513                         {
514                                 Type type = mb.FindType(typeName);
515                                 if (type != null)
516                                 {
517                                         return type;
518                                 }
519                         }
520                         foreach (Module module in addedModules)
521                         {
522                                 Type type = module.FindType(typeName);
523                                 if (type != null)
524                                 {
525                                         return type;
526                                 }
527                         }
528                         return null;
529                 }
530
531                 public override string ImageRuntimeVersion
532                 {
533                         get { return imageRuntimeVersion; }
534                 }
535
536                 public void __SetImageRuntimeVersion(string imageRuntimeVersion, int mdStreamVersion)
537                 {
538                         this.imageRuntimeVersion = imageRuntimeVersion;
539                         this.mdStreamVersion = mdStreamVersion;
540                 }
541
542                 public override Module ManifestModule
543                 {
544                         get
545                         {
546                                 if (pseudoManifestModule == null)
547                                 {
548                                         pseudoManifestModule = new ManifestModule(this);
549                                 }
550                                 return pseudoManifestModule;
551                         }
552                 }
553
554                 public override MethodInfo EntryPoint
555                 {
556                         get { return entryPoint; }
557                 }
558
559                 public override AssemblyName[] GetReferencedAssemblies()
560                 {
561                         return Empty<AssemblyName>.Array;
562                 }
563
564                 public override Module[] GetLoadedModules(bool getResourceModules)
565                 {
566                         return GetModules(getResourceModules);
567                 }
568
569                 public override Module[] GetModules(bool getResourceModules)
570                 {
571                         List<Module> list = new List<Module>();
572                         foreach (ModuleBuilder module in modules)
573                         {
574                                 if (getResourceModules || !module.IsResource())
575                                 {
576                                         list.Add(module);
577                                 }
578                         }
579                         foreach (Module module in addedModules)
580                         {
581                                 if (getResourceModules || !module.IsResource())
582                                 {
583                                         list.Add(module);
584                                 }
585                         }
586                         return list.ToArray();
587                 }
588
589                 public override Module GetModule(string name)
590                 {
591                         foreach (ModuleBuilder module in modules)
592                         {
593                                 if (module.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
594                                 {
595                                         return module;
596                                 }
597                         }
598                         foreach (Module module in addedModules)
599                         {
600                                 if (module.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
601                                 {
602                                         return module;
603                                 }
604                         }
605                         return null;
606                 }
607
608                 public Module __AddModule(RawModule module)
609                 {
610                         Module mod = module.ToModule(this);
611                         addedModules.Add(mod);
612                         return mod;
613                 }
614
615                 public override ManifestResourceInfo GetManifestResourceInfo(string resourceName)
616                 {
617                         throw new NotSupportedException();
618                 }
619
620                 public override string[] GetManifestResourceNames()
621                 {
622                         throw new NotSupportedException();
623                 }
624
625                 public override Stream GetManifestResourceStream(string resourceName)
626                 {
627                         throw new NotSupportedException();
628                 }
629
630                 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
631                 {
632                         List<CustomAttributeData> list = new List<CustomAttributeData>();
633                         foreach (CustomAttributeBuilder cab in customAttributes)
634                         {
635                                 if (attributeType == null || attributeType.IsAssignableFrom(cab.Constructor.DeclaringType))
636                                 {
637                                         list.Add(cab.ToData(this));
638                                 }
639                         }
640                         return list;
641                 }
642         }
643
644         sealed class ManifestModule : Module
645         {
646                 private readonly AssemblyBuilder assembly;
647                 private readonly Guid guid = Guid.NewGuid();
648
649                 internal ManifestModule(AssemblyBuilder assembly)
650                         : base(assembly.universe)
651                 {
652                         this.assembly = assembly;
653                 }
654
655                 public override int MDStreamVersion
656                 {
657                         get { return assembly.mdStreamVersion; }
658                 }
659
660                 public override Assembly Assembly
661                 {
662                         get { return assembly; }
663                 }
664
665                 internal override Type FindType(TypeName typeName)
666                 {
667                         return null;
668                 }
669
670                 internal override void  GetTypesImpl(List<Type> list)
671                 {
672                 }
673
674                 public override string FullyQualifiedName
675                 {
676                         get { return Path.Combine(assembly.dir, "RefEmit_InMemoryManifestModule"); }
677                 }
678
679                 public override string Name
680                 {
681                         get { return "<In Memory Module>"; }
682                 }
683
684                 public override Guid ModuleVersionId
685                 {
686                         get { return guid; }
687                 }
688
689                 public override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
690                 {
691                         throw new ArgumentException();
692                 }
693
694                 public override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
695                 {
696                         throw new ArgumentException();
697                 }
698
699                 public override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
700                 {
701                         throw new ArgumentException();
702                 }
703
704                 public override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
705                 {
706                         throw new ArgumentException();
707                 }
708
709                 public override string ResolveString(int metadataToken)
710                 {
711                         throw new ArgumentException();
712                 }
713
714                 public override Type[] __ResolveOptionalParameterTypes(int metadataToken)
715                 {
716                         throw new ArgumentException();
717                 }
718
719                 public override string ScopeName
720                 {
721                         get { return "RefEmit_InMemoryManifestModule"; }
722                 }
723
724                 public override AssemblyName[] __GetReferencedAssemblies()
725                 {
726                         throw new InvalidOperationException();
727                 }
728
729                 internal override Type GetModuleType()
730                 {
731                         throw new InvalidOperationException();
732                 }
733
734                 internal override IKVM.Reflection.Reader.ByteReader GetBlob(int blobIndex)
735                 {
736                         throw new InvalidOperationException();
737                 }
738         }
739 }