Expose apis in System.Reflection.Assembly
authorRahul Kumar <rahku@microsoft.com>
Mon, 17 Oct 2016 23:52:57 +0000 (16:52 -0700)
committerRahul Kumar <rahku@microsoft.com>
Tue, 18 Oct 2016 23:50:00 +0000 (16:50 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/153162f00bff94660b69237bcea341fb11e90926

src/coreclr/src/mscorlib/model.xml
src/coreclr/src/mscorlib/ref/mscorlib.cs
src/coreclr/src/mscorlib/src/System.Private.CoreLib.txt
src/coreclr/src/mscorlib/src/System/Reflection/Assembly.cs
src/coreclr/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs

index 70b2597..c6072f9 100644 (file)
       <Member Name="GetReferencedAssemblies" />
       <Member Name="get_EntryPoint" />
       <Member Name="get_FullName" />
+      <Member Name="get_GlobalAssemblyCache" />
+      <Member Name="get_HostContext" />
       <Member Name="get_ImageRuntimeVersion" />
+      <Member Name="get_IsFullyTrusted" />
       <Member Name="get_IsDynamic" />
       <Member Name="get_CodeBase" />
       <Member Name="get_Location" />
       <Member Name="get_CustomAttributes" />
       <Member Name="get_Modules" />
       <Member Name="get_ReflectionOnly" />
+      <Member Name="get_SecurityRuleSet" />
       <Member Name="GetAssembly(System.Type)" />
       <Member Name="op_Equality(System.Reflection.Assembly,System.Reflection.Assembly)" />
       <Member Name="op_Inequality(System.Reflection.Assembly,System.Reflection.Assembly)" />
       <Member Name="Load(System.String)" />
       <Member Name="Load(System.Byte[])" />
       <Member Name="Load(System.Byte[],System.Byte[])" />
+      <Member Name="LoadFile(System.String)" />
+      <Member Name="LoadFrom(System.String)" />
+      <Member Name="LoadFrom(System.String,System.Byte[],System.Configuration.Assemblies.AssemblyHashAlgorithm)" />
+      <Member Name="LoadModule(System.String,System.Byte[])" />
+      <Member Name="LoadModule(System.String,System.Byte[],System.Byte[])" />
+      <Member Name="LoadWithPartialName(System.String)" />
       <Member Name="ReflectionOnlyLoad(System.String)" />
       <Member Name="ReflectionOnlyLoad(System.Byte[])" />
       <Member Name="ReflectionOnlyLoadFrom(System.String)" />
       <Member Name="ToString" />
+      <Member Name="UnsafeLoadFrom(System.String)" />
       <Member MemberType="Property" Name="DefinedTypes" />
       <Member MemberType="Property" Name="CustomAttributes" />
       <Member MemberType="Property" Name="Modules" />
       <Member MemberType="Property" Name="ExportedTypes" />
       <Member MemberType="Property" Name="EntryPoint" />
       <Member MemberType="Property" Name="FullName" />
+      <Member MemberType="Property" Name="GlobalAssemblyCache" />
+      <Member MemberType="Property" Name="HostContext" />
       <Member MemberType="Property" Name="CodeBase" />
       <Member MemberType="Property" Name="ImageRuntimeVersion" />
+      <Member MemberType="Property" Name="IsFullyTrusted" />
       <Member MemberType="Property" Name="Location" />
       <Member MemberType="Property" Name="ManifestModule" />
+      <Member MemberType="Property" Name="SecurityRuleSet" />
       <Member Status="ImplRoot" MemberType="Event" Name="ModuleResolve" />
     </Type>
     <Type Name="System.Reflection.IntrospectionExtensions">
index 4160762..f4ed66a 100644 (file)
@@ -7254,9 +7254,12 @@ namespace System.Reflection
         public virtual System.Reflection.MethodInfo EntryPoint { get { throw null; } }
         public virtual System.Collections.Generic.IEnumerable<System.Type> ExportedTypes { get { throw null; } }
         public virtual string FullName { get { throw null; } }
+        public virtual bool GlobalAssemblyCache { get { throw null; } }
+        public virtual Int64 HostContext { get { throw null; } }
         [System.Runtime.InteropServices.ComVisibleAttribute(false)]
         public virtual string ImageRuntimeVersion { get { throw null; } }
         public virtual bool IsDynamic { get { throw null; } }
+        public bool IsFullyTrusted { get { throw null; } }
         public virtual string Location { [System.Security.SecurityCriticalAttribute]get { throw null; } }
         [System.Runtime.InteropServices.ComVisibleAttribute(false)]
         public virtual System.Reflection.Module ManifestModule { get { throw null; } }
@@ -7264,6 +7267,7 @@ namespace System.Reflection
         public virtual System.Collections.Generic.IEnumerable<System.Reflection.Module> Modules { get { throw null; } }
         [System.Runtime.InteropServices.ComVisibleAttribute(false)]
         public virtual bool ReflectionOnly { get { throw null; } }
+        public virtual System.Security.SecurityRuleSet SecurityRuleSet { get { throw null; } }
         public object CreateInstance(string typeName) { throw null; }
         public object CreateInstance(string typeName, bool ignoreCase) { throw null; }
         public virtual object CreateInstance(String typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, System.Globalization.CultureInfo culture, Object[] activationAttributes) { throw null; }
@@ -7314,6 +7318,13 @@ namespace System.Reflection
         public static System.Reflection.Assembly Load(System.Reflection.AssemblyName assemblyRef) { throw null; }
         [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)][System.Security.SecuritySafeCriticalAttribute]
         public static System.Reflection.Assembly Load(string assemblyString) { throw null; }
+        public static System.Reflection.Assembly LoadFile(String path) { throw null; }
+        public static System.Reflection.Assembly LoadFrom(String path) { throw null; }
+        public static Assembly LoadFrom(string assemblyFile, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm) { throw null; }
+        public System.Reflection.Module LoadModule(String moduleName, byte[] rawModule) { throw null; }
+        public System.Reflection.Module LoadModule(String moduleName, byte[] rawModule, byte[] rawSymbolStore) { throw null; }
+        [ObsoleteAttribute("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")]
+        public static Assembly LoadWithPartialName(string partialName) { throw null; }
         [System.Security.SecuritySafeCriticalAttribute][System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
         public static Assembly ReflectionOnlyLoad(byte[] rawAssembly) { throw null; }
         [System.Security.SecuritySafeCriticalAttribute][System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
@@ -7321,6 +7332,7 @@ namespace System.Reflection
         [System.Security.SecuritySafeCriticalAttribute][System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
         public static Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw null; }
         public override string ToString() { throw null; }
+        public static Assembly UnsafeLoadFrom(string assemblyFile) { throw null; }
     }
     [System.AttributeUsageAttribute((System.AttributeTargets)(1), Inherited=false)]
     [System.Runtime.InteropServices.ComVisibleAttribute(true)]
index 762ee45..e0a4f13 100644 (file)
@@ -1477,6 +1477,7 @@ NotSupported_PIAInAppxProcess = A Primary Interop Assembly is not supported in A
 ; Not referring to "Windows Phone" in the messages, as FEATURE_WINDOWSPHONE is defined for .NET Core as well.
 NotSupported_WindowsPhone = {0} is not supported.
 NotSupported_AssemblyLoadCodeBase = Assembly.Load with a Codebase is not supported.
+NotSupported_AssemblyLoadFromHash = Assembly.LoadFrom with hashValue is not supported.
 #endif
 
 ; TypeLoadException
index 479d6ca..988299f 100644 (file)
@@ -37,6 +37,7 @@ namespace System.Reflection
     using __HResults = System.__HResults;
     using System.Runtime.Versioning;
     using System.Diagnostics.Contracts;
+    using System.Runtime.Loader;
 
 
     [Serializable]
@@ -105,21 +106,24 @@ 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
+        [System.Security.SecurityCritical]
+        public static Assembly LoadFrom(String assemblyFile)
+        {
+            if(assemblyFile == null) 
+                throw new ArgumentNullException("assemblyFile");
+            string fullPath = Path.GetFullPathInternal(assemblyFile);
+            return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath);
+        }
 #else
+        // Locate an assembly by the name of the file containing the manifest.
         [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(
@@ -130,8 +134,8 @@ namespace System.Reflection
                 false,// forIntrospection
                 false,// suppressSecurityChecks
                 ref stackMark);
-#endif // FEATURE_WINDOWSPHONE
         }
+#endif
 
         // Locate an assembly for reflection by the name of the file containing the manifest.
         [System.Security.SecuritySafeCritical]  // auto-generated
@@ -202,6 +206,9 @@ namespace System.Reflection
                                         byte[] hashValue,
                                         AssemblyHashAlgorithm hashAlgorithm)
         {
+#if FEATURE_CORECLR
+            throw new NotSupportedException(Environment.GetResourceString("NotSupported_AssemblyLoadFromHash"));
+#else
             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
 
             return RuntimeAssembly.InternalLoadFrom(
@@ -212,6 +219,7 @@ namespace System.Reflection
                 false,
                 false,
                 ref stackMark);
+#endif
         }
 
 #if FEATURE_CAS_POLICY
@@ -234,6 +242,12 @@ namespace System.Reflection
                                                     true, // suppressSecurityChecks
                                                     ref stackMark);
         }
+#elif FEATURE_CORECLR
+        [SecurityCritical]
+        public static Assembly UnsafeLoadFrom(string assemblyFile)
+        {
+            return LoadFrom(assemblyFile);
+        }
 #endif // FEATURE_CAS_POLICY
 
         // Locate an assembly by the long form of the assembly name. 
@@ -383,6 +397,16 @@ namespace System.Reflection
             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
             return RuntimeAssembly.LoadWithPartialNameInternal(partialName, securityEvidence, ref stackMark);
         }
+#elif FEATURE_CORECLR
+        [System.Security.SecuritySafeCritical]  // auto-generated
+        [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")]
+        public static Assembly LoadWithPartialName(String partialName)
+        {
+            if(partialName == null)
+                throw new ArgumentNullException("partialName");
+            return Load(partialName);
+        }
+
 #endif // FEATURE_FUSION
 
         // Loads the assembly with a COFF based IMAGE containing
@@ -401,6 +425,9 @@ namespace System.Reflection
 
             AppDomain.CheckLoadByteArraySupported();
 
+#if FEATURE_CORECLR
+            return Load(rawAssembly, null);
+#else
             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
             return RuntimeAssembly.nLoadImage(
                 rawAssembly,
@@ -409,6 +436,7 @@ namespace System.Reflection
                 ref stackMark,
                 false,  // fIntrospection
                 SecurityContextSource.CurrentAssembly);
+#endif
         }
 
         // Loads the assembly for reflection with a COFF based IMAGE containing
@@ -451,6 +479,14 @@ namespace System.Reflection
 
             AppDomain.CheckLoadByteArraySupported();
 
+#if FEATURE_CORECLR
+            if(rawAssembly == null)
+                throw new ArgumentNullException("rawAssembly");
+            AssemblyLoadContext alc = new FileLoadAssemblyLoadContext();
+            MemoryStream assemblyStream = new MemoryStream(rawAssembly);
+            MemoryStream symbolStream = (rawSymbolStore==null)?new MemoryStream(rawSymbolStore):null;
+            return alc.LoadFromStream(assemblyStream, symbolStream);
+#else
             StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
             return RuntimeAssembly.nLoadImage(
                 rawAssembly,
@@ -459,6 +495,7 @@ namespace System.Reflection
                 ref stackMark,
                 false,  // fIntrospection
                 SecurityContextSource.CurrentAssembly);
+#endif
         }
 
         // Load an assembly from a byte array, controlling where the grant set of this assembly is
@@ -527,6 +564,10 @@ namespace System.Reflection
         }
 #endif // FEATURE_CAS_POLICY
 
+#if FEATURE_CORECLR
+        private static Dictionary<string, Assembly> s_loadfile = new Dictionary<string, Assembly>();
+#endif
+
         [System.Security.SecuritySafeCritical]  // auto-generated
         public static Assembly LoadFile(String path)
         {
@@ -536,8 +577,31 @@ namespace System.Reflection
 
             AppDomain.CheckLoadFileSupported();
 
+#if FEATURE_CORECLR
+            Assembly result = null;
+            if(path == null)
+                throw new ArgumentNullException("path");
+
+            if (Path.IsRelative(path))
+            {
+                throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), "path");
+            }
+
+            string normalizedPath = Path.GetFullPathInternal(path);
+
+            lock(s_loadfile)
+            {          
+                if(s_loadfile.TryGetValue(normalizedPath, out result))
+                    return result;
+                AssemblyLoadContext alc = new FileLoadAssemblyLoadContext();
+                result = alc.LoadFromAssemblyPath(normalizedPath);
+                s_loadfile.Add(normalizedPath, result);
+            }
+            return result;
+#else
             new FileIOPermission(FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read, path).Demand();
             return RuntimeAssembly.nLoadFile(path, null);
+#endif
         }
 
 #if FEATURE_CAS_POLICY
@@ -824,7 +888,23 @@ namespace System.Reflection
                 throw new NotImplementedException();
             }
         }
+#elif FEATURE_CORECLR
+        public bool IsFullyTrusted
+        {
+            [SecuritySafeCritical]
+            get
+            {
+                return true;
+            }
+        }
 
+        public virtual SecurityRuleSet SecurityRuleSet
+        {
+            get
+            {
+                return SecurityRuleSet.None;
+            }
+        }
 #endif // FEATURE_CAS_POLICY
 
         // ISerializable implementation
@@ -890,8 +970,6 @@ namespace System.Reflection
             }
         }
 
-#if FEATURE_MULTIMODULE_ASSEMBLIES
-
         public Module LoadModule(String moduleName,
                                  byte[] rawModule)
         {
@@ -904,7 +982,6 @@ namespace System.Reflection
         {
             throw new NotImplementedException();
         }
-#endif //FEATURE_MULTIMODULE_ASSEMBLIES
 
         //
         // Locates a type from this assembly and creates an instance of it using
@@ -2270,7 +2347,11 @@ namespace System.Reflection
             [System.Security.SecuritySafeCritical]  // auto-generated
             get
             {
+#if FEATURE_CORECLR
+                return false;
+#else
                 return IsGlobalAssemblyCache(GetNativeHandle());
+#endif
             }
         }
 
@@ -2284,7 +2365,11 @@ namespace System.Reflection
             [System.Security.SecuritySafeCritical]  // auto-generated
             get
             {
+#if FEATURE_CORECLR
+                return 0;
+#else
                 return GetHostContext(GetNativeHandle());
+#endif
             }
         }
 
index 7552986..183d5a3 100644 (file)
@@ -476,6 +476,20 @@ namespace System.Runtime.Loader
             return null;
         }
     }
+
+    [System.Security.SecuritySafeCritical]
+    internal class FileLoadAssemblyLoadContext : AssemblyLoadContext
+    {
+        internal FileLoadAssemblyLoadContext() : base(false)
+        {
+        }
+
+        [System.Security.SecuritySafeCritical]  
+        protected override Assembly Load(AssemblyName assemblyName)
+        {
+            return null;
+        }
+    }
 }
 
 #endif // FEATURE_HOST_ASSEMBLY_RESOLVER