This is based on the following principles:
- We should not be making changes to instance/virtual methods
in the abstract base types for Reflection. These are apis
in themselves to third party classes that subclass these types.
Even if the Runtime chooses not to make its own implementations
of these type serializable, third party classes have the right
to make that choice for themselves and build off the base class
serialization infrastructure that was shipped before.
RuntimeAssembly and RuntimeModule still override with PNSE
so we'll get the desired exception for those cases.
- The Runtime's own implementations of these types will not be
serializable. Removing all [Serializable] attributes and
serialization interfaces. Runtime types are internal types and
thus have no duty to implement ISerializable if the public
abstract base type does not.
Commit migrated from https://github.com/dotnet/coreclr/commit/
97c58ac4fce27b7796206a59eea0ca27cb49fe1a
public virtual FileStream[] GetFiles() => GetFiles(getResourceModules: false);
public virtual FileStream[] GetFiles(bool getResourceModules) { throw NotImplemented.ByDesign; }
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
+ public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { throw NotImplemented.ByDesign; }
public override string ToString()
{
public Type ResolveType(int metadataToken) => ResolveType(metadataToken, null, null);
public virtual Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) { throw NotImplemented.ByDesign; }
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
+ public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { throw NotImplemented.ByDesign; }
public override bool Equals(object o) => base.Equals(o);
public override int GetHashCode() => base.GetHashCode();
public object GetRealObject(StreamingContext context)
{
- throw new PlatformNotSupportedException();
+ // Once all the serializable fields have come in we can set up the real
+ // instance based on just two of them (MemberImpl and PositionImpl).
+
+ if (MemberImpl == null)
+ throw new SerializationException(SR.Serialization_InsufficientState);
+
+ ParameterInfo[] args = null;
+
+ switch (MemberImpl.MemberType)
+ {
+ case MemberTypes.Constructor:
+ case MemberTypes.Method:
+ if (PositionImpl == -1)
+ {
+ if (MemberImpl.MemberType == MemberTypes.Method)
+ return ((MethodInfo)MemberImpl).ReturnParameter;
+ else
+ throw new SerializationException(SR.Serialization_BadParameterInfo);
+ }
+ else
+ {
+ args = ((MethodBase)MemberImpl).GetParametersNoCopy();
+
+ if (args != null && PositionImpl < args.Length)
+ return args[PositionImpl];
+ else
+ throw new SerializationException(SR.Serialization_BadParameterInfo);
+ }
+
+ case MemberTypes.Property:
+ args = ((PropertyInfo)MemberImpl).GetIndexParameters();
+
+ if (args != null && PositionImpl > -1 && PositionImpl < args.Length)
+ return args[PositionImpl];
+ else
+ throw new SerializationException(SR.Serialization_BadParameterInfo);
+
+ default:
+ throw new SerializationException(SR.Serialization_NoParameterInfo);
+ }
}
public override string ToString() => ParameterType.FormatTypeName() + " " + Name;
using System.Diagnostics;
using System.Globalization;
-using System.Runtime.Serialization;
using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache;
namespace System.Reflection
{
- internal sealed unsafe class MdFieldInfo : RuntimeFieldInfo, ISerializable
+ internal sealed unsafe class MdFieldInfo : RuntimeFieldInfo
{
#region Private Data Members
private int m_tkField;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Globalization;
-using System.Runtime.Serialization;
using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache;
namespace System.Reflection
{
- internal sealed class RuntimeConstructorInfo : ConstructorInfo, ISerializable, IRuntimeMethodInfo
+ internal sealed class RuntimeConstructorInfo : ConstructorInfo, IRuntimeMethodInfo
{
#region Private Data Members
private volatile RuntimeType m_declaringType;
return RuntimeMethodHandle.InvokeMethod(null, null, sig, true);
}
#endregion
-
- #region ISerializable Implementation
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- internal string SerializationToString()
- {
- // We don't need the return type for constructors.
- return FormatNameAndSig(true);
- }
- #endregion
}
}
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
-using System.Runtime.Serialization;
using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache;
namespace System.Reflection
{
- internal unsafe sealed class RuntimeEventInfo : EventInfo, ISerializable
+ internal unsafe sealed class RuntimeEventInfo : EventInfo
{
#region Private Data Members
private int m_token;
internal RuntimeModule GetRuntimeModule() { return m_declaringType.GetRuntimeModule(); }
#endregion
- #region ISerializable
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
- #endregion
-
#region EventInfo Overrides
public override MethodInfo[] GetOtherMethods(bool nonPublic)
{
using System.Collections.Generic;
using System.Diagnostics.Contracts;
-using System.Runtime.Serialization;
using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache;
namespace System.Reflection
{
- internal abstract class RuntimeFieldInfo : FieldInfo, ISerializable
+ internal abstract class RuntimeFieldInfo : FieldInfo
{
#region Private Data Members
private BindingFlags m_bindingFlags;
#region FieldInfo Overrides
// All implemented on derived classes
#endregion
-
- #region ISerializable Implementation
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
- #endregion
}
}
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Globalization;
-using System.Runtime.Serialization;
using System.Security;
using System.Text;
using System.Threading;
namespace System.Reflection
{
- internal sealed class RuntimeMethodInfo : MethodInfo, ISerializable, IRuntimeMethodInfo
+ internal sealed class RuntimeMethodInfo : MethodInfo, IRuntimeMethodInfo
{
#region Private Data Members
private IntPtr m_handle;
}
#endregion
- #region ISerializable Implementation
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- internal string SerializationToString()
- {
- return ReturnType.FormatTypeName(true) + " " + FormatNameAndSig(true);
- }
- #endregion
-
#region Legacy Internal
internal static MethodBase InternalGetCurrentMethod(ref StackCrawlMark stackMark)
{
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
-using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using MdToken = System.Reflection.MetadataToken;
namespace System.Reflection
{
- internal unsafe sealed class RuntimeParameterInfo : ParameterInfo, ISerializable
+ internal unsafe sealed class RuntimeParameterInfo : ParameterInfo
{
#region Static Members
internal unsafe static ParameterInfo[] GetParameters(IRuntimeMethodInfo method, MemberInfo member, Signature sig)
}
#endregion
- #region VTS magic to serialize/deserialized to/from pre-Whidbey endpoints.
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
- #endregion
-
#region Constructor
// used by RuntimePropertyInfo
internal RuntimeParameterInfo(RuntimeParameterInfo accessor, RuntimePropertyInfo property)
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Globalization;
-using System.Runtime.Serialization;
using System.Text;
using RuntimeTypeCache = System.RuntimeType.RuntimeTypeCache;
namespace System.Reflection
{
- internal unsafe sealed class RuntimePropertyInfo : PropertyInfo, ISerializable
+ internal unsafe sealed class RuntimePropertyInfo : PropertyInfo
{
#region Private Data Members
private int m_token;
#endregion
#endregion
-
- #region ISerializable Implementation
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
-
- internal string SerializationToString()
- {
- return FormatNameAndSig(true);
- }
- #endregion
}
}
using System.Collections;
using System.Collections.Generic;
using System.Runtime;
-using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
}
internal class RuntimeType :
- System.Reflection.TypeInfo, ISerializable, ICloneable
+ System.Reflection.TypeInfo, ICloneable
{
#region Definitions
}
#endregion
- #region ISerializable
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new PlatformNotSupportedException();
- }
- #endregion
-
#region ICustomAttributeProvider
public override Object[] GetCustomAttributes(bool inherit)
{