From fcddeabd49c36406b561101ae25c23c48a6aa5cd Mon Sep 17 00:00:00 2001 From: Atsushi Kanamori Date: Wed, 18 Jan 2017 09:50:44 -0800 Subject: Adding ISerializable to System.Delegate/System.MulticastDelegate Doing this now because the lack of it is forcing us to spam apicompat baselines with exemptions for every delegate type in the framework. System.Delegate.GetObjectData() just throws NotSupportedException so that's easy to implement now. System.MulticastDelegate.GetObjectData() is more complicated and probably needs MethodInfo serialization to work first. So this is a stub. --- src/System.Private.CoreLib/src/System/Delegate.cs | 8 +++++++- src/System.Private.CoreLib/src/System/MulticastDelegate.cs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/System.Private.CoreLib/src/System/Delegate.cs b/src/System.Private.CoreLib/src/System/Delegate.cs index 399fd783b..7fa5553cf 100644 --- a/src/System.Private.CoreLib/src/System/Delegate.cs +++ b/src/System.Private.CoreLib/src/System/Delegate.cs @@ -5,6 +5,7 @@ using System.Text; using System.Runtime; using System.Reflection; +using System.Runtime.Serialization; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Diagnostics; @@ -19,7 +20,7 @@ namespace System // sequential layout directive so that Bartok matches it. [StructLayout(LayoutKind.Sequential)] [DebuggerDisplay("Target method(s) = {GetTargetMethodsDescriptionForDebugger()}")] - public abstract partial class Delegate : ICloneable + public abstract partial class Delegate : ICloneable, ISerializable { // This ctor exists solely to prevent C# from generating a protected .ctor that violates the surface area. I really want this to be a // "protected-and-internal" rather than "internal" but C# has no keyword for the former. @@ -707,6 +708,11 @@ namespace System return MemberwiseClone(); } + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) + { + throw new NotSupportedException(); + } + internal bool IsOpenStatic { get diff --git a/src/System.Private.CoreLib/src/System/MulticastDelegate.cs b/src/System.Private.CoreLib/src/System/MulticastDelegate.cs index 7caec691c..55b550239 100644 --- a/src/System.Private.CoreLib/src/System/MulticastDelegate.cs +++ b/src/System.Private.CoreLib/src/System/MulticastDelegate.cs @@ -3,13 +3,14 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Runtime.Serialization; using System.Runtime.CompilerServices; using Internal.Runtime.CompilerServices; namespace System { - public abstract class MulticastDelegate : Delegate + public abstract class MulticastDelegate : Delegate, ISerializable { // This ctor exists solely to prevent C# from generating a protected .ctor that violates the surface area. I really want this to be a // "protected-and-internal" rather than "internal" but C# has no keyword for the former. @@ -114,5 +115,10 @@ namespace System { return base.GetInvocationList(); } + + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + throw new NotImplementedException(); + } } } -- cgit v1.2.3 From d36cff726565d312e3c48381a15a54f7b54d02e8 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Wed, 18 Jan 2017 11:35:19 -0800 Subject: Brings over some Assembly and AssemblyName APIs [tfs-changeset: 1644899] --- .../src/System.Private.CoreLib.csproj | 1 + .../src/System/Reflection/Assembly.cs | 32 ++++++++++ .../src/System/Reflection/AssemblyName.cs | 14 +++++ .../src/System/Reflection/StrongNameKeyPair.cs | 73 ++++++++++++++++++++++ .../src/System/Security/Attributes.cs | 7 +++ 5 files changed, 127 insertions(+) create mode 100644 src/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs diff --git a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj index baf7c70b5..4998a45c6 100644 --- a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -194,6 +194,7 @@ + diff --git a/src/System.Private.CoreLib/src/System/Reflection/Assembly.cs b/src/System.Private.CoreLib/src/System/Reflection/Assembly.cs index 2405a050f..84ff35d6b 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Assembly.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Assembly.cs @@ -5,7 +5,9 @@ using System.IO; using System.Globalization; using System.Collections.Generic; +using System.Configuration.Assemblies; using System.Runtime.Serialization; +using System.Security; using Internal.Reflection.Augments; @@ -76,6 +78,8 @@ namespace System.Reflection public virtual Stream GetManifestResourceStream(string name) { throw NotImplemented.ByDesign; } public virtual Stream GetManifestResourceStream(Type type, string name) { throw NotImplemented.ByDesign; } + public bool IsFullyTrusted => true; + public virtual AssemblyName GetName() => GetName(copiedName: false); public virtual AssemblyName GetName(bool copiedName) { throw NotImplemented.ByDesign; } @@ -91,6 +95,8 @@ namespace System.Reflection public virtual object[] GetCustomAttributes(bool inherit) { throw NotImplemented.ByDesign; } public virtual object[] GetCustomAttributes(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; } + public virtual String EscapedCodeBase => AssemblyName.EscapeCodeBase(CodeBase); + public object CreateInstance(string typeName) => CreateInstance(typeName, false, BindingFlags.Public | BindingFlags.Instance, binder: null, args: null, culture: null, activationAttributes: null); public object CreateInstance(string typeName, bool ignoreCase) => CreateInstance(typeName, ignoreCase, BindingFlags.Public | BindingFlags.Instance, binder: null, args: null, culture: null, activationAttributes: null); public virtual object CreateInstance(string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes) @@ -130,6 +136,12 @@ namespace System.Reflection return displayName; } + /* + Returns true if the assembly was loaded from the global assembly cache. + */ + public virtual bool GlobalAssemblyCache { get { throw NotImplemented.ByDesign; } } + public virtual Int64 HostContext { get { throw NotImplemented.ByDesign; } } + public override bool Equals(object o) => base.Equals(o); public override int GetHashCode() => base.GetHashCode(); @@ -180,8 +192,28 @@ namespace System.Reflection return Load(name); } + public static Assembly LoadFile(String path) { throw new PlatformNotSupportedException(); } + public static Assembly LoadFrom(String assemblyFile) { throw new PlatformNotSupportedException(); } + public static Assembly LoadFrom(String assemblyFile, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { throw new PlatformNotSupportedException(); } + + [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(nameof(partialName)); + + return Load(partialName); + } + + public static Assembly UnsafeLoadFrom(string assemblyFile) => LoadFrom(assemblyFile); + + public Module LoadModule(String moduleName, byte[] rawModule) => LoadModule(moduleName, rawModule, null); + public virtual Module LoadModule(String moduleName, byte[] rawModule, byte[] rawSymbolStore) { throw NotImplemented.ByDesign; } + public static Assembly ReflectionOnlyLoad(byte[] rawAssembly) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } public static Assembly ReflectionOnlyLoad(string assemblyString) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } public static Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); } + + public virtual SecurityRuleSet SecurityRuleSet => SecurityRuleSet.None; } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs b/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs index 0eed90c2a..d4b8cebef 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs @@ -129,6 +129,18 @@ namespace System.Reflection public string CodeBase { get; set; } public AssemblyHashAlgorithm HashAlgorithm { get; set; } public AssemblyVersionCompatibility VersionCompatibility { get; set; } + public StrongNameKeyPair KeyPair { get; set; } + + public String EscapedCodeBase + { + get + { + if (CodeBase == null) + return null; + else + return EscapeCodeBase(CodeBase); + } + } public byte[] GetPublicKey() { @@ -172,6 +184,8 @@ namespace System.Reflection public static AssemblyName GetAssemblyName(String assemblyFile) { throw new NotImplementedException(); } public static bool ReferenceMatchesDefinition(AssemblyName reference, AssemblyName definition) { throw new NotImplementedException(); } + internal static String EscapeCodeBase(String codebase) { throw new PlatformNotSupportedException(); } + private AssemblyNameFlags _flags; private byte[] _publicKey; private byte[] _publicKeyToken; diff --git a/src/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs b/src/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs new file mode 100644 index 000000000..db3e92423 --- /dev/null +++ b/src/System.Private.CoreLib/src/System/Reflection/StrongNameKeyPair.cs @@ -0,0 +1,73 @@ +// 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. + +/*============================================================ +** +** +** +** +** +** Purpose: Encapsulate access to a public/private key pair +** used to sign strong name assemblies. +** +** +===========================================================*/ + +using System; +using System.Runtime.Serialization; + +namespace System.Reflection +{ + [Serializable] + public class StrongNameKeyPair : IDeserializationCallback, ISerializable + { + private bool _keyPairExported; + private byte[] _keyPairArray; + private String _keyPairContainer; + private byte[] _publicKey; + + // Build key pair from byte array in memory. + public StrongNameKeyPair(byte[] keyPairArray) + { + if (keyPairArray == null) + throw new ArgumentNullException(nameof(keyPairArray)); + + _keyPairArray = new byte[keyPairArray.Length]; + Array.Copy(keyPairArray, _keyPairArray, keyPairArray.Length); + + _keyPairExported = true; + } + + protected StrongNameKeyPair(SerializationInfo info, StreamingContext context) + { + _keyPairExported = (bool)info.GetValue("_keyPairExported", typeof(bool)); + _keyPairArray = (byte[])info.GetValue("_keyPairArray", typeof(byte[])); + _keyPairContainer = (string)info.GetValue("_keyPairContainer", typeof(string)); + _publicKey = (byte[])info.GetValue("_publicKey", typeof(byte[])); + } + + public StrongNameKeyPair(String keyPairContainer) + { + throw new PlatformNotSupportedException(); + } + + public byte[] PublicKey + { + get + { + throw new PlatformNotSupportedException(); + } + } + + void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) + { + info.AddValue("_keyPairExported", _keyPairExported); + info.AddValue("_keyPairArray", _keyPairArray); + info.AddValue("_keyPairContainer", _keyPairContainer); + info.AddValue("_publicKey", _publicKey); + } + + void IDeserializationCallback.OnDeserialization(Object sender) { } + } +} diff --git a/src/System.Private.CoreLib/src/System/Security/Attributes.cs b/src/System.Private.CoreLib/src/System/Security/Attributes.cs index 538fbf15d..fcb292cd2 100644 --- a/src/System.Private.CoreLib/src/System/Security/Attributes.cs +++ b/src/System.Private.CoreLib/src/System/Security/Attributes.cs @@ -71,4 +71,11 @@ namespace System.Security { public SecurityTransparentAttribute() { } } + + public enum SecurityRuleSet : byte + { + None = 0, + Level1 = 1, // v2.0 transparency model + Level2 = 2, // v4.0 transparency model + } } -- cgit v1.2.3