diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2017-06-13 18:47:36 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2017-06-13 18:47:36 +0900 |
commit | 61d6a817e39d3bae0f47dbc09838d51db22a5d30 (patch) | |
tree | cb37caa1784bc738b976273335d6ed04a7cc80b0 /src/mscorlib/src/System/Reflection | |
parent | 5b975f8233e8c8d17b215372f89ca713b45d6a0b (diff) | |
download | coreclr-61d6a817e39d3bae0f47dbc09838d51db22a5d30.tar.gz coreclr-61d6a817e39d3bae0f47dbc09838d51db22a5d30.tar.bz2 coreclr-61d6a817e39d3bae0f47dbc09838d51db22a5d30.zip |
Imported Upstream version 2.0.0.11992upstream/2.0.0.11992
Diffstat (limited to 'src/mscorlib/src/System/Reflection')
36 files changed, 98 insertions, 263 deletions
diff --git a/src/mscorlib/src/System/Reflection/Assembly.CoreCLR.cs b/src/mscorlib/src/System/Reflection/Assembly.CoreCLR.cs index 708f79b64f..9d34b48177 100644 --- a/src/mscorlib/src/System/Reflection/Assembly.CoreCLR.cs +++ b/src/mscorlib/src/System/Reflection/Assembly.CoreCLR.cs @@ -15,34 +15,78 @@ namespace System.Reflection { public abstract partial class Assembly : ICustomAttributeProvider, ISerializable { + private static volatile bool s_LoadFromResolveHandlerSetup = false; + private static object s_syncRootLoadFrom = new object(); + private static List<string> s_LoadFromAssemblyList = new List<string>(); + private static object s_syncLoadFromAssemblyList = new object(); + + private static Assembly LoadFromResolveHandler(object sender, ResolveEventArgs args) + { + Assembly requestingAssembly = args.RequestingAssembly; + + // Requesting assembly for LoadFrom is always loaded in defaultContext - proceed only if that + // is the case. + if (AssemblyLoadContext.Default != AssemblyLoadContext.GetLoadContext(requestingAssembly)) + return null; + + // Get the path where requesting assembly lives and check if it is in the list + // of assemblies for which LoadFrom was invoked. + bool fRequestorLoadedViaLoadFrom = false; + string requestorPath = Path.GetFullPath(requestingAssembly.Location); + if (string.IsNullOrEmpty(requestorPath)) + return null; + + lock(s_syncLoadFromAssemblyList) + { + fRequestorLoadedViaLoadFrom = s_LoadFromAssemblyList.Contains(requestorPath); + } + + // If the requestor assembly was not loaded using LoadFrom, exit. + if (!fRequestorLoadedViaLoadFrom) + return null; + + // Requestor assembly was loaded using loadFrom, so look for its dependencies + // in the same folder as it. + // Form the name of the assembly using the path of the assembly that requested its load. + AssemblyName requestedAssemblyName = new AssemblyName(args.Name); + string requestedAssemblyPath = Path.Combine(Path.GetDirectoryName(requestorPath), requestedAssemblyName.Name+".dll"); + + // Load the dependency via LoadFrom so that it goes through the same path of being in the LoadFrom list. + return Assembly.LoadFrom(requestedAssemblyPath); + } + public static Assembly LoadFrom(String assemblyFile) { if (assemblyFile == null) throw new ArgumentNullException(nameof(assemblyFile)); + string fullPath = Path.GetFullPath(assemblyFile); - return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath); - } - // Evidence is protected in Assembly.Load() - [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.")] - [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod - internal static Assembly LoadFrom(String assemblyFile, - Evidence securityEvidence) - { - Contract.Ensures(Contract.Result<Assembly>() != null); + if (!s_LoadFromResolveHandlerSetup) + { + lock (s_syncRootLoadFrom) + { + if (!s_LoadFromResolveHandlerSetup) + { + AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromResolveHandler); + s_LoadFromResolveHandlerSetup = true; + } + } + } - StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; + // Add the path to the LoadFrom path list which we will consult + // before handling the resolves in our handler. + lock(s_syncLoadFromAssemblyList) + { + if (!s_LoadFromAssemblyList.Contains(fullPath)) + { + s_LoadFromAssemblyList.Add(fullPath); + } + } - return RuntimeAssembly.InternalLoadFrom( - assemblyFile, - securityEvidence, - null, // hashValue - AssemblyHashAlgorithm.None, - false,// forIntrospection); - ref stackMark); + return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath); } - [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod public static Assembly LoadFrom(String assemblyFile, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) diff --git a/src/mscorlib/src/System/Reflection/AssemblyName.cs b/src/mscorlib/src/System/Reflection/AssemblyName.cs index 80fdf5d162..6bfc5b7496 100644 --- a/src/mscorlib/src/System/Reflection/AssemblyName.cs +++ b/src/mscorlib/src/System/Reflection/AssemblyName.cs @@ -27,7 +27,6 @@ namespace System.Reflection using System.Diagnostics.Contracts; using System.Text; - [Serializable] public sealed class AssemblyName : ICloneable, ISerializable, IDeserializationCallback { // @@ -279,7 +278,11 @@ namespace System.Reflection { get { - return nToString(); + if (this.Name == null) + return string.Empty; + // Do not call GetPublicKeyToken() here - that latches the result into AssemblyName which isn't a side effect we want. + byte[] pkt = _PublicKeyToken ?? nGetPublicKeyToken(); + return AssemblyNameFormatter.ComputeDisplayName(Name, Version, CultureName, pkt, Flags, ContentType); } } @@ -295,68 +298,12 @@ namespace System.Reflection public void GetObjectData(SerializationInfo info, StreamingContext context) { - if (info == null) - throw new ArgumentNullException(nameof(info)); - Contract.EndContractBlock(); - - //Allocate the serialization info and serialize our static data. - info.AddValue("_Name", _Name); - info.AddValue("_PublicKey", _PublicKey, typeof(byte[])); - info.AddValue("_PublicKeyToken", _PublicKeyToken, typeof(byte[])); -#if FEATURE_USE_LCID - info.AddValue("_CultureInfo", (_CultureInfo == null) ? -1 : _CultureInfo.LCID); -#endif - info.AddValue("_CodeBase", _CodeBase); - info.AddValue("_Version", _Version); - info.AddValue("_HashAlgorithm", _HashAlgorithm, typeof(AssemblyHashAlgorithm)); - info.AddValue("_HashAlgorithmForControl", _HashAlgorithmForControl, typeof(AssemblyHashAlgorithm)); - info.AddValue("_StrongNameKeyPair", _StrongNameKeyPair, typeof(StrongNameKeyPair)); - info.AddValue("_VersionCompatibility", _VersionCompatibility, typeof(AssemblyVersionCompatibility)); - info.AddValue("_Flags", _Flags, typeof(AssemblyNameFlags)); - info.AddValue("_HashForControl", _HashForControl, typeof(byte[])); + throw new PlatformNotSupportedException(); } public void OnDeserialization(Object sender) { - // Deserialization has already been performed - if (m_siInfo == null) - return; - - _Name = m_siInfo.GetString("_Name"); - _PublicKey = (byte[])m_siInfo.GetValue("_PublicKey", typeof(byte[])); - _PublicKeyToken = (byte[])m_siInfo.GetValue("_PublicKeyToken", typeof(byte[])); -#if FEATURE_USE_LCID - int lcid = (int)m_siInfo.GetInt32("_CultureInfo"); - if (lcid != -1) - _CultureInfo = new CultureInfo(lcid); -#endif - - _CodeBase = m_siInfo.GetString("_CodeBase"); - _Version = (Version)m_siInfo.GetValue("_Version", typeof(Version)); - _HashAlgorithm = (AssemblyHashAlgorithm)m_siInfo.GetValue("_HashAlgorithm", typeof(AssemblyHashAlgorithm)); - _StrongNameKeyPair = (StrongNameKeyPair)m_siInfo.GetValue("_StrongNameKeyPair", typeof(StrongNameKeyPair)); - _VersionCompatibility = (AssemblyVersionCompatibility)m_siInfo.GetValue("_VersionCompatibility", typeof(AssemblyVersionCompatibility)); - _Flags = (AssemblyNameFlags)m_siInfo.GetValue("_Flags", typeof(AssemblyNameFlags)); - - try - { - _HashAlgorithmForControl = (AssemblyHashAlgorithm)m_siInfo.GetValue("_HashAlgorithmForControl", typeof(AssemblyHashAlgorithm)); - _HashForControl = (byte[])m_siInfo.GetValue("_HashForControl", typeof(byte[])); - } - catch (SerializationException) - { // RTM did not have these defined - _HashAlgorithmForControl = AssemblyHashAlgorithm.None; - _HashForControl = null; - } - - m_siInfo = null; - } - - // Constructs a new AssemblyName during deserialization. - internal AssemblyName(SerializationInfo info, StreamingContext context) - { - //The graph is not valid until OnDeserialization() has been called. - m_siInfo = info; + throw new PlatformNotSupportedException(); } public AssemblyName(String assemblyName) diff --git a/src/mscorlib/src/System/Reflection/CustomAttribute.cs b/src/mscorlib/src/System/Reflection/CustomAttribute.cs index 96eb45f3e4..1cf00f17d8 100644 --- a/src/mscorlib/src/System/Reflection/CustomAttribute.cs +++ b/src/mscorlib/src/System/Reflection/CustomAttribute.cs @@ -20,7 +20,6 @@ using System.Diagnostics.Contracts; namespace System.Reflection { - [Serializable] public class CustomAttributeData { #region Public Static Members @@ -570,7 +569,6 @@ namespace System.Reflection #endregion } - [Serializable] public struct CustomAttributeNamedArgument { #region Public Static Members @@ -659,7 +657,6 @@ namespace System.Reflection } - [Serializable] public struct CustomAttributeTypedArgument { #region Public Static Members @@ -958,14 +955,12 @@ namespace System.Reflection #endregion } - [Serializable] internal struct CustomAttributeRecord { internal ConstArray blob; internal MetadataToken tkCtor; } - [Serializable] internal enum CustomAttributeEncoding : int { Undefined = 0, @@ -990,7 +985,6 @@ namespace System.Reflection Enum = 0x55 } - [Serializable] [StructLayout(LayoutKind.Auto)] internal struct CustomAttributeEncodedArgument { @@ -1045,7 +1039,6 @@ namespace System.Reflection #endregion } - [Serializable] [StructLayout(LayoutKind.Auto)] internal struct CustomAttributeNamedParameter { @@ -1077,7 +1070,6 @@ namespace System.Reflection #endregion } - [Serializable] [StructLayout(LayoutKind.Auto)] internal struct CustomAttributeCtorParameter { @@ -1099,7 +1091,6 @@ namespace System.Reflection #endregion } - [Serializable] [StructLayout(LayoutKind.Auto)] internal struct CustomAttributeType { @@ -2040,7 +2031,7 @@ namespace System.Reflection count = 0; bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType)) + if (!all && !s_pca.ContainsKey(caType) && !IsSecurityAttribute(caType)) return Array.Empty<Attribute>(); List<Attribute> pcas = new List<Attribute>(); @@ -2078,7 +2069,7 @@ namespace System.Reflection internal static bool IsDefined(RuntimeType type, RuntimeType caType) { bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType)) + if (!all && !s_pca.ContainsKey(caType) && !IsSecurityAttribute(caType)) return false; if (all || caType == (RuntimeType)typeof(SerializableAttribute)) @@ -2107,7 +2098,7 @@ namespace System.Reflection count = 0; bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType)) + if (!all && !s_pca.ContainsKey(caType) && !IsSecurityAttribute(caType)) return Array.Empty<Attribute>(); List<Attribute> pcas = new List<Attribute>(); @@ -2140,7 +2131,7 @@ namespace System.Reflection internal static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType) { bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null) + if (!all && !s_pca.ContainsKey(caType)) return false; if (all || caType == (RuntimeType)typeof(DllImportAttribute)) @@ -2170,7 +2161,7 @@ namespace System.Reflection count = 0; bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null) + if (!all && !s_pca.ContainsKey(caType)) return null; Attribute[] pcas = new Attribute[s_pcasCount]; @@ -2201,7 +2192,7 @@ namespace System.Reflection internal static bool IsDefined(RuntimeParameterInfo parameter, RuntimeType caType) { bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null) + if (!all && !s_pca.ContainsKey(caType)) return false; @@ -2231,7 +2222,7 @@ namespace System.Reflection bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType)) + if (!all && !s_pca.ContainsKey(caType) && !IsSecurityAttribute(caType)) return Array.Empty<Attribute>(); List<Attribute> pcas = new List<Attribute>(); @@ -2283,7 +2274,7 @@ namespace System.Reflection count = 0; bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null) + if (!all && !s_pca.ContainsKey(caType)) return null; Attribute[] pcas = new Attribute[s_pcasCount]; @@ -2309,7 +2300,7 @@ namespace System.Reflection internal static bool IsDefined(RuntimeFieldInfo field, RuntimeType caType) { bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null) + if (!all && !s_pca.ContainsKey(caType)) return false; if (all || caType == (RuntimeType)typeof(MarshalAsAttribute)) @@ -2334,7 +2325,7 @@ namespace System.Reflection bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null && !IsSecurityAttribute(caType)) + if (!all && !s_pca.ContainsKey(caType) && !IsSecurityAttribute(caType)) return Array.Empty<Attribute>(); List<Attribute> pcas = new List<Attribute>(); @@ -2357,7 +2348,7 @@ namespace System.Reflection { bool all = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute); - if (!all && s_pca.GetValueOrDefault(caType) == null) + if (!all && !s_pca.ContainsKey(caType)) return false; if (all || IsSecurityAttribute(caType)) diff --git a/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilderAccess.cs b/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilderAccess.cs index ead2fafcef..b096960406 100644 --- a/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilderAccess.cs +++ b/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilderAccess.cs @@ -9,7 +9,6 @@ using System; namespace System.Reflection.Emit { - [Serializable] [Flags] public enum AssemblyBuilderAccess { diff --git a/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs index 55aa5c5a8f..a36882b036 100644 --- a/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs @@ -242,6 +242,8 @@ namespace System.Reflection.Emit return m_typeBuilder.Attributes; } + public override bool IsTypeDefinition => true; + public override bool IsSZArray => false; protected override bool IsArrayImpl() diff --git a/src/mscorlib/src/System/Reflection/Emit/EventToken.cs b/src/mscorlib/src/System/Reflection/Emit/EventToken.cs index 18ec630b5f..e44dc3d0ce 100644 --- a/src/mscorlib/src/System/Reflection/Emit/EventToken.cs +++ b/src/mscorlib/src/System/Reflection/Emit/EventToken.cs @@ -18,7 +18,6 @@ using System.Reflection; namespace System.Reflection.Emit { - [Serializable] public struct EventToken { public static readonly EventToken Empty = new EventToken(); diff --git a/src/mscorlib/src/System/Reflection/Emit/FieldToken.cs b/src/mscorlib/src/System/Reflection/Emit/FieldToken.cs index 6c5d778d8f..c7450ca301 100644 --- a/src/mscorlib/src/System/Reflection/Emit/FieldToken.cs +++ b/src/mscorlib/src/System/Reflection/Emit/FieldToken.cs @@ -22,7 +22,6 @@ namespace System.Reflection.Emit // by the Metadata to represent the field. FieldTokens are generated by // Module.GetFieldToken(). There are no meaningful accessors on this class, // but it can be passed to ILGenerator which understands it's internals. - [Serializable] public struct FieldToken { public static readonly FieldToken Empty = new FieldToken(); diff --git a/src/mscorlib/src/System/Reflection/Emit/FlowControl.cs b/src/mscorlib/src/System/Reflection/Emit/FlowControl.cs index fb8564652f..531d229a5c 100644 --- a/src/mscorlib/src/System/Reflection/Emit/FlowControl.cs +++ b/src/mscorlib/src/System/Reflection/Emit/FlowControl.cs @@ -16,7 +16,6 @@ using System; namespace System.Reflection.Emit { - [Serializable] public enum FlowControl { Branch = 0, diff --git a/src/mscorlib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs index dd5ffa92a9..75e4acc903 100644 --- a/src/mscorlib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs @@ -154,6 +154,8 @@ namespace System.Reflection.Emit protected override TypeAttributes GetAttributeFlagsImpl() { return TypeAttributes.Public; } + public override bool IsTypeDefinition => false; + public override bool IsSZArray => false; protected override bool IsArrayImpl() { return false; } diff --git a/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs b/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs index 4021410a33..fa31d66f6c 100644 --- a/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs @@ -1605,7 +1605,6 @@ namespace System.Reflection.Emit * takes place. * ***************************/ - [Serializable] internal enum ScopeAction { Open = 0x0, diff --git a/src/mscorlib/src/System/Reflection/Emit/Label.cs b/src/mscorlib/src/System/Reflection/Emit/Label.cs index f6315a67d2..d67c0e6a19 100644 --- a/src/mscorlib/src/System/Reflection/Emit/Label.cs +++ b/src/mscorlib/src/System/Reflection/Emit/Label.cs @@ -26,7 +26,6 @@ namespace System.Reflection.Emit // is passed to the MethodWriter. // Labels are created by using ILGenerator.CreateLabel and their position is set // by using ILGenerator.MarkLabel. - [Serializable] public struct Label { internal int m_label; diff --git a/src/mscorlib/src/System/Reflection/Emit/MethodToken.cs b/src/mscorlib/src/System/Reflection/Emit/MethodToken.cs index 0905ac922a..9698b07333 100644 --- a/src/mscorlib/src/System/Reflection/Emit/MethodToken.cs +++ b/src/mscorlib/src/System/Reflection/Emit/MethodToken.cs @@ -18,7 +18,6 @@ using System.Reflection; namespace System.Reflection.Emit { - [Serializable] public struct MethodToken { public static readonly MethodToken Empty = new MethodToken(); diff --git a/src/mscorlib/src/System/Reflection/Emit/ModuleBuilderData.cs b/src/mscorlib/src/System/Reflection/Emit/ModuleBuilderData.cs index 4f1b8eb713..4a9b774d15 100644 --- a/src/mscorlib/src/System/Reflection/Emit/ModuleBuilderData.cs +++ b/src/mscorlib/src/System/Reflection/Emit/ModuleBuilderData.cs @@ -19,7 +19,6 @@ namespace System.Reflection.Emit // This is a package private class. This class hold all of the managed // data member for ModuleBuilder. Note that what ever data members added to // this class cannot be accessed from the EE. - [Serializable] internal class ModuleBuilderData { internal ModuleBuilderData(ModuleBuilder module, String strModuleName, String strFileName, int tkFile) diff --git a/src/mscorlib/src/System/Reflection/Emit/OpcodeType.cs b/src/mscorlib/src/System/Reflection/Emit/OpcodeType.cs index 2363d607fc..db7fa2f209 100644 --- a/src/mscorlib/src/System/Reflection/Emit/OpcodeType.cs +++ b/src/mscorlib/src/System/Reflection/Emit/OpcodeType.cs @@ -17,7 +17,6 @@ using System; namespace System.Reflection.Emit { - [Serializable] public enum OpCodeType { [Obsolete("This API has been deprecated. http://go.microsoft.com/fwlink/?linkid=14202")] diff --git a/src/mscorlib/src/System/Reflection/Emit/OperandType.cs b/src/mscorlib/src/System/Reflection/Emit/OperandType.cs index 033539b999..db113b1725 100644 --- a/src/mscorlib/src/System/Reflection/Emit/OperandType.cs +++ b/src/mscorlib/src/System/Reflection/Emit/OperandType.cs @@ -17,7 +17,6 @@ using System; namespace System.Reflection.Emit { - [Serializable] public enum OperandType { InlineBrTarget = 0, diff --git a/src/mscorlib/src/System/Reflection/Emit/PEFileKinds.cs b/src/mscorlib/src/System/Reflection/Emit/PEFileKinds.cs index f9246fce6d..f6606c477a 100644 --- a/src/mscorlib/src/System/Reflection/Emit/PEFileKinds.cs +++ b/src/mscorlib/src/System/Reflection/Emit/PEFileKinds.cs @@ -8,7 +8,6 @@ using System; namespace System.Reflection.Emit { // This Enum matchs the CorFieldAttr defined in CorHdr.h - [Serializable] public enum PEFileKinds { Dll = 0x0001, diff --git a/src/mscorlib/src/System/Reflection/Emit/ParameterToken.cs b/src/mscorlib/src/System/Reflection/Emit/ParameterToken.cs index 42f85af464..067bc2d010 100644 --- a/src/mscorlib/src/System/Reflection/Emit/ParameterToken.cs +++ b/src/mscorlib/src/System/Reflection/Emit/ParameterToken.cs @@ -20,7 +20,6 @@ namespace System.Reflection.Emit { // The ParameterToken class is an opaque representation of the Token returned // by the Metadata to represent the parameter. - [Serializable] public struct ParameterToken { public static readonly ParameterToken Empty = new ParameterToken(); diff --git a/src/mscorlib/src/System/Reflection/Emit/PropertyToken.cs b/src/mscorlib/src/System/Reflection/Emit/PropertyToken.cs index b450b198d2..02f34881f4 100644 --- a/src/mscorlib/src/System/Reflection/Emit/PropertyToken.cs +++ b/src/mscorlib/src/System/Reflection/Emit/PropertyToken.cs @@ -18,7 +18,6 @@ using System.Reflection; namespace System.Reflection.Emit { - [Serializable] public struct PropertyToken { public static readonly PropertyToken Empty = new PropertyToken(); diff --git a/src/mscorlib/src/System/Reflection/Emit/StackBehaviour.cs b/src/mscorlib/src/System/Reflection/Emit/StackBehaviour.cs index afcf2ddf0a..b9054b709e 100644 --- a/src/mscorlib/src/System/Reflection/Emit/StackBehaviour.cs +++ b/src/mscorlib/src/System/Reflection/Emit/StackBehaviour.cs @@ -17,7 +17,6 @@ using System; namespace System.Reflection.Emit { - [Serializable] public enum StackBehaviour { Pop0 = 0, diff --git a/src/mscorlib/src/System/Reflection/Emit/StringToken.cs b/src/mscorlib/src/System/Reflection/Emit/StringToken.cs index 1d90816fc6..cc5b734ae8 100644 --- a/src/mscorlib/src/System/Reflection/Emit/StringToken.cs +++ b/src/mscorlib/src/System/Reflection/Emit/StringToken.cs @@ -18,7 +18,6 @@ using System.Reflection; namespace System.Reflection.Emit { - [Serializable] public struct StringToken { internal int m_string; diff --git a/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs b/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs index 16848b43dd..ca2f7d9d6e 100644 --- a/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs +++ b/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs @@ -12,7 +12,6 @@ namespace System.Reflection.Emit using System.Diagnostics.Contracts; using CultureInfo = System.Globalization.CultureInfo; - [Serializable] internal enum TypeKind { IsArray = 1, @@ -271,6 +270,9 @@ namespace System.Reflection.Emit #endregion #region Type Overrides + + public override bool IsTypeDefinition => false; + public override bool IsSZArray => m_cRank <= 1 && m_isSzArray; public override Type MakePointerType() diff --git a/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs index a98af2bdcf..2f550a4e40 100644 --- a/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs @@ -20,7 +20,6 @@ namespace System.Reflection.Emit using System.Diagnostics.Contracts; - [Serializable] public enum PackingSize { Unspecified = 0, @@ -1109,6 +1108,8 @@ namespace System.Reflection.Emit return m_iAttr; } + public override bool IsTypeDefinition => true; + public override bool IsSZArray => false; protected override bool IsArrayImpl() diff --git a/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs b/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs index 6d46362f91..64a38b0995 100644 --- a/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs +++ b/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs @@ -189,6 +189,7 @@ namespace System.Reflection.Emit public override MemberInfo[] GetMembers(BindingFlags bindingAttr) { throw new NotSupportedException(); } protected override TypeAttributes GetAttributeFlagsImpl() { return m_type.Attributes; } + public override bool IsTypeDefinition => false; public override bool IsSZArray => false; protected override bool IsArrayImpl() { return false; } diff --git a/src/mscorlib/src/System/Reflection/Emit/TypeToken.cs b/src/mscorlib/src/System/Reflection/Emit/TypeToken.cs index 4f0c1b3dac..15a0816a50 100644 --- a/src/mscorlib/src/System/Reflection/Emit/TypeToken.cs +++ b/src/mscorlib/src/System/Reflection/Emit/TypeToken.cs @@ -19,7 +19,6 @@ using System.Threading; namespace System.Reflection.Emit { - [Serializable] public struct TypeToken { public static readonly TypeToken Empty = new TypeToken(); diff --git a/src/mscorlib/src/System/Reflection/MdFieldInfo.cs b/src/mscorlib/src/System/Reflection/MdFieldInfo.cs index 41ee4d9297..9645b7fef2 100644 --- a/src/mscorlib/src/System/Reflection/MdFieldInfo.cs +++ b/src/mscorlib/src/System/Reflection/MdFieldInfo.cs @@ -9,7 +9,6 @@ using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache; namespace System.Reflection { - [Serializable] internal sealed unsafe class MdFieldInfo : RuntimeFieldInfo, ISerializable { #region Private Data Members diff --git a/src/mscorlib/src/System/Reflection/MdImport.cs b/src/mscorlib/src/System/Reflection/MdImport.cs index a224a50513..9230ffa9ef 100644 --- a/src/mscorlib/src/System/Reflection/MdImport.cs +++ b/src/mscorlib/src/System/Reflection/MdImport.cs @@ -20,7 +20,6 @@ using System.Diagnostics.Contracts; namespace System.Reflection { - [Serializable] internal enum CorElementType : byte { End = 0x00, @@ -61,7 +60,6 @@ namespace System.Reflection Pinned = 0x45, } - [Serializable] [Flags()] internal enum MdSigCallingConvention : byte { @@ -85,7 +83,6 @@ namespace System.Reflection } - [Serializable] [Flags()] internal enum PInvokeAttributes { @@ -122,7 +119,6 @@ namespace System.Reflection } - [Serializable] [Flags()] internal enum MethodSemanticsAttributes { @@ -135,7 +131,6 @@ namespace System.Reflection } - [Serializable] internal enum MetadataTokenType { Module = 0x00000000, @@ -166,7 +161,6 @@ namespace System.Reflection Invalid = 0x7FFFFFFF, } - [Serializable] internal struct ConstArray { public IntPtr Signature { get { return m_constArray; } } @@ -191,7 +185,6 @@ namespace System.Reflection internal IntPtr m_constArray; } - [Serializable] internal struct MetadataToken { #region Implicit Cast Operators diff --git a/src/mscorlib/src/System/Reflection/MemberSerializationStringGenerator.cs b/src/mscorlib/src/System/Reflection/MemberSerializationStringGenerator.cs deleted file mode 100644 index d25c746a85..0000000000 --- a/src/mscorlib/src/System/Reflection/MemberSerializationStringGenerator.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Text; -using System.Reflection; -using System.Diagnostics; -using System.Collections.Generic; - -namespace System -{ - internal static class MemberSerializationStringGenerator - { - // - // Generate the "Signature2" binary serialization string for PropertyInfos - // - // Because the string is effectively a file format for serialized Reflection objects, it must be exactly correct. If missing - // metadata prevents generating the string, this method throws a MissingMetadata exception. - // - public static string SerializationToString(this PropertyInfo property) => ((RuntimePropertyInfo)property).SerializationToString(); - - // - // Generate the "Signature2" binary serialization string for ConstructorInfos - // - // Because the string is effectively a file format for serialized Reflection objects, it must be exactly correct. If missing - // metadata prevents generating the string, this method throws a MissingMetadata exception. - // - public static string SerializationToString(this ConstructorInfo constructor) => ((RuntimeConstructorInfo)constructor).SerializationToString(); - - // - // Generate the "Signature2" binary serialization string for MethodInfos - // - // Because the string is effectively a file format for serialized Reflection objects, it must be exactly correct. If missing - // metadata prevents generating the string, this method throws a MissingMetadata exception. - // - public static string SerializationToString(this MethodInfo method) => ((RuntimeMethodInfo)method).SerializationToString(); - } -} diff --git a/src/mscorlib/src/System/Reflection/RtFieldInfo.cs b/src/mscorlib/src/System/Reflection/RtFieldInfo.cs index 20d6e6392f..ddfc56b2aa 100644 --- a/src/mscorlib/src/System/Reflection/RtFieldInfo.cs +++ b/src/mscorlib/src/System/Reflection/RtFieldInfo.cs @@ -11,7 +11,6 @@ using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache; namespace System.Reflection { - [Serializable] internal unsafe sealed class RtFieldInfo : RuntimeFieldInfo, IRuntimeFieldInfo { #region FCalls diff --git a/src/mscorlib/src/System/Reflection/RuntimeAssembly.cs b/src/mscorlib/src/System/Reflection/RuntimeAssembly.cs index 4632525453..6737190c1c 100644 --- a/src/mscorlib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/mscorlib/src/System/Reflection/RuntimeAssembly.cs @@ -18,7 +18,6 @@ using System.Diagnostics.Contracts; namespace System.Reflection { - [Serializable] internal class RuntimeAssembly : Assembly { #if FEATURE_APPX @@ -261,15 +260,7 @@ namespace System.Reflection // ISerializable implementation public override void GetObjectData(SerializationInfo info, StreamingContext context) { - if (info == null) - throw new ArgumentNullException(nameof(info)); - - Contract.EndContractBlock(); - - UnitySerializationHolder.GetUnitySerializationInfo(info, - UnitySerializationHolder.AssemblyUnity, - this.FullName, - this); + throw new PlatformNotSupportedException(); } public override Module ManifestModule @@ -320,26 +311,6 @@ namespace System.Reflection return CustomAttributeData.GetCustomAttributesInternal(this); } - [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod - internal static RuntimeAssembly InternalLoadFrom(String assemblyFile, - Evidence securityEvidence, - byte[] hashValue, - AssemblyHashAlgorithm hashAlgorithm, - bool forIntrospection, - ref StackCrawlMark stackMark) - { - if (assemblyFile == null) - throw new ArgumentNullException(nameof(assemblyFile)); - - Contract.EndContractBlock(); - - AssemblyName an = new AssemblyName(); - an.CodeBase = assemblyFile; - an.SetHashControl(hashValue, hashAlgorithm); - // The stack mark is used for MDA filtering - return InternalLoadAssemblyName(an, securityEvidence, null, ref stackMark, true /*thrownOnFileNotFound*/, forIntrospection); - } - // Wrapper function to wrap the typical use of InternalLoad. internal static RuntimeAssembly InternalLoad(String assemblyString, Evidence assemblySecurity, diff --git a/src/mscorlib/src/System/Reflection/RuntimeConstructorInfo.cs b/src/mscorlib/src/System/Reflection/RuntimeConstructorInfo.cs index 8c3b1fce98..e0fb3ec87d 100644 --- a/src/mscorlib/src/System/Reflection/RuntimeConstructorInfo.cs +++ b/src/mscorlib/src/System/Reflection/RuntimeConstructorInfo.cs @@ -11,7 +11,6 @@ using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache; namespace System.Reflection { - [Serializable] internal sealed class RuntimeConstructorInfo : ConstructorInfo, ISerializable, IRuntimeMethodInfo { #region Private Data Members @@ -465,10 +464,7 @@ namespace System.Reflection #region ISerializable Implementation public void GetObjectData(SerializationInfo info, StreamingContext context) { - if (info == null) - throw new ArgumentNullException(nameof(info)); - Contract.EndContractBlock(); - MemberInfoSerializationHolder.GetSerializationInfo(info, this); + throw new PlatformNotSupportedException(); } internal string SerializationToString() diff --git a/src/mscorlib/src/System/Reflection/RuntimeEventInfo.cs b/src/mscorlib/src/System/Reflection/RuntimeEventInfo.cs index 930e1820bd..9e86867b6d 100644 --- a/src/mscorlib/src/System/Reflection/RuntimeEventInfo.cs +++ b/src/mscorlib/src/System/Reflection/RuntimeEventInfo.cs @@ -10,7 +10,6 @@ using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache; namespace System.Reflection { - [Serializable] internal unsafe sealed class RuntimeEventInfo : EventInfo, ISerializable { #region Private Data Members @@ -159,11 +158,7 @@ namespace System.Reflection #region ISerializable public void GetObjectData(SerializationInfo info, StreamingContext context) { - if (info == null) - throw new ArgumentNullException(nameof(info)); - Contract.EndContractBlock(); - - MemberInfoSerializationHolder.GetSerializationInfo(info, this); + throw new PlatformNotSupportedException(); } #endregion diff --git a/src/mscorlib/src/System/Reflection/RuntimeFieldInfo.cs b/src/mscorlib/src/System/Reflection/RuntimeFieldInfo.cs index 29cc97d225..e61c0922d7 100644 --- a/src/mscorlib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/mscorlib/src/System/Reflection/RuntimeFieldInfo.cs @@ -9,7 +9,6 @@ using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache; namespace System.Reflection { - [Serializable] internal abstract class RuntimeFieldInfo : FieldInfo, ISerializable { #region Private Data Members @@ -125,11 +124,7 @@ namespace System.Reflection #region ISerializable Implementation public void GetObjectData(SerializationInfo info, StreamingContext context) { - if (info == null) - throw new ArgumentNullException(nameof(info)); - Contract.EndContractBlock(); - - MemberInfoSerializationHolder.GetSerializationInfo(info, this); + throw new PlatformNotSupportedException(); } #endregion } diff --git a/src/mscorlib/src/System/Reflection/RuntimeMethodInfo.cs b/src/mscorlib/src/System/Reflection/RuntimeMethodInfo.cs index b8a2341e4e..3b2a75b1b7 100644 --- a/src/mscorlib/src/System/Reflection/RuntimeMethodInfo.cs +++ b/src/mscorlib/src/System/Reflection/RuntimeMethodInfo.cs @@ -14,7 +14,6 @@ using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache; namespace System.Reflection { - [Serializable] internal sealed class RuntimeMethodInfo : MethodInfo, ISerializable, IRuntimeMethodInfo { #region Private Data Members @@ -772,14 +771,7 @@ namespace System.Reflection #region ISerializable Implementation public void GetObjectData(SerializationInfo info, StreamingContext context) { - if (info == null) - throw new ArgumentNullException(nameof(info)); - Contract.EndContractBlock(); - - if (m_reflectedTypeCache.IsGlobal) - throw new NotSupportedException(SR.NotSupported_GlobalMethodSerialization); - - MemberInfoSerializationHolder.GetSerializationInfo(info, this); + throw new PlatformNotSupportedException(); } internal string SerializationToString() diff --git a/src/mscorlib/src/System/Reflection/RuntimeModule.cs b/src/mscorlib/src/System/Reflection/RuntimeModule.cs index 75809cba01..f9b733736d 100644 --- a/src/mscorlib/src/System/Reflection/RuntimeModule.cs +++ b/src/mscorlib/src/System/Reflection/RuntimeModule.cs @@ -12,7 +12,6 @@ using System.Diagnostics.Contracts; namespace System.Reflection { - [Serializable] internal class RuntimeModule : Module { internal RuntimeModule() { throw new NotSupportedException(); } @@ -448,12 +447,7 @@ namespace System.Reflection #region Public Virtuals public override void GetObjectData(SerializationInfo info, StreamingContext context) { - if (info == null) - { - throw new ArgumentNullException(nameof(info)); - } - Contract.EndContractBlock(); - UnitySerializationHolder.GetUnitySerializationInfo(info, UnitySerializationHolder.ModuleUnity, this.ScopeName, this.GetRuntimeAssembly()); + throw new PlatformNotSupportedException(); } public override Type GetType(String className, bool throwOnError, bool ignoreCase) diff --git a/src/mscorlib/src/System/Reflection/RuntimeParameterInfo.cs b/src/mscorlib/src/System/Reflection/RuntimeParameterInfo.cs index addf68e75d..d21af03649 100644 --- a/src/mscorlib/src/System/Reflection/RuntimeParameterInfo.cs +++ b/src/mscorlib/src/System/Reflection/RuntimeParameterInfo.cs @@ -11,7 +11,6 @@ using MdToken = System.Reflection.MetadataToken; namespace System.Reflection { - [Serializable] internal unsafe sealed class RuntimeParameterInfo : ParameterInfo, ISerializable { #region Static Members @@ -164,35 +163,7 @@ namespace System.Reflection #region VTS magic to serialize/deserialized to/from pre-Whidbey endpoints. public void GetObjectData(SerializationInfo info, StreamingContext context) { - if (info == null) - throw new ArgumentNullException(nameof(info)); - Contract.EndContractBlock(); - - // We could be serializing for consumption by a pre-Whidbey - // endpoint. Therefore we set up all the serialized fields to look - // just like a v1.0/v1.1 instance. - - // Need to set the type to ParameterInfo so that pre-Whidbey and Whidbey code - // can deserialize this. This is also why we cannot simply use [OnSerializing]. - info.SetType(typeof(ParameterInfo)); - - // Use the properties intead of the fields in case the fields haven't been et - // _importer, bExtraConstChecked, and m_cachedData don't need to be set - - // Now set the legacy fields that the current implementation doesn't - // use any more. Note that _importer is a raw pointer that should - // never have been serialized in V1. We set it to zero here; if the - // deserializer uses it (by calling GetCustomAttributes() on this - // instance) they'll AV, but at least it will be a well defined - // exception and not a random AV. - - info.AddValue("AttrsImpl", Attributes); - info.AddValue("ClassImpl", ParameterType); - info.AddValue("DefaultValueImpl", DefaultValue); - info.AddValue("MemberImpl", Member); - info.AddValue("NameImpl", Name); - info.AddValue("PositionImpl", Position); - info.AddValue("_token", m_tkParamDef); + throw new PlatformNotSupportedException(); } #endregion diff --git a/src/mscorlib/src/System/Reflection/RuntimePropertyInfo.cs b/src/mscorlib/src/System/Reflection/RuntimePropertyInfo.cs index b6a4792e4f..24f6de1e77 100644 --- a/src/mscorlib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/mscorlib/src/System/Reflection/RuntimePropertyInfo.cs @@ -12,7 +12,6 @@ using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache; namespace System.Reflection { - [Serializable] internal unsafe sealed class RuntimePropertyInfo : PropertyInfo, ISerializable { #region Private Data Members @@ -451,11 +450,7 @@ namespace System.Reflection #region ISerializable Implementation public void GetObjectData(SerializationInfo info, StreamingContext context) { - if (info == null) - throw new ArgumentNullException(nameof(info)); - Contract.EndContractBlock(); - - MemberInfoSerializationHolder.GetSerializationInfo(info, this); + throw new PlatformNotSupportedException(); } internal string SerializationToString() |