diff options
Diffstat (limited to 'src/mscorlib/src/System/Reflection/Assembly.cs')
-rw-r--r-- | src/mscorlib/src/System/Reflection/Assembly.cs | 1048 |
1 files changed, 78 insertions, 970 deletions
diff --git a/src/mscorlib/src/System/Reflection/Assembly.cs b/src/mscorlib/src/System/Reflection/Assembly.cs index 479d6ca3a6..677e4aa964 100644 --- a/src/mscorlib/src/System/Reflection/Assembly.cs +++ b/src/mscorlib/src/System/Reflection/Assembly.cs @@ -37,7 +37,7 @@ namespace System.Reflection using __HResults = System.__HResults; using System.Runtime.Versioning; using System.Diagnostics.Contracts; - + using System.Runtime.Loader; [Serializable] [System.Runtime.InteropServices.ComVisible(true)] @@ -48,14 +48,9 @@ namespace System.Reflection [ClassInterface(ClassInterfaceType.None)] [ComDefaultInterface(typeof(_Assembly))] [System.Runtime.InteropServices.ComVisible(true)] -#pragma warning disable 618 - [PermissionSetAttribute(SecurityAction.InheritanceDemand, Unrestricted = true)] -#pragma warning restore 618 public abstract class Assembly : _Assembly, IEvidenceFactory, ICustomAttributeProvider, ISerializable { -#region constructors protected Assembly() {} -#endregion #region public static methods @@ -67,7 +62,7 @@ namespace System.Reflection public static Assembly GetAssembly(Type type) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); Module m = type.Module; @@ -105,36 +100,15 @@ namespace System.Reflection return base.GetHashCode(); } - // Locate an assembly by the name of the file containing the manifest. -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#else - [System.Security.SecuritySafeCritical] -#endif - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly LoadFrom(String assemblyFile) { - Contract.Ensures(Contract.Result<Assembly>() != null); - Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly); - -#if FEATURE_WINDOWSPHONE - throw new NotSupportedException(Environment.GetResourceString("NotSupported_WindowsPhone", "Assembly.LoadFrom")); -#else - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - - return RuntimeAssembly.InternalLoadFrom( - assemblyFile, - null, // securityEvidence - null, // hashValue - AssemblyHashAlgorithm.None, - false,// forIntrospection - false,// suppressSecurityChecks - ref stackMark); -#endif // FEATURE_WINDOWSPHONE + if(assemblyFile == null) + throw new ArgumentNullException(nameof(assemblyFile)); + string fullPath = Path.GetFullPath(assemblyFile); + return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath); } // Locate an assembly for reflection by the name of the file containing the manifest. - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly ReflectionOnlyLoadFrom(String assemblyFile) { @@ -153,7 +127,6 @@ namespace System.Reflection } // Evidence is protected in Assembly.Load() - [System.Security.SecuritySafeCritical] // auto-generated [Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of LoadFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly LoadFrom(String assemblyFile, @@ -174,7 +147,6 @@ namespace System.Reflection } // Evidence is protected in Assembly.Load() - [System.Security.SecuritySafeCritical] // auto-generated [Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of LoadFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")] [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly LoadFrom(String assemblyFile, @@ -196,49 +168,21 @@ namespace System.Reflection ref stackMark); } - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly LoadFrom(String assemblyFile, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - - return RuntimeAssembly.InternalLoadFrom( - assemblyFile, - null, - hashValue, - hashAlgorithm, - false, - false, - ref stackMark); + throw new NotSupportedException(Environment.GetResourceString("NotSupported_AssemblyLoadFromHash")); } -#if FEATURE_CAS_POLICY - // Load an assembly into the LoadFrom context bypassing some security checks - [SecurityCritical] - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly UnsafeLoadFrom(string assemblyFile) { - - Contract.Ensures(Contract.Result<Assembly>() != null); - Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly); - - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - - return RuntimeAssembly.InternalLoadFrom(assemblyFile, - null, // securityEvidence - null, // hashValue - AssemblyHashAlgorithm.None, - false, // forIntrospection - true, // suppressSecurityChecks - ref stackMark); + return LoadFrom(assemblyFile); } -#endif // FEATURE_CAS_POLICY // Locate an assembly by the long form of the assembly name. // eg. "Toolbox.dll, version=1.1.10.1220, locale=en, publickey=1234567890123456789012345678901234567890" - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly Load(String assemblyString) { @@ -253,7 +197,6 @@ namespace System.Reflection // Calls Type.GetType for WinRT types. // Note: Type.GetType fails for assembly names that start with weird characters like '['. By calling it for managed types we would // break AppCompat. - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable internal static Type GetType_Compat(String assemblyString, String typeName) { @@ -283,7 +226,6 @@ namespace System.Reflection // Locate an assembly for reflection by the long form of the assembly name. // eg. "Toolbox.dll, version=1.1.10.1220, locale=en, publickey=1234567890123456789012345678901234567890" // - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly ReflectionOnlyLoad(String assemblyString) { @@ -293,7 +235,6 @@ namespace System.Reflection return RuntimeAssembly.InternalLoad(assemblyString, null, ref stackMark, true /*forIntrospection*/); } - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable [Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")] public static Assembly Load(String assemblyString, Evidence assemblySecurity) @@ -307,11 +248,6 @@ namespace System.Reflection // Locate an assembly by its name. The name can be strong or // weak. The assembly is loaded into the domain of the caller. -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#else - [System.Security.SecuritySafeCritical] -#endif [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly Load(AssemblyName assemblyRef) { @@ -331,11 +267,6 @@ namespace System.Reflection // Locate an assembly by its name. The name can be strong or // weak. The assembly is loaded into the domain of the caller. -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#else - [System.Security.SecuritySafeCritical] -#endif [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable internal static Assembly Load(AssemblyName assemblyRef, IntPtr ptrLoadContextBinder) { @@ -353,7 +284,6 @@ namespace System.Reflection return RuntimeAssembly.InternalLoadAssemblyName(assemblyRef, null, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/, false /*suppressSecurityChecks*/, ptrLoadContextBinder); } - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable [Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")] public static Assembly Load(AssemblyName assemblyRef, Evidence assemblySecurity) @@ -365,34 +295,17 @@ namespace System.Reflection return RuntimeAssembly.InternalLoadAssemblyName(assemblyRef, assemblySecurity, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/, false /*suppressSecurityChecks*/); } -#if FEATURE_FUSION - [System.Security.SecuritySafeCritical] // auto-generated [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")] - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly LoadWithPartialName(String partialName) { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return RuntimeAssembly.LoadWithPartialNameInternal(partialName, null, ref stackMark); - } - - [System.Security.SecuritySafeCritical] // auto-generated - [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")] - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable - public static Assembly LoadWithPartialName(String partialName, Evidence securityEvidence) - { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return RuntimeAssembly.LoadWithPartialNameInternal(partialName, securityEvidence, ref stackMark); + if(partialName == null) + throw new ArgumentNullException(nameof(partialName)); + return Load(partialName); } -#endif // FEATURE_FUSION // Loads the assembly with a COFF based IMAGE containing // an emitted assembly. The assembly is loaded into the domain // of the caller. -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#else - [System.Security.SecuritySafeCritical] -#endif [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly Load(byte[] rawAssembly) { @@ -401,20 +314,12 @@ namespace System.Reflection AppDomain.CheckLoadByteArraySupported(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return RuntimeAssembly.nLoadImage( - rawAssembly, - null, // symbol store - null, // evidence - ref stackMark, - false, // fIntrospection - SecurityContextSource.CurrentAssembly); + return Load(rawAssembly, null); } // Loads the assembly for reflection with a COFF based IMAGE containing // an emitted assembly. The assembly is loaded into the domain // of the caller. - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly ReflectionOnlyLoad(byte[] rawAssembly) { @@ -436,40 +341,30 @@ namespace System.Reflection // an emitted assembly. The assembly is loaded into the domain // of the caller. The second parameter is the raw bytes // representing the symbol store that matches the assembly. -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#else - [System.Security.SecuritySafeCritical] -#endif [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore) { - Contract.Ensures(Contract.Result<Assembly>() != null); Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly); AppDomain.CheckLoadByteArraySupported(); - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return RuntimeAssembly.nLoadImage( - rawAssembly, - rawSymbolStore, - null, // evidence - ref stackMark, - false, // fIntrospection - SecurityContextSource.CurrentAssembly); + if(rawAssembly == null) + throw new ArgumentNullException(nameof(rawAssembly)); + AssemblyLoadContext alc = new IndividualAssemblyLoadContext(); + MemoryStream assemblyStream = new MemoryStream(rawAssembly); + MemoryStream symbolStream = (rawSymbolStore!=null)?new MemoryStream(rawSymbolStore):null; + return alc.LoadFromStream(assemblyStream, symbolStream); } // Load an assembly from a byte array, controlling where the grant set of this assembly is // propigated from. - [SecuritySafeCritical] [MethodImpl(MethodImplOptions.NoInlining)] // Due to the stack crawl mark public static Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore, SecurityContextSource securityContextSource) { - Contract.Ensures(Contract.Result<Assembly>() != null); Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly); @@ -478,7 +373,7 @@ namespace System.Reflection if (securityContextSource < SecurityContextSource.CurrentAppDomain || securityContextSource > SecurityContextSource.CurrentAssembly) { - throw new ArgumentOutOfRangeException("securityContextSource"); + throw new ArgumentOutOfRangeException(nameof(securityContextSource)); } StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -490,79 +385,37 @@ namespace System.Reflection securityContextSource); } -#if FEATURE_CAS_POLICY - [System.Security.SecuritySafeCritical] // auto-generated - [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlEvidence)] - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable - [Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")] - public static Assembly Load(byte[] rawAssembly, - byte[] rawSymbolStore, - Evidence securityEvidence) - { - - Contract.Ensures(Contract.Result<Assembly>() != null); - Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly); - - AppDomain.CheckLoadByteArraySupported(); + private static Dictionary<string, Assembly> s_loadfile = new Dictionary<string, Assembly>(); - if (securityEvidence != null && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) - { - // A zone of MyComputer could not have been used to sandbox, so for compatibility we do not - // throw an exception when we see it. - Zone zone = securityEvidence.GetHostEvidence<Zone>(); - if (zone == null || zone.SecurityZone != SecurityZone.MyComputer) - { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); - } - } - - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - return RuntimeAssembly.nLoadImage( - rawAssembly, - rawSymbolStore, - securityEvidence, - ref stackMark, - false, // fIntrospection - SecurityContextSource.CurrentAssembly); - } -#endif // FEATURE_CAS_POLICY - - [System.Security.SecuritySafeCritical] // auto-generated public static Assembly LoadFile(String path) { - Contract.Ensures(Contract.Result<Assembly>() != null); Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly); AppDomain.CheckLoadFileSupported(); - new FileIOPermission(FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read, path).Demand(); - return RuntimeAssembly.nLoadFile(path, null); - } - -#if FEATURE_CAS_POLICY - [System.Security.SecuritySafeCritical] // auto-generated - [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlEvidence)] - [Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of LoadFile which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")] - public static Assembly LoadFile(String path, - Evidence securityEvidence) - { - - Contract.Ensures(Contract.Result<Assembly>() != null); - Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly); + Assembly result = null; + if(path == null) + throw new ArgumentNullException(nameof(path)); - AppDomain.CheckLoadFileSupported(); + if (PathInternal.IsPartiallyQualified(path)) + { + throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), nameof(path)); + } - if (securityEvidence != null && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) - throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); + string normalizedPath = Path.GetFullPath(path); - new FileIOPermission(FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read, path).Demand(); - return RuntimeAssembly.nLoadFile(path, securityEvidence); + lock(s_loadfile) + { + if(s_loadfile.TryGetValue(normalizedPath, out result)) + return result; + AssemblyLoadContext alc = new IndividualAssemblyLoadContext(); + result = alc.LoadFromAssemblyPath(normalizedPath); + s_loadfile.Add(normalizedPath, result); + } + return result; } -#endif // FEATURE_CAS_POLICY -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly Load(Stream assemblyStream, Stream pdbStream) { @@ -572,8 +425,6 @@ namespace System.Reflection StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RuntimeAssembly.InternalLoadFromStream(assemblyStream, pdbStream, ref stackMark); } - - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly Load(Stream assemblyStream) { @@ -583,12 +434,10 @@ namespace System.Reflection StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RuntimeAssembly.InternalLoadFromStream(assemblyStream, null, ref stackMark); } -#endif //FEATURE_CORECLR /* * Get the assembly that the current code is running from. */ - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly GetExecutingAssembly() { @@ -596,7 +445,6 @@ namespace System.Reflection return RuntimeAssembly.GetExecutingAssembly(ref stackMark); } - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly GetCallingAssembly() { @@ -607,25 +455,22 @@ namespace System.Reflection return RuntimeAssembly.GetExecutingAssembly(ref stackMark); } - [System.Security.SecuritySafeCritical] // auto-generated public static Assembly GetEntryAssembly() { AppDomainManager domainManager = AppDomain.CurrentDomain.DomainManager; if (domainManager == null) domainManager = new AppDomainManager(); return domainManager.EntryAssembly; } - + #endregion // public static methods #region public methods public virtual event ModuleResolveEventHandler ModuleResolve { - [System.Security.SecurityCritical] // auto-generated_required add { throw new NotImplementedException(); } - [System.Security.SecurityCritical] // auto-generated_required remove { throw new NotImplementedException(); @@ -634,9 +479,6 @@ namespace System.Reflection public virtual String CodeBase { -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#endif get { throw new NotImplementedException(); @@ -645,24 +487,17 @@ namespace System.Reflection public virtual String EscapedCodeBase { - [System.Security.SecuritySafeCritical] // auto-generated get { return AssemblyName.EscapeCodeBase(CodeBase); } } -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#endif public virtual AssemblyName GetName() { return GetName(false); } -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#endif public virtual AssemblyName GetName(bool copiedName) { throw new NotImplementedException(); @@ -684,13 +519,6 @@ namespace System.Reflection } } -#if !FEATURE_CORECLR - Type _Assembly.GetType() - { - return base.GetType(); - } -#endif - public virtual Type GetType(String name) { return GetType(name, false, false); @@ -789,31 +617,11 @@ namespace System.Reflection throw new NotImplementedException(); } -#if FEATURE_CAS_POLICY - public virtual Evidence Evidence - { - get - { - throw new NotImplementedException(); - } - } - - public virtual PermissionSet PermissionSet - { - // SecurityCritical because permissions can contain sensitive information such as paths - [SecurityCritical] - get - { - throw new NotImplementedException(); - } - } - public bool IsFullyTrusted { - [SecuritySafeCritical] get { - return PermissionSet.IsUnrestricted(); + return true; } } @@ -821,14 +629,11 @@ namespace System.Reflection { get { - throw new NotImplementedException(); + return SecurityRuleSet.None; } } -#endif // FEATURE_CAS_POLICY - // ISerializable implementation - [System.Security.SecurityCritical] // auto-generated_required public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { throw new NotImplementedException(); @@ -890,8 +695,6 @@ namespace System.Reflection } } -#if FEATURE_MULTIMODULE_ASSEMBLIES - public Module LoadModule(String moduleName, byte[] rawModule) { @@ -904,7 +707,6 @@ namespace System.Reflection { throw new NotImplementedException(); } -#endif //FEATURE_MULTIMODULE_ASSEMBLIES // // Locates a type from this assembly and creates an instance of it using @@ -986,9 +788,6 @@ namespace System.Reflection // Returns the file in the File table of the manifest that matches the // given name. (Name should not include path.) -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#endif public virtual FileStream GetFile(String name) { throw new NotImplementedException(); @@ -999,9 +798,6 @@ namespace System.Reflection return GetFiles(false); } -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#endif public virtual FileStream[] GetFiles(bool getResourceModules) { throw new NotImplementedException(); @@ -1034,9 +830,6 @@ namespace System.Reflection public virtual String Location { -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#endif get { throw new NotImplementedException(); @@ -1103,27 +896,7 @@ namespace System.Reflection [Serializable] internal class RuntimeAssembly : Assembly -#if !FEATURE_CORECLR - , ICustomQueryInterface -#endif { -#if !FEATURE_CORECLR -#region ICustomQueryInterface - [System.Security.SecurityCritical] - CustomQueryInterfaceResult ICustomQueryInterface.GetInterface([In]ref Guid iid, out IntPtr ppv) - { - if (iid == typeof(NativeMethods.IDispatch).GUID) - { - ppv = Marshal.GetComInterfaceForObject(this, typeof(_Assembly)); - return CustomQueryInterfaceResult.Handled; - } - - ppv = IntPtr.Zero; - return CustomQueryInterfaceResult.NotHandled; - } -#endregion -#endif // !FEATURE_CORECLR - #if FEATURE_APPX // The highest byte is the flags and the lowest 3 bytes are // the cached ctor token of [DynamicallyInvocableAttribute]. @@ -1166,54 +939,12 @@ namespace System.Reflection private ASSEMBLY_FLAGS Flags { - [SecuritySafeCritical] get { if ((m_flags & ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_INITIALIZED) == 0) { - ASSEMBLY_FLAGS flags = ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_UNKNOWN; - -#if FEATURE_CORECLR - flags |= ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_FRAMEWORK | ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_SAFE_REFLECTION; -#else - if (RuntimeAssembly.IsFrameworkAssembly(GetName())) - { - flags |= ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_FRAMEWORK | ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_SAFE_REFLECTION; - - foreach (string name in s_unsafeFrameworkAssemblyNames) - { - if (String.Compare(GetSimpleName(), name, StringComparison.OrdinalIgnoreCase) == 0) - { - flags &= ~ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_SAFE_REFLECTION; - break; - } - } - - // Each blessed API will be annotated with a "__DynamicallyInvokableAttribute". - // This "__DynamicallyInvokableAttribute" is a type defined in its own assembly. - // So the ctor is always a MethodDef and the type a TypeDef. - // We cache this ctor MethodDef token for faster custom attribute lookup. - // If this attribute type doesn't exist in the assembly, it means the assembly - // doesn't contain any blessed APIs. - Type invocableAttribute = GetType("__DynamicallyInvokableAttribute", false); - if (invocableAttribute != null) - { - Contract.Assert(((MetadataToken)invocableAttribute.MetadataToken).IsTypeDef); - - ConstructorInfo ctor = invocableAttribute.GetConstructor(Type.EmptyTypes); - Contract.Assert(ctor != null); - - int token = ctor.MetadataToken; - Contract.Assert(((MetadataToken)token).IsMethodDef); - - flags |= (ASSEMBLY_FLAGS)token & ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_TOKEN_MASK; - } - } - else if (IsDesignerBindingContext()) - { - flags = ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_SAFE_REFLECTION; - } -#endif + ASSEMBLY_FLAGS flags = ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_UNKNOWN + | ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_FRAMEWORK | ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_SAFE_REFLECTION; m_flags = flags | ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_INITIALIZED; } @@ -1221,7 +952,7 @@ namespace System.Reflection return m_flags; } } -#endif // FEATURE_CORECLR +#endif // FEATURE_APPX internal object SyncRoot { @@ -1237,12 +968,10 @@ namespace System.Reflection public override event ModuleResolveEventHandler ModuleResolve { - [System.Security.SecurityCritical] // auto-generated_required add { _ModuleResolve += value; } - [System.Security.SecurityCritical] // auto-generated_required remove { _ModuleResolve -= value; @@ -1251,14 +980,12 @@ namespace System.Reflection private const String s_localFilePrefix = "file:"; - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static extern void GetCodeBase(RuntimeAssembly assembly, bool copiedName, StringHandleOnStack retString); - [System.Security.SecurityCritical] // auto-generated internal String GetCodeBase(bool copiedName) { String codeBase = null; @@ -1268,11 +995,6 @@ namespace System.Reflection public override String CodeBase { -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#else - [System.Security.SecuritySafeCritical] -#endif get { String codeBase = GetCodeBase(false); VerifyCodeBaseDiscovery(codeBase); @@ -1288,11 +1010,6 @@ namespace System.Reflection // If the assembly is copied before it is loaded, the codebase will be set to the // actual file loaded if copiedName is true. If it is false, then the original code base // is returned. -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#else - [System.Security.SecuritySafeCritical] -#endif public override AssemblyName GetName(bool copiedName) { AssemblyName an = new AssemblyName(); @@ -1326,27 +1043,12 @@ namespace System.Reflection return an; } -#if FEATURE_APTCA - // This method is called from the VM when creating conditional APTCA exceptions, in order to include - // the text which must be added to the partial trust visible assembly list - [SecurityCritical] - [PermissionSet(SecurityAction.Assert, Unrestricted = true)] - private string GetNameForConditionalAptca() - { - AssemblyName assemblyName = GetName(); - return assemblyName.GetNameWithPublicKey(); - - } -#endif // FEATURE_APTCA - - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static void GetFullName(RuntimeAssembly assembly, StringHandleOnStack retString); public override String FullName { - [System.Security.SecuritySafeCritical] // auto-generated get { // If called by Object.ToString(), return val may be NULL. if (m_fullname == null) @@ -1360,14 +1062,12 @@ namespace System.Reflection } } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static extern void GetEntryPoint(RuntimeAssembly assembly, ObjectHandleOnStack retMethod); public override MethodInfo EntryPoint { - [System.Security.SecuritySafeCritical] // auto-generated get { IRuntimeMethodInfo methodHandle = null; GetEntryPoint(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref methodHandle)); @@ -1379,7 +1079,6 @@ namespace System.Reflection } } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static extern void GetType(RuntimeAssembly assembly, @@ -1389,12 +1088,11 @@ namespace System.Reflection ObjectHandleOnStack type, ObjectHandleOnStack keepAlive); - [System.Security.SecuritySafeCritical] public override Type GetType(String name, bool throwOnError, bool ignoreCase) { // throw on null strings regardless of the value of "throwOnError" if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); RuntimeType type = null; Object keepAlive = null; @@ -1404,17 +1102,14 @@ namespace System.Reflection return type; } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] internal extern static void GetForwardedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes); - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static void GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes); - [System.Security.SecuritySafeCritical] // auto-generated public override Type[] GetExportedTypes() { Type[] types = null; @@ -1424,7 +1119,6 @@ namespace System.Reflection public override IEnumerable<TypeInfo> DefinedTypes { - [System.Security.SecuritySafeCritical] get { List<RuntimeType> rtTypes = new List<RuntimeType>(); @@ -1441,7 +1135,6 @@ namespace System.Reflection } // Load a resource based on the NameSpace of the type. - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public override Stream GetManifestResourceStream(Type type, String name) { @@ -1449,7 +1142,6 @@ namespace System.Reflection return GetManifestResourceStream(type, name, false, ref stackMark); } - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public override Stream GetManifestResourceStream(String name) { @@ -1457,76 +1149,11 @@ namespace System.Reflection return GetManifestResourceStream(name, ref stackMark, false); } -#if FEATURE_CAS_POLICY - [System.Security.SecurityCritical] // auto-generated - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - private extern static void GetEvidence(RuntimeAssembly assembly, ObjectHandleOnStack retEvidence); - - [SecurityCritical] - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - private extern static SecurityRuleSet GetSecurityRuleSet(RuntimeAssembly assembly); - - public override Evidence Evidence - { - [SecuritySafeCritical] - [SecurityPermissionAttribute( SecurityAction.Demand, ControlEvidence = true )] - get - { - Evidence evidence = EvidenceNoDemand; - return evidence.Clone(); - } - } - - internal Evidence EvidenceNoDemand - { - [SecurityCritical] - get - { - Evidence evidence = null; - GetEvidence(GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref evidence)); - return evidence; - } - } - - public override PermissionSet PermissionSet - { - [SecurityCritical] - get - { - PermissionSet grantSet = null; - PermissionSet deniedSet = null; - - GetGrantSet(out grantSet, out deniedSet); - - if (grantSet != null) - { - return grantSet.Copy(); - } - else - { - return new PermissionSet(PermissionState.Unrestricted); - } - } - } - - public override SecurityRuleSet SecurityRuleSet - { - [SecuritySafeCritical] - get - { - return GetSecurityRuleSet(GetNativeHandle()); - } - } -#endif // FEATURE_CAS_POLICY - // ISerializable implementation - [System.Security.SecurityCritical] // auto-generated_required public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); @@ -1550,17 +1177,17 @@ namespace System.Reflection { return CustomAttribute.GetCustomAttributes(this, typeof(object) as RuntimeType); } - + public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType); } @@ -1568,13 +1195,13 @@ namespace System.Reflection public override bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"caType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.IsDefined(this, attributeRuntimeType); } @@ -1583,8 +1210,7 @@ namespace System.Reflection { return CustomAttributeData.GetCustomAttributesInternal(this); } - - [System.Security.SecurityCritical] // auto-generated + [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable internal static RuntimeAssembly InternalLoadFrom(String assemblyFile, Evidence securityEvidence, @@ -1595,16 +1221,10 @@ namespace System.Reflection ref StackCrawlMark stackMark) { if (assemblyFile == null) - throw new ArgumentNullException("assemblyFile"); + throw new ArgumentNullException(nameof(assemblyFile)); Contract.EndContractBlock(); -#if FEATURE_CAS_POLICY - if (securityEvidence != null && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) - { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); - } -#endif // FEATURE_CAS_POLICY AssemblyName an = new AssemblyName(); an.CodeBase = assemblyFile; an.SetHashControl(hashValue, hashAlgorithm); @@ -1613,7 +1233,6 @@ namespace System.Reflection } // Wrapper function to wrap the typical use of InternalLoad. - [System.Security.SecurityCritical] // auto-generated internal static RuntimeAssembly InternalLoad(String assemblyString, Evidence assemblySecurity, ref StackCrawlMark stackMark, @@ -1622,7 +1241,6 @@ namespace System.Reflection return InternalLoad(assemblyString, assemblySecurity, ref stackMark, IntPtr.Zero, forIntrospection); } - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable internal static RuntimeAssembly InternalLoad(String assemblyString, Evidence assemblySecurity, @@ -1644,14 +1262,13 @@ namespace System.Reflection } // Creates AssemblyName. Fills assembly if AssemblyResolve event has been raised. - [System.Security.SecurityCritical] // auto-generated internal static AssemblyName CreateAssemblyName( String assemblyString, bool forIntrospection, out RuntimeAssembly assemblyFromResolveEvent) { if (assemblyString == null) - throw new ArgumentNullException("assemblyString"); + throw new ArgumentNullException(nameof(assemblyString)); Contract.EndContractBlock(); if ((assemblyString.Length == 0) || @@ -1670,7 +1287,6 @@ namespace System.Reflection } // Wrapper function to wrap the typical use of InternalLoadAssemblyName. - [System.Security.SecurityCritical] // auto-generated internal static RuntimeAssembly InternalLoadAssemblyName( AssemblyName assemblyRef, Evidence assemblySecurity, @@ -1684,7 +1300,6 @@ namespace System.Reflection return InternalLoadAssemblyName(assemblyRef, assemblySecurity, reqAssembly, ref stackMark, IntPtr.Zero, true /*throwOnError*/, forIntrospection, suppressSecurityChecks, ptrLoadContextBinder); } - [System.Security.SecurityCritical] // auto-generated internal static RuntimeAssembly InternalLoadAssemblyName( AssemblyName assemblyRef, Evidence assemblySecurity, @@ -1698,7 +1313,7 @@ namespace System.Reflection { if (assemblyRef == null) - throw new ArgumentNullException("assemblyRef"); + throw new ArgumentNullException(nameof(assemblyRef)); Contract.EndContractBlock(); if (assemblyRef.CodeBase != null) @@ -1717,13 +1332,6 @@ namespace System.Reflection if (assemblySecurity != null) { -#if FEATURE_CAS_POLICY - if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) - { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); - } -#endif // FEATURE_CAS_POLICY - if (!suppressSecurityChecks) { #pragma warning disable 618 @@ -1732,22 +1340,19 @@ namespace System.Reflection } } - String codeBase = VerifyCodeBase(assemblyRef.CodeBase); - if (codeBase != null && !suppressSecurityChecks) { - - if (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) != 0) { -#if FEATURE_FUSION // Of all the binders, Fusion is the only one that understands Web locations - IPermission perm = CreateWebPermission( assemblyRef.EscapedCodeBase ); - perm.Demand(); -#else + if (codeBase != null && !suppressSecurityChecks) + { + if (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) != 0) + { + // Of all the binders, Fusion is the only one that understands Web locations throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileName"), "assemblyRef.CodeBase"); -#endif } - else { + else + { System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true ); new FileIOPermission( FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read , urlString.GetFileName() ).Demand(); - } + } } return nLoad(assemblyRef, codeBase, assemblySecurity, reqAssembly, ref stackMark, @@ -1765,7 +1370,6 @@ namespace System.Reflection }; #if FEATURE_APPX - [System.Security.SecuritySafeCritical] internal bool IsFrameworkAssembly() { ASSEMBLY_FLAGS flags = Flags; @@ -1780,43 +1384,28 @@ namespace System.Reflection return (flags & ASSEMBLY_FLAGS.ASSEMBLY_FLAGS_SAFE_REFLECTION) != 0; } - [System.Security.SecuritySafeCritical] private bool IsDesignerBindingContext() { return RuntimeAssembly.nIsDesignerBindingContext(this); } - [System.Security.SecurityCritical] [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static bool nIsDesignerBindingContext(RuntimeAssembly assembly); #endif - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern RuntimeAssembly _nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, - ref StackCrawlMark stackMark, + ref StackCrawlMark stackMark, IntPtr pPrivHostBinder, - bool throwOnFileNotFound, + bool throwOnFileNotFound, bool forIntrospection, bool suppressSecurityChecks, IntPtr ptrLoadContextBinder); -#if !FEATURE_CORECLR - // The NGEN task uses this method, so please do not modify its signature - [System.Security.SecurityCritical] // auto-generated - [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern bool IsFrameworkAssembly(AssemblyName assemblyName); - - [System.Security.SecurityCritical] - [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern bool IsNewPortableAssembly(AssemblyName assemblyName); -#endif - - [System.Security.SecurityCritical] // auto-generated private static RuntimeAssembly nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, @@ -1832,177 +1421,6 @@ namespace System.Reflection throwOnFileNotFound, forIntrospection, suppressSecurityChecks, ptrLoadContextBinder); } -#if FEATURE_FUSION - // used by vm - [System.Security.SecurityCritical] // auto-generated - [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable - private static unsafe RuntimeAssembly LoadWithPartialNameHack(String partialName, bool cropPublicKey) - { - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - - AssemblyName an = new AssemblyName(partialName); - - if (!IsSimplyNamed(an)) - { - if (cropPublicKey) - { - an.SetPublicKey(null); - an.SetPublicKeyToken(null); - } - - if(IsFrameworkAssembly(an) || !AppDomain.IsAppXModel()) - { - AssemblyName GACAssembly = EnumerateCache(an); - if(GACAssembly != null) - return InternalLoadAssemblyName(GACAssembly, null, null,ref stackMark, true /*thrownOnFileNotFound*/, false, false); - else - return null; - } - } - - if (AppDomain.IsAppXModel()) - { - // also try versionless bind from the package - an.Version = null; - return nLoad(an, null, null, null, ref stackMark, - IntPtr.Zero, - false, false, false); - } - return null; - - } - -#if !FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated - internal static RuntimeAssembly LoadWithPartialNameInternal(String partialName, Evidence securityEvidence, ref StackCrawlMark stackMark) - { - AssemblyName an = new AssemblyName(partialName); - return LoadWithPartialNameInternal(an, securityEvidence, ref stackMark); - } - - [System.Security.SecurityCritical] // auto-generated - internal static RuntimeAssembly LoadWithPartialNameInternal(AssemblyName an, Evidence securityEvidence, ref StackCrawlMark stackMark) - { - if (securityEvidence != null) - { -#if FEATURE_CAS_POLICY - if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) - { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); - } -#endif // FEATURE_CAS_POLICY - new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); - } - - AppDomain.CheckLoadWithPartialNameSupported(stackMark); - - RuntimeAssembly result = null; - try { - result = nLoad(an, null, securityEvidence, null, ref stackMark, - IntPtr.Zero, - true, false, false); - } - catch(Exception e) { - if (e.IsTransient) - throw e; - - if (IsUserError(e)) - throw; - - - if(IsFrameworkAssembly(an) || !AppDomain.IsAppXModel()) - { - if (IsSimplyNamed(an)) - return null; - - AssemblyName GACAssembly = EnumerateCache(an); - if(GACAssembly != null) - result = InternalLoadAssemblyName(GACAssembly, securityEvidence, null, ref stackMark, true /*thrownOnFileNotFound*/, false, false); - } - else - { - an.Version = null; - result = nLoad(an, null, securityEvidence, null, ref stackMark, - IntPtr.Zero, - false, false, false); - } - } - - - return result; - } -#endif // !FEATURE_CORECLR - - [SecuritySafeCritical] - private static bool IsUserError(Exception e) - { - return (uint)e.HResult == COR_E_LOADING_REFERENCE_ASSEMBLY; - } - - private static bool IsSimplyNamed(AssemblyName partialName) - { - byte[] pk = partialName.GetPublicKeyToken(); - if ((pk != null) && - (pk.Length == 0)) - return true; - - pk = partialName.GetPublicKey(); - if ((pk != null) && - (pk.Length == 0)) - return true; - - return false; - } - - [System.Security.SecurityCritical] // auto-generated - private static AssemblyName EnumerateCache(AssemblyName partialName) - { - new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert(); - - partialName.Version = null; - - ArrayList a = new ArrayList(); - Fusion.ReadCache(a, partialName.FullName, ASM_CACHE.GAC); - - IEnumerator myEnum = a.GetEnumerator(); - AssemblyName ainfoBest = null; - CultureInfo refCI = partialName.CultureInfo; - - while (myEnum.MoveNext()) { - AssemblyName ainfo = new AssemblyName((String)myEnum.Current); - - if (CulturesEqual(refCI, ainfo.CultureInfo)) { - if (ainfoBest == null) - ainfoBest = ainfo; - else { - // Choose highest version - if (ainfo.Version > ainfoBest.Version) - ainfoBest = ainfo; - } - } - } - - return ainfoBest; - } - - private static bool CulturesEqual(CultureInfo refCI, CultureInfo defCI) - { - bool defNoCulture = defCI.Equals(CultureInfo.InvariantCulture); - - // cultured asms aren't allowed to be bound to if - // the ref doesn't ask for them specifically - if ((refCI == null) || refCI.Equals(CultureInfo.InvariantCulture)) - return defNoCulture; - - if (defNoCulture || - ( !defCI.Equals(refCI) )) - return false; - - return true; - } -#endif // FEATURE_FUSION - - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern bool IsReflectionOnly(RuntimeAssembly assembly); @@ -2011,23 +1429,20 @@ namespace System.Reflection [ComVisible(false)] public override bool ReflectionOnly { - [System.Security.SecuritySafeCritical] // auto-generated get { return IsReflectionOnly(GetNativeHandle()); } } -#if FEATURE_CORECLR // Loads the assembly with a COFF based IMAGE containing // an emitted assembly. The assembly is loaded into the domain // of the caller. Currently is implemented only for UnmanagedMemoryStream // (no derived classes since we are not calling Read()) - [System.Security.SecurityCritical] // auto-generated internal static RuntimeAssembly InternalLoadFromStream(Stream assemblyStream, Stream pdbStream, ref StackCrawlMark stackMark) { if (assemblyStream == null) - throw new ArgumentNullException("assemblyStream"); + throw new ArgumentNullException(nameof(assemblyStream)); if (assemblyStream.GetType()!=typeof(UnmanagedMemoryStream)) throw new NotSupportedException(); @@ -2070,44 +1485,13 @@ namespace System.Reflection return assembly; } } -#endif //FEATURE_CORECLR - -#if FEATURE_MULTIMODULE_ASSEMBLIES - [System.Security.SecurityCritical] // auto-generated - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - private extern static void LoadModule(RuntimeAssembly assembly, - String moduleName, - byte[] rawModule, int cbModule, - byte[] rawSymbolStore, int cbSymbolStore, - ObjectHandleOnStack retModule); - - [SecurityPermissionAttribute(SecurityAction.Demand, ControlEvidence = true)] - [System.Security.SecuritySafeCritical] // auto-generated - public override Module LoadModule(String moduleName, byte[] rawModule, byte[] rawSymbolStore) - { - RuntimeModule retModule = null; - LoadModule( - GetNativeHandle(), - moduleName, - rawModule, - (rawModule != null) ? rawModule.Length : 0, - rawSymbolStore, - (rawSymbolStore != null) ? rawSymbolStore.Length : 0, - JitHelpers.GetObjectHandleOnStack(ref retModule)); - - return retModule; - } -#endif //FEATURE_MULTIMODULE_ASSEMBLIES // Returns the module in this assembly with name 'name' - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static extern void GetModule(RuntimeAssembly assembly, String name, ObjectHandleOnStack retModule); - [System.Security.SecuritySafeCritical] // auto-generated public override Module GetModule(String name) { Module retModule = null; @@ -2117,11 +1501,6 @@ namespace System.Reflection // Returns the file in the File table of the manifest that matches the // given name. (Name should not include path.) -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#else - [System.Security.SecuritySafeCritical] -#endif public override FileStream GetFile(String name) { RuntimeModule m = (RuntimeModule)GetModule(name); @@ -2133,11 +1512,6 @@ namespace System.Reflection FileAccess.Read, FileShare.Read, FileStream.DefaultBufferSize, false); } -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#else - [System.Security.SecuritySafeCritical] -#endif public override FileStream[] GetFiles(bool getResourceModules) { Module[] m = GetModules(getResourceModules); @@ -2152,26 +1526,20 @@ namespace System.Reflection return fs; } - // Returns the names of all the resources - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern String[] GetManifestResourceNames(RuntimeAssembly assembly); // Returns the names of all the resources - [System.Security.SecuritySafeCritical] // auto-generated public override String[] GetManifestResourceNames() { return GetManifestResourceNames(GetNativeHandle()); } - - - [System.Security.SecurityCritical] // auto-generated + [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static void GetExecutingAssembly(StackCrawlMarkHandle stackMark, ObjectHandleOnStack retAssembly); - [System.Security.SecurityCritical] // auto-generated internal static RuntimeAssembly GetExecutingAssembly(ref StackCrawlMark stackMark) { RuntimeAssembly retAssembly = null; @@ -2180,17 +1548,14 @@ namespace System.Reflection } // Returns the names of all the resources - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern AssemblyName[] GetReferencedAssemblies(RuntimeAssembly assembly); - [System.Security.SecuritySafeCritical] // auto-generated public override AssemblyName[] GetReferencedAssemblies() { return GetReferencedAssemblies(GetNativeHandle()); } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static extern int GetManifestResourceInfo(RuntimeAssembly assembly, @@ -2199,7 +1564,6 @@ namespace System.Reflection StringHandleOnStack retFileName, StackCrawlMarkHandle stackMark); - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public override ManifestResourceInfo GetManifestResourceInfo(String resourceName) { @@ -2218,18 +1582,12 @@ namespace System.Reflection (ResourceLocation) location); } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static extern void GetLocation(RuntimeAssembly assembly, StringHandleOnStack retString); public override String Location { -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated -#else - [System.Security.SecuritySafeCritical] -#endif get { String location = null; @@ -2242,7 +1600,6 @@ namespace System.Reflection } } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static void GetImageRuntimeVersion(RuntimeAssembly assembly, StringHandleOnStack retString); @@ -2252,7 +1609,6 @@ namespace System.Reflection [ComVisible(false)] public override String ImageRuntimeVersion { - [System.Security.SecuritySafeCritical] // auto-generated get{ String s = null; GetImageRuntimeVersion(GetNativeHandle(), JitHelpers.GetStringHandleOnStack(ref s)); @@ -2261,30 +1617,26 @@ namespace System.Reflection } - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern static bool IsGlobalAssemblyCache(RuntimeAssembly assembly); public override bool GlobalAssemblyCache { - [System.Security.SecuritySafeCritical] // auto-generated get { - return IsGlobalAssemblyCache(GetNativeHandle()); + return false; } } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static Int64 GetHostContext(RuntimeAssembly assembly); public override Int64 HostContext { - [System.Security.SecuritySafeCritical] // auto-generated get { - return GetHostContext(GetNativeHandle()); + return 0; } } @@ -2309,14 +1661,13 @@ namespace System.Reflection else if ((len > 2) && (codebase[0] == '\\') && (codebase[1] == '\\')) return "file://" + codebase; else - return "file:///" + Path.GetFullPathInternal( codebase ); + return "file:///" + Path.GetFullPath(codebase); #else else - return "file://" + Path.GetFullPathInternal( codebase ); + return "file://" + Path.GetFullPath(codebase); #endif // !PLATFORM_UNIX } - [System.Security.SecurityCritical] // auto-generated internal Stream GetManifestResourceStream( Type type, String name, @@ -2326,7 +1677,7 @@ namespace System.Reflection StringBuilder sb = new StringBuilder(); if(type == null) { if (name == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } else { String nameSpace = type.Namespace; @@ -2339,25 +1690,11 @@ namespace System.Reflection if(name != null) sb.Append(name); - - return GetManifestResourceStream(sb.ToString(), ref stackMark, skipSecurityCheck); - } -#if FEATURE_CAS_POLICY - internal bool IsStrongNameVerified - { - [System.Security.SecurityCritical] // auto-generated - get { return GetIsStrongNameVerified(GetNativeHandle()); } + return GetManifestResourceStream(sb.ToString(), ref stackMark, skipSecurityCheck); } - [System.Security.SecurityCritical] // auto-generated - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - private static extern bool GetIsStrongNameVerified(RuntimeAssembly assembly); -#endif // FEATURE_CAS_POLICY - // GetResource will return a pointer to the resources in memory. - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static unsafe extern byte* GetResource(RuntimeAssembly assembly, @@ -2366,7 +1703,6 @@ namespace System.Reflection StackCrawlMarkHandle stackMark, bool skipSecurityCheck); - [System.Security.SecurityCritical] // auto-generated internal unsafe Stream GetManifestResourceStream(String name, ref StackCrawlMark stackMark, bool skipSecurityCheck) { ulong length = 0; @@ -2384,7 +1720,6 @@ namespace System.Reflection return null; } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static extern void GetVersion(RuntimeAssembly assembly, @@ -2393,7 +1728,6 @@ namespace System.Reflection out int buildNum, out int revNum); - [System.Security.SecurityCritical] // auto-generated internal Version GetVersion() { int majorVer, minorVer, build, revision; @@ -2401,12 +1735,10 @@ namespace System.Reflection return new Version (majorVer, minorVer, build, revision); } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static extern void GetLocale(RuntimeAssembly assembly, StringHandleOnStack retString); - [System.Security.SecurityCritical] // auto-generated internal CultureInfo GetLocale() { String locale = null; @@ -2419,27 +1751,18 @@ namespace System.Reflection return new CultureInfo(locale); } - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] private static extern bool FCallIsDynamic(RuntimeAssembly assembly); public override bool IsDynamic { - [SecuritySafeCritical] get { return FCallIsDynamic(GetNativeHandle()); } } - [System.Security.SecurityCritical] // auto-generated private void VerifyCodeBaseDiscovery(String codeBase) { -#if FEATURE_CAS_POLICY - if (CodeAccessSecurityEngine.QuickCheckForAllDemands()) { - return; - } -#endif // FEATURE_CAS_POLICY - if ((codeBase != null) && (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) == 0)) { System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true ); @@ -2447,12 +1770,10 @@ namespace System.Reflection } } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static extern void GetSimpleName(RuntimeAssembly assembly, StringHandleOnStack retSimpleName); - [SecuritySafeCritical] internal String GetSimpleName() { string name = null; @@ -2460,35 +1781,29 @@ namespace System.Reflection return name; } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static AssemblyHashAlgorithm GetHashAlgorithm(RuntimeAssembly assembly); - [System.Security.SecurityCritical] // auto-generated private AssemblyHashAlgorithm GetHashAlgorithm() { return GetHashAlgorithm(GetNativeHandle()); } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static AssemblyNameFlags GetFlags(RuntimeAssembly assembly); - [System.Security.SecurityCritical] // auto-generated private AssemblyNameFlags GetFlags() { return GetFlags(GetNativeHandle()); } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SecurityCritical] [SuppressUnmanagedCodeSecurity] private static extern void GetRawBytes(RuntimeAssembly assembly, ObjectHandleOnStack retRawBytes); // Get the raw bytes of the assembly - [SecuritySafeCritical] internal byte[] GetRawBytes() { byte[] rawBytes = null; @@ -2497,12 +1812,10 @@ namespace System.Reflection return rawBytes; } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private static extern void GetPublicKey(RuntimeAssembly assembly, ObjectHandleOnStack retPublicKey); - [System.Security.SecurityCritical] // auto-generated internal byte[] GetPublicKey() { byte[] publicKey = null; @@ -2510,12 +1823,10 @@ namespace System.Reflection return publicKey; } - [SecurityCritical] [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static void GetGrantSet(RuntimeAssembly assembly, ObjectHandleOnStack granted, ObjectHandleOnStack denied); - [SecurityCritical] internal void GetGrantSet(out PermissionSet newGrant, out PermissionSet newDenied) { PermissionSet granted = null, denied = null; @@ -2523,134 +1834,51 @@ namespace System.Reflection newGrant = granted; newDenied = denied; } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] private extern static bool IsAllSecurityCritical(RuntimeAssembly assembly); // Is everything introduced by this assembly critical - [System.Security.SecuritySafeCritical] // auto-generated internal bool IsAllSecurityCritical() { return IsAllSecurityCritical(GetNativeHandle()); } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] private extern static bool IsAllSecuritySafeCritical(RuntimeAssembly assembly); // Is everything introduced by this assembly safe critical - [System.Security.SecuritySafeCritical] // auto-generated internal bool IsAllSecuritySafeCritical() { return IsAllSecuritySafeCritical(GetNativeHandle()); } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] private extern static bool IsAllPublicAreaSecuritySafeCritical(RuntimeAssembly assembly); // Is everything introduced by this assembly safe critical - [System.Security.SecuritySafeCritical] // auto-generated internal bool IsAllPublicAreaSecuritySafeCritical() { return IsAllPublicAreaSecuritySafeCritical(GetNativeHandle()); } - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] private extern static bool IsAllSecurityTransparent(RuntimeAssembly assembly); // Is everything introduced by this assembly transparent - [System.Security.SecuritySafeCritical] // auto-generated internal bool IsAllSecurityTransparent() { return IsAllSecurityTransparent(GetNativeHandle()); } -#if FEATURE_FUSION - // demandFlag: - // 0 demand PathDiscovery permission only - // 1 demand Read permission only - // 2 demand both Read and PathDiscovery - // 3 demand Web permission only - [System.Security.SecurityCritical] // auto-generated - private static void DemandPermission(String codeBase, bool havePath, - int demandFlag) - { - FileIOPermissionAccess access = FileIOPermissionAccess.PathDiscovery; - switch(demandFlag) { - - case 0: // default - break; - case 1: - access = FileIOPermissionAccess.Read; - break; - case 2: - access = FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read; - break; - - case 3: - IPermission perm = CreateWebPermission(AssemblyName.EscapeCodeBase(codeBase)); - perm.Demand(); - return; - } - - if (!havePath) { - System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true ); - codeBase = urlString.GetFileName(); - } - - codeBase = Path.GetFullPathInternal(codeBase); // canonicalize - - new FileIOPermission(access, codeBase).Demand(); - } -#endif - -#if FEATURE_FUSION - private static IPermission CreateWebPermission( String codeBase ) - { - Contract.Assert( codeBase != null, "Must pass in a valid CodeBase" ); - Assembly sys = Assembly.Load("System, Version=" + ThisAssembly.Version + ", Culture=neutral, PublicKeyToken=" + AssemblyRef.EcmaPublicKeyToken); - - Type type = sys.GetType("System.Net.NetworkAccess", true); - - IPermission retval = null; - if (!type.IsEnum || !type.IsVisible) - goto Exit; - - Object[] webArgs = new Object[2]; - webArgs[0] = (Enum) Enum.Parse(type, "Connect", true); - if (webArgs[0] == null) - goto Exit; - - webArgs[1] = codeBase; - - type = sys.GetType("System.Net.WebPermission", true); - - if (!type.IsVisible) - goto Exit; - - retval = (IPermission) Activator.CreateInstance(type, webArgs); - - Exit: - if (retval == null) { - Contract.Assert( false, "Unable to create WebPermission" ); - throw new InvalidOperationException(); - } - - return retval; - } -#endif // This method is called by the VM. - [System.Security.SecurityCritical] private RuntimeModule OnModuleResolveEvent(String moduleName) { ModuleResolveEventHandler moduleResolve = _ModuleResolve; @@ -2683,14 +1911,13 @@ namespace System.Reflection return InternalGetSatelliteAssembly(culture, version, ref stackMark); } - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable internal Assembly InternalGetSatelliteAssembly(CultureInfo culture, Version version, ref StackCrawlMark stackMark) { if (culture == null) - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); Contract.EndContractBlock(); @@ -2698,15 +1925,6 @@ namespace System.Reflection return InternalGetSatelliteAssembly(name, culture, version, true, ref stackMark); } -#if !FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated - [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] - [SuppressUnmanagedCodeSecurity] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool UseRelativeBindForSatellites(); -#endif - - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable internal RuntimeAssembly InternalGetSatelliteAssembly(String name, CultureInfo culture, @@ -2728,104 +1946,9 @@ namespace System.Reflection an.CultureInfo = culture; an.Name = name; - RuntimeAssembly retAssembly = null; - -#if !FEATURE_CORECLR - bool bIsAppXDevMode = AppDomain.IsAppXDesignMode(); - - bool useRelativeBind = false; - if (CodeAccessSecurityEngine.QuickCheckForAllDemands()) - { - if (IsFrameworkAssembly()) - useRelativeBind = true; - else - useRelativeBind = UseRelativeBindForSatellites(); - } - - - if (bIsAppXDevMode || useRelativeBind) - { - if (GlobalAssemblyCache) - { - // lookup in GAC - ArrayList a = new ArrayList(); - bool bTryLoadAnyway = false; - try - { - Fusion.ReadCache(a, an.FullName, ASM_CACHE.GAC); - } - catch(Exception e) - { - if (e.IsTransient) - throw; - - // We also catch any other exception types we haven't come across yet, - // not just UnauthorizedAccessException. - - // We do not want this by itself to cause us to fail to load resources. - - // On Classic, try the old unoptimized way, for full compatibility with 4.0. - // i.e. fall back to using nLoad. - if (!AppDomain.IsAppXModel()) - bTryLoadAnyway = true; - - // On AppX: - // Do not try nLoad since that would effectively allow Framework - // resource satellite assemblies to be placed in AppX packages. - // Instead, leave retAssembly == null. If we were called by the - // ResourceManager, this will usually result in falling back to - // the next culture in the resource fallback chain, possibly the - // neutral culture. - - // Note: if throwOnFileNotFound is true, arbitrary - // exceptions will be absorbed here and - // FileNotFoundException will be thrown in their place. - // (See below: "throw new FileNotFoundException"). - } - if (a.Count > 0 || bTryLoadAnyway) - { - // present in the GAC, load it from there - retAssembly = nLoad(an, null, null, this, ref stackMark, - IntPtr.Zero, - throwOnFileNotFound, false, false); - } - } - else - { - String codeBase = CodeBase; - - if ((codeBase != null) && - (String.Compare(codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) == 0)) - { - retAssembly = InternalProbeForSatelliteAssemblyNextToParentAssembly(an, - name, - codeBase, - culture, - throwOnFileNotFound, - bIsAppXDevMode /* useLoadFile */, // if bIsAppXDevMode is false, then useRelativeBind is true. - ref stackMark); - if (retAssembly != null && !IsSimplyNamed(an)) - { - AssemblyName defName = retAssembly.GetName(); - if (!AssemblyName.ReferenceMatchesDefinitionInternal(an,defName,false)) - retAssembly = null; - } - } - else if (!bIsAppXDevMode) - { - retAssembly = nLoad(an, null, null, this, ref stackMark, - IntPtr.Zero, - throwOnFileNotFound, false, false); - } - } - } - else -#endif // !FEATURE_CORECLR - { - retAssembly = nLoad(an, null, null, this, ref stackMark, - IntPtr.Zero, - throwOnFileNotFound, false, false); - } + RuntimeAssembly retAssembly = nLoad(an, null, null, this, ref stackMark, + IntPtr.Zero, + throwOnFileNotFound, false, false); if (retAssembly == this || (retAssembly == null && throwOnFileNotFound)) { @@ -2836,7 +1959,6 @@ namespace System.Reflection } // Helper method used by InternalGetSatelliteAssembly only. Not abstracted for use elsewhere. - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable private RuntimeAssembly InternalProbeForSatelliteAssemblyNextToParentAssembly(AssemblyName an, String name, @@ -2930,7 +2052,7 @@ namespace System.Reflection // the .DLL and .EXE load attempts if the user is interested in digging deeper. if (retAssembly == null && throwOnFileNotFound) - throw dllNotFoundException; + throw dllNotFoundException; } } catch (DirectoryNotFoundException) @@ -2944,11 +2066,9 @@ namespace System.Reflection return retAssembly; } - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern RuntimeAssembly nLoadFile(String path, Evidence evidence); - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] static internal extern RuntimeAssembly nLoadImage(byte[] rawAssembly, byte[] rawSymbolStore, @@ -2956,8 +2076,7 @@ namespace System.Reflection ref StackCrawlMark stackMark, bool fIntrospection, SecurityContextSource securityContextSource); -#if FEATURE_CORECLR - [System.Security.SecurityCritical] // auto-generated + [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] static internal extern unsafe void nLoadFromUnmanagedArray(bool fIntrospection, @@ -2967,9 +2086,7 @@ namespace System.Reflection ulong pdbSize, StackCrawlMarkHandle stackMark, ObjectHandleOnStack retAssembly); -#endif - [System.Security.SecurityCritical] // auto-generated [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] [SuppressUnmanagedCodeSecurity] private extern static void GetModules(RuntimeAssembly assembly, @@ -2977,7 +2094,6 @@ namespace System.Reflection bool getResourceModules, ObjectHandleOnStack retModuleHandles); - [System.Security.SecuritySafeCritical] // auto-generated private RuntimeModule[] GetModulesInternal(bool loadIfNotFound, bool getResourceModules) { @@ -2996,17 +2112,9 @@ namespace System.Reflection return GetModulesInternal(false, getResourceModules); } - [System.Security.SecuritySafeCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern RuntimeModule GetManifestModule(RuntimeAssembly assembly); -#if FEATURE_APTCA - [System.Security.SecuritySafeCritical] - [MethodImplAttribute(MethodImplOptions.InternalCall)] - internal static extern bool AptcaCheck(RuntimeAssembly targetAssembly, RuntimeAssembly sourceAssembly); -#endif // FEATURE_APTCA - - [System.Security.SecurityCritical] // auto-generated [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern int GetToken(RuntimeAssembly assembly); } |