2 // System.Reflection/Assembly.cs
5 // Paolo Molaro (lupus@ximian.com)
7 // (C) 2001 Ximian, Inc. http://www.ximian.com
8 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System
.Security
;
31 using System
.Security
.Policy
;
32 using System
.Security
.Permissions
;
33 using System
.Runtime
.Serialization
;
34 using System
.Reflection
;
35 using System
.Reflection
.Emit
;
37 using System
.Globalization
;
38 using System
.Runtime
.CompilerServices
;
39 using System
.Runtime
.InteropServices
;
40 using System
.Collections
;
41 using System
.Collections
.Generic
;
42 using System
.Configuration
.Assemblies
;
46 namespace System
.Reflection
{
48 #pragma warning disable 659 // overrides Equals but not GetHashCode
51 [ComDefaultInterfaceAttribute (typeof (_Assembly
))]
53 [ClassInterface(ClassInterfaceType
.None
)]
55 public partial class Assembly
: ICustomAttributeProvider
, _Assembly
{
57 public abstract class Assembly
: ICustomAttributeProvider
, _Assembly
, IEvidenceFactory
, ISerializable
{
59 public partial class Assembly
: ICustomAttributeProvider
, _Assembly
, IEvidenceFactory
, ISerializable
{
61 internal class ResolveEventHolder
{
62 public event ModuleResolveEventHandler ModuleResolve
;
65 // Note: changes to fields must be reflected in _MonoReflectionAssembly struct (object-internals.h)
66 #pragma warning disable 649
67 private IntPtr _mono_assembly
;
68 #pragma warning restore 649
70 private ResolveEventHolder resolve_event_holder
;
71 private Evidence _evidence
;
72 internal PermissionSet _minimum
; // for SecurityAction.RequestMinimum
73 internal PermissionSet _optional
; // for SecurityAction.RequestOptional
74 internal PermissionSet _refuse
; // for SecurityAction.RequestRefuse
75 private PermissionSet _granted
; // for the resolved assembly granted permissions
76 private PermissionSet _denied
; // for the resolved assembly denied permissions
77 private bool fromByteArray
;
78 private string assemblyName
;
87 resolve_event_holder
= new ResolveEventHolder ();
91 // We can't store the event directly in this class, since the
92 // compiler would silently insert the fields before _mono_assembly
94 public event ModuleResolveEventHandler ModuleResolve
{
95 [SecurityPermission (SecurityAction
.LinkDemand
, ControlAppDomain
= true)]
97 resolve_event_holder
.ModuleResolve
+= value;
99 [SecurityPermission (SecurityAction
.LinkDemand
, ControlAppDomain
= true)]
101 resolve_event_holder
.ModuleResolve
-= value;
105 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
106 private extern string get_code_base (bool escaped
);
108 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
109 private extern string get_fullname ();
111 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
112 private extern string get_location ();
114 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
115 private extern string InternalImageRuntimeVersion ();
117 // SECURITY: this should be the only caller to icall get_code_base
118 private string GetCodeBase (bool escaped
)
120 string cb
= get_code_base (escaped
);
122 if (SecurityManager
.SecurityEnabled
) {
123 // we cannot divulge local file informations
124 if (String
.Compare ("FILE://", 0, cb
, 0, 7, true, CultureInfo
.InvariantCulture
) == 0) {
125 string file
= cb
.Substring (7);
126 new FileIOPermission (FileIOPermissionAccess
.PathDiscovery
, file
).Demand ();
133 public virtual string CodeBase
{
134 get { return GetCodeBase (false); }
137 public virtual string EscapedCodeBase
{
138 get { return GetCodeBase (true); }
141 public virtual string FullName
{
144 // FIXME: This is wrong, but it gets us going
145 // in the compiler for now
151 public virtual extern MethodInfo EntryPoint
{
152 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
156 public virtual Evidence Evidence
{
157 [SecurityPermission (SecurityAction
.Demand
, ControlEvidence
= true)]
158 get { return UnprotectedGetEvidence (); }
161 // note: the security runtime requires evidences but may be unable to do so...
162 internal Evidence
UnprotectedGetEvidence ()
164 // if the host (runtime) hasn't provided it's own evidence...
165 if (_evidence
== null) {
166 // ... we will provide our own
168 _evidence
= Evidence
.GetDefaultHostEvidence (this);
174 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
175 internal extern bool get_global_assembly_cache ();
178 internal bool FromByteArray
{
179 set { fromByteArray = value; }
182 public virtual String Location
{
187 string loc
= get_location ();
189 if ((loc
!= String
.Empty
) && SecurityManager
.SecurityEnabled
) {
190 // we cannot divulge local file informations
191 new FileIOPermission (FileIOPermissionAccess
.PathDiscovery
, loc
).Demand ();
199 public virtual string ImageRuntimeVersion
{
201 return InternalImageRuntimeVersion ();
205 [SecurityPermission (SecurityAction
.LinkDemand
, SerializationFormatter
= true)]
206 public virtual void GetObjectData (SerializationInfo info
, StreamingContext context
)
209 throw new ArgumentNullException ("info");
211 UnitySerializationHolder
.GetAssemblyData (this, info
, context
);
214 public virtual bool IsDefined (Type attributeType
, bool inherit
)
216 return MonoCustomAttrs
.IsDefined (this, attributeType
, inherit
);
219 public virtual object [] GetCustomAttributes (bool inherit
)
221 return MonoCustomAttrs
.GetCustomAttributes (this, inherit
);
224 public virtual object [] GetCustomAttributes (Type attributeType
, bool inherit
)
226 return MonoCustomAttrs
.GetCustomAttributes (this, attributeType
, inherit
);
229 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
230 private extern object GetFilesInternal (String name
, bool getResourceModules
);
232 public virtual FileStream
[] GetFiles ()
234 return GetFiles (false);
237 public virtual FileStream
[] GetFiles (bool getResourceModules
)
239 string[] names
= (string[]) GetFilesInternal (null, getResourceModules
);
241 return new FileStream
[0];
243 string location
= Location
;
246 if (location
!= String
.Empty
) {
247 res
= new FileStream
[names
.Length
+ 1];
248 res
[0] = new FileStream (location
, FileMode
.Open
, FileAccess
.Read
);
249 for (int i
= 0; i
< names
.Length
; ++i
)
250 res
[i
+ 1] = new FileStream (names
[i
], FileMode
.Open
, FileAccess
.Read
);
252 res
= new FileStream
[names
.Length
];
253 for (int i
= 0; i
< names
.Length
; ++i
)
254 res
[i
] = new FileStream (names
[i
], FileMode
.Open
, FileAccess
.Read
);
259 public virtual FileStream
GetFile (String name
)
262 throw new ArgumentNullException (null, "Name cannot be null.");
263 if (name
.Length
== 0)
264 throw new ArgumentException ("Empty name is not valid");
266 string filename
= (string)GetFilesInternal (name
, true);
267 if (filename
!= null)
268 return new FileStream (filename
, FileMode
.Open
, FileAccess
.Read
);
273 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
274 internal extern IntPtr
GetManifestResourceInternal (String name
, out int size
, out Module module
);
276 public virtual Stream
GetManifestResourceStream (String name
)
279 throw new ArgumentNullException ("name");
280 if (name
.Length
== 0)
281 throw new ArgumentException ("String cannot have zero length.",
284 ManifestResourceInfo info
= GetManifestResourceInfo (name
);
288 if (info
.ReferencedAssembly
!= null)
289 return info
.ReferencedAssembly
.GetManifestResourceStream (name
);
290 if ((info
.FileName
!= null) && (info
.ResourceLocation
== 0)) {
292 throw new FileNotFoundException (info
.FileName
);
294 string location
= Path
.GetDirectoryName (Location
);
295 string filename
= Path
.Combine (location
, info
.FileName
);
297 // we don't control the content of 'info.FileName' so we want to make sure we keep to ourselves
298 filename
= Path
.GetFullPath (filename
);
299 if (!filename
.StartsWith (location
))
300 throw new SecurityException ("non-rooted access to manifest resource");
302 return new FileStream (filename
, FileMode
.Open
, FileAccess
.Read
);
307 IntPtr data
= GetManifestResourceInternal (name
, out size
, out module
);
308 if (data
== (IntPtr
) 0)
311 UnmanagedMemoryStream stream
;
313 stream
= new UnmanagedMemoryStream ((byte*) data
, size
);
316 * The returned pointer points inside metadata, so
317 * we have to increase the refcount of the module, and decrease
318 * it when the stream is finalized.
320 stream
.Closed
+= new EventHandler (new ResourceCloseHandler (module
).OnClose
);
325 public virtual Stream
GetManifestResourceStream (Type type
, String name
)
332 throw new ArgumentNullException ("type");
336 if (ns
== null || ns
.Length
== 0)
337 return GetManifestResourceStream (name
);
339 return GetManifestResourceStream (ns
+ "." + name
);
342 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
343 internal virtual extern Type
[] GetTypes (bool exportedOnly
);
345 public virtual Type
[] GetTypes ()
347 return GetTypes (false);
350 public virtual Type
[] GetExportedTypes ()
352 return GetTypes (true);
355 public virtual Type
GetType (String name
, Boolean throwOnError
)
357 return GetType (name
, throwOnError
, false);
360 public virtual Type
GetType (String name
) {
361 return GetType (name
, false, false);
364 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
365 internal extern Type
InternalGetType (Module module
, String name
, Boolean throwOnError
, Boolean ignoreCase
);
367 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
368 internal extern static void InternalGetAssemblyName (string assemblyFile
, AssemblyName aname
);
370 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
371 static extern void FillName (Assembly ass
, AssemblyName aname
);
373 [MonoTODO ("copiedName == true is not supported")]
374 public virtual AssemblyName
GetName (Boolean copiedName
)
376 // CodeBase, which is restricted, will be copied into the AssemblyName object so...
377 if (SecurityManager
.SecurityEnabled
) {
378 GetCodeBase (true); // this will ensure the Demand is made
380 return UnprotectedGetName ();
383 public virtual AssemblyName
GetName ()
385 return GetName (false);
388 // the security runtime requires access to the assemblyname (e.g. to get the strongname)
389 internal virtual AssemblyName
UnprotectedGetName ()
391 AssemblyName aname
= new AssemblyName ();
392 FillName (this, aname
);
396 public override string ToString ()
398 // note: ToString work without requiring CodeBase (so no checks are needed)
400 if (assemblyName
!= null)
403 assemblyName
= get_fullname ();
407 public static String
CreateQualifiedName (String assemblyName
, String typeName
)
409 return typeName
+ ", " + assemblyName
;
412 public static Assembly
GetAssembly (Type type
)
415 return type
.Assembly
;
416 throw new ArgumentNullException ("type");
420 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
421 public static extern Assembly
GetEntryAssembly();
423 internal Assembly
GetSatelliteAssemblyNoThrow (CultureInfo culture
, Version version
)
425 return GetSatelliteAssembly (culture
, version
, false);
428 internal Assembly
GetSatelliteAssembly (CultureInfo culture
, Version version
, bool throwOnError
)
431 throw new ArgumentException ("culture");
433 AssemblyName aname
= GetName (true);
435 aname
.Version
= version
;
437 aname
.CultureInfo
= culture
;
438 aname
.Name
= aname
.Name
+ ".resources";
442 assembly
= AppDomain
.CurrentDomain
.LoadSatellite (aname
, false);
443 if (assembly
!= null)
445 } catch (FileNotFoundException
) {
450 // Try the assembly directory
451 string location
= Path
.GetDirectoryName (Location
);
452 string fullName
= Path
.Combine (location
, Path
.Combine (culture
.Name
, aname
.Name
+ ".dll"));
454 // it's unlikely that culture.Name or aname.Name could contain stuff like ".." but...
455 fullName
= Path
.GetFullPath (fullName
);
456 if (!fullName
.StartsWith (location
)) {
458 throw new SecurityException ("non-rooted access to satellite assembly");
462 if (!throwOnError
&& !File
.Exists (fullName
))
465 return LoadFrom (fullName
);
468 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
469 private extern static Assembly
LoadFrom (String assemblyFile
, bool refonly
);
471 public static Assembly
LoadFrom (String assemblyFile
)
473 return LoadFrom (assemblyFile
, false);
479 public static Assembly
LoadFrom (String assemblyFile
, Evidence securityEvidence
)
481 Assembly a
= LoadFrom (assemblyFile
, false);
483 if ((a
!= null) && (securityEvidence
!= null)) {
484 // merge evidence (i.e. replace defaults with provided evidences)
485 a
.Evidence
.Merge (securityEvidence
);
494 [MonoTODO("This overload is not currently implemented")]
495 // FIXME: What are we missing?
496 public static Assembly
LoadFrom (String assemblyFile
, Evidence securityEvidence
, byte[] hashValue
, AssemblyHashAlgorithm hashAlgorithm
)
498 throw new NotImplementedException ();
503 public static Assembly
LoadFrom (String assemblyFile
, byte [] hashValue
, AssemblyHashAlgorithm hashAlgorithm
)
505 throw new NotImplementedException ();
512 public static Assembly
LoadFile (String path
, Evidence securityEvidence
)
515 throw new ArgumentNullException ("path");
516 if (path
== String
.Empty
)
517 throw new ArgumentException ("Path can't be empty", "path");
518 // FIXME: Make this do the right thing
519 return LoadFrom (path
, securityEvidence
);
522 public static Assembly
LoadFile (String path
)
524 return LoadFile (path
, null);
527 public static Assembly
Load (String assemblyString
)
529 return AppDomain
.CurrentDomain
.Load (assemblyString
);
535 public static Assembly
Load (String assemblyString
, Evidence assemblySecurity
)
537 return AppDomain
.CurrentDomain
.Load (assemblyString
, assemblySecurity
);
540 public static Assembly
Load (AssemblyName assemblyRef
)
542 return AppDomain
.CurrentDomain
.Load (assemblyRef
);
548 public static Assembly
Load (AssemblyName assemblyRef
, Evidence assemblySecurity
)
550 return AppDomain
.CurrentDomain
.Load (assemblyRef
, assemblySecurity
);
553 public static Assembly
Load (Byte
[] rawAssembly
)
555 return AppDomain
.CurrentDomain
.Load (rawAssembly
);
558 public static Assembly
Load (Byte
[] rawAssembly
, Byte
[] rawSymbolStore
)
560 return AppDomain
.CurrentDomain
.Load (rawAssembly
, rawSymbolStore
);
566 public static Assembly
Load (Byte
[] rawAssembly
, Byte
[] rawSymbolStore
,
567 Evidence securityEvidence
)
569 return AppDomain
.CurrentDomain
.Load (rawAssembly
, rawSymbolStore
, securityEvidence
);
573 [MonoLimitation ("Argument securityContextSource is ignored")]
574 public static Assembly
Load (byte [] rawAssembly
, byte [] rawSymbolStore
, SecurityContextSource securityContextSource
)
576 return AppDomain
.CurrentDomain
.Load (rawAssembly
, rawSymbolStore
);
580 public static Assembly
ReflectionOnlyLoad (byte[] rawAssembly
)
582 return AppDomain
.CurrentDomain
.Load (rawAssembly
, null, null, true);
585 public static Assembly
ReflectionOnlyLoad (string assemblyString
)
587 return AppDomain
.CurrentDomain
.Load (assemblyString
, null, true);
590 public static Assembly
ReflectionOnlyLoadFrom (string assemblyFile
)
592 if (assemblyFile
== null)
593 throw new ArgumentNullException ("assemblyFile");
595 return LoadFrom (assemblyFile
, true);
601 public static Assembly
LoadWithPartialName (string partialName
)
603 return LoadWithPartialName (partialName
, null);
606 [MonoTODO ("Not implemented")]
607 public Module
LoadModule (string moduleName
, byte [] rawModule
)
609 throw new NotImplementedException ();
612 [MonoTODO ("Not implemented")]
617 Module
LoadModule (string moduleName
, byte [] rawModule
, byte [] rawSymbolStore
)
619 throw new NotImplementedException ();
622 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
623 private static extern Assembly
load_with_partial_name (string name
, Evidence e
);
628 public static Assembly
LoadWithPartialName (string partialName
, Evidence securityEvidence
)
630 return LoadWithPartialName (partialName
, securityEvidence
, true);
634 * LAMESPEC: It is possible for this method to throw exceptions IF the name supplied
635 * is a valid gac name and contains filesystem entry charachters at the end of the name
636 * ie System/// will throw an exception. However ////System will not as that is canocolized
640 // FIXME: LoadWithPartialName must look cache (no CAS) or read from disk (CAS)
641 internal static Assembly
LoadWithPartialName (string partialName
, Evidence securityEvidence
, bool oldBehavior
)
644 throw new NotImplementedException ();
646 if (partialName
== null)
647 throw new NullReferenceException ();
649 return load_with_partial_name (partialName
, securityEvidence
);
652 public Object
CreateInstance (String typeName
)
654 return CreateInstance (typeName
, false);
657 public Object
CreateInstance (String typeName
, Boolean ignoreCase
)
659 Type t
= GetType (typeName
, false, ignoreCase
);
664 return Activator
.CreateInstance (t
);
665 } catch (InvalidOperationException
) {
666 throw new ArgumentException ("It is illegal to invoke a method on a Type loaded via ReflectionOnly methods.");
674 Object
CreateInstance (String typeName
, Boolean ignoreCase
,
675 BindingFlags bindingAttr
, Binder binder
,
676 Object
[] args
, CultureInfo culture
,
677 Object
[] activationAttributes
)
679 Type t
= GetType (typeName
, false, ignoreCase
);
684 return Activator
.CreateInstance (t
, bindingAttr
, binder
, args
, culture
, activationAttributes
);
685 } catch (InvalidOperationException
) {
686 throw new ArgumentException ("It is illegal to invoke a method on a Type loaded via ReflectionOnly methods.");
690 public Module
[] GetLoadedModules ()
692 return GetLoadedModules (false);
695 public Module
[] GetModules ()
697 return GetModules (false);
700 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
701 internal virtual extern Module
[] GetModulesInternal ();
704 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
705 internal extern string[] GetNamespaces ();
707 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
708 public extern virtual String
[] GetManifestResourceNames ();
710 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
711 public extern static Assembly
GetExecutingAssembly ();
713 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
714 public extern static Assembly
GetCallingAssembly ();
716 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
717 internal static extern AssemblyName
[] GetReferencedAssemblies (Assembly module
);
719 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
720 private extern bool GetManifestResourceInfoInternal (String name
, ManifestResourceInfo info
);
722 public virtual ManifestResourceInfo
GetManifestResourceInfo (String resourceName
)
724 if (resourceName
== null)
725 throw new ArgumentNullException ("resourceName");
726 if (resourceName
.Length
== 0)
727 throw new ArgumentException ("String cannot have zero length.");
728 ManifestResourceInfo result
= new ManifestResourceInfo ();
729 bool found
= GetManifestResourceInfoInternal (resourceName
, result
);
736 private class ResourceCloseHandler
{
737 #pragma warning disable 169, 414
739 #pragma warning restore 169, 414
741 public ResourceCloseHandler (Module module
) {
742 this.module
= module
;
745 public void OnClose (object sender
, EventArgs e
) {
746 // The module dtor will take care of things
752 // The following functions are only for the Mono Debugger.
755 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
756 internal static extern int MonoDebugger_GetMethodToken (MethodBase method
);
758 [MonoTODO ("Currently it always returns zero")]
769 internal virtual Module
GetManifestModule () {
770 return GetManifestModuleInternal ();
773 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
774 internal extern Module
GetManifestModuleInternal ();
777 public virtual extern bool ReflectionOnly
{
778 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
782 public override bool Equals (object o
)
784 if (((object) this) == o
)
790 Assembly other
= (Assembly
) o
;
791 return other
._mono_assembly
== _mono_assembly
;
795 public virtual IList
<CustomAttributeData
> GetCustomAttributesData () {
796 return CustomAttributeData
.GetCustomAttributes (this);
801 // Code Access Security
803 internal void Resolve ()
806 // FIXME: As we (currently) delay the resolution until the first CAS
807 // Demand it's too late to evaluate the Minimum permission set as a
808 // condition to load the assembly into the AppDomain
809 LoadAssemblyPermissions ();
810 Evidence e
= new Evidence (UnprotectedGetEvidence ()); // we need a copy to add PRE
811 e
.AddHost (new PermissionRequestEvidence (_minimum
, _optional
, _refuse
));
812 _granted
= SecurityManager
.ResolvePolicy (e
,
813 _minimum
, _optional
, _refuse
, out _denied
);
817 internal PermissionSet GrantedPermissionSet
{
819 if (_granted
== null) {
820 if (SecurityManager
.ResolvingPolicyLevel
!= null) {
821 if (SecurityManager
.ResolvingPolicyLevel
.IsFullTrustAssembly (this))
822 return DefaultPolicies
.FullTrust
;
824 return null; // we can't resolve during resolution
832 internal PermissionSet DeniedPermissionSet
{
834 // yes we look for granted, as denied may be null
835 if (_granted
== null) {
836 if (SecurityManager
.ResolvingPolicyLevel
!= null) {
837 if (SecurityManager
.ResolvingPolicyLevel
.IsFullTrustAssembly (this))
840 return DefaultPolicies
.FullTrust
; // deny unrestricted
848 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
849 extern internal static bool LoadPermissions (Assembly a
,
850 ref IntPtr minimum
, ref int minLength
,
851 ref IntPtr optional
, ref int optLength
,
852 ref IntPtr refused
, ref int refLength
);
854 // Support for SecurityAction.RequestMinimum, RequestOptional and RequestRefuse
855 private void LoadAssemblyPermissions ()
857 IntPtr minimum
= IntPtr
.Zero
, optional
= IntPtr
.Zero
, refused
= IntPtr
.Zero
;
858 int minLength
= 0, optLength
= 0, refLength
= 0;
859 if (LoadPermissions (this, ref minimum
, ref minLength
, ref optional
,
860 ref optLength
, ref refused
, ref refLength
)) {
862 // Note: no need to cache these permission sets as they will only be created once
863 // at assembly resolution time.
865 byte[] data
= new byte [minLength
];
866 Marshal
.Copy (minimum
, data
, 0, minLength
);
867 _minimum
= SecurityManager
.Decode (data
);
870 byte[] data
= new byte [optLength
];
871 Marshal
.Copy (optional
, data
, 0, optLength
);
872 _optional
= SecurityManager
.Decode (data
);
875 byte[] data
= new byte [refLength
];
876 Marshal
.Copy (refused
, data
, 0, refLength
);
877 _refuse
= SecurityManager
.Decode (data
);
884 static Exception
CreateNIE ()
886 return new NotImplementedException ("Derived classes must implement it");
889 public virtual Type
GetType (string name
, bool throwOnError
, bool ignoreCase
)
894 public virtual Module
GetModule (String name
)
899 public virtual AssemblyName
[] GetReferencedAssemblies ()
904 public virtual Module
[] GetModules (bool getResourceModules
)
909 [MonoTODO ("Always returns the same as GetModules")]
910 public virtual Module
[] GetLoadedModules (bool getResourceModules
)
915 public virtual Assembly
GetSatelliteAssembly (CultureInfo culture
)
920 public virtual Assembly
GetSatelliteAssembly (CultureInfo culture
, Version version
)
925 public virtual Module ManifestModule
{
926 get { throw CreateNIE (); }
929 public virtual bool GlobalAssemblyCache
{
930 get { throw CreateNIE (); }
933 public virtual bool IsDynamic
{
934 get { return false; }
937 public override int GetHashCode ()
939 return base.GetHashCode ();
942 public static bool operator == (Assembly left
, Assembly right
)
944 if ((object)left
== (object)right
)
946 if ((object)left
== null ^
(object)right
== null)
948 return left
.Equals (right
);
951 public static bool operator != (Assembly left
, Assembly right
)
953 if ((object)left
== (object)right
)
955 if ((object)left
== null ^
(object)right
== null)
957 return !left
.Equals (right
);
963 #pragma warning restore 659