Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a493839

Browse files
krwqViktorHofer
authored andcommitted
Merge serialization changes to 2.0.0 (#12020)
* Scale back [Serializable] on CoreCLR types (#11765) Removes SerializableAttribute from CoreCLR types not intended to be serializable as well as adding special handling to MulticastDelegate to prevent serializing delegates (which can't be correctly serialized cross platform/runtime). * ISerializable cleanup (#11873) Changes to throw PlatformNotSupportedException from ISerializable.GetObjectData and serialization constructors on non-Serializable types. Also removes private serialization constructors and some unneeded code that was used to support serializing non-serializable types. A few tests testing GetObjectData implementations are also removed. For Exception types, we call base instead of throwing from GetObjectData to be consistent with the many Exceptions that don't override GetObjectData * IDeserializationCallback cleanup Throws PlatformNotSupportedException from IDeserializationCallback and IObjectReference implementations on types that are no longer serializable. * Coretype variables renamed back to netfx counterpart for reflection based serialization (#11910) * Variables renamed for reflection based serialization * Make EqualityComparers serialize like desktop * add missing interfaces * TimeZone serializable added * Internal hashtable serializable * Removed TimeZone as serializable type * Remove Lazy<T>'s [Serializable] attribute for 2.0 For performance, Lazy was completely rewritten for .NET Core 2.0 and has an entirely different format than desktop; trying to get it to match the desktop serialization format would require either reverting or providing a complicated custom serialization/deserialization implementation to try to match. Lazy can also wrap an Exception that occurred from trying to instantiate the object, and the only exception types that are serializable as of now in core are the base Exception and AggregateException. As such, we're cutting it from the list of supported types in 2.0. An easy workaround is simply to do what the implementation does: serialize lazy.Value instead of lazy. * tiny fixes to equalitycomparer.cs * Merge pull request #11995 from ViktorHofer/SerializationFollowUp Internal hashtable serialization attribute removed * Fixes deserializaing TimeZoneInfo by putting back the IDeserializationCallback.OnDeserialization method. (#12024)
1 parent 7e94cac commit a493839

File tree

283 files changed

+605
-2670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

283 files changed

+605
-2670
lines changed

src/mscorlib/Resources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,6 +3287,9 @@
32873287
<data name="Serialization_DateTimeTicksOutOfRange" xml:space="preserve">
32883288
<value>Invalid serialized DateTime data. Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.</value>
32893289
</data>
3290+
<data name="Serialization_DelegatesNotSupported" xml:space="preserve">
3291+
<value>Serializing delegates is not supported on this platform.</value>
3292+
</data>
32903293
<data name="Serialization_InsufficientDeserializationState" xml:space="preserve">
32913294
<value>Insufficient state to deserialize the object. Missing field '{0}'. More information is needed.</value>
32923295
</data>

src/mscorlib/System.Private.CoreLib.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@
325325
<Compile Include="$(BclSourcesRoot)\System\Currency.cs" />
326326
<Compile Include="$(BclSourcesRoot)\System\Decimal.cs" />
327327
<Compile Include="$(BclSourcesRoot)\System\DefaultBinder.CanConvert.cs" />
328-
<Compile Include="$(BclSourcesRoot)\System\DelegateSerializationHolder.cs" />
329328
<Compile Include="$(BclSourcesRoot)\System\Double.cs" />
330329
<Compile Include="$(BclSourcesRoot)\System\Empty.cs" />
331330
<Compile Include="$(BclSourcesRoot)\System\Enum.cs" />
@@ -398,7 +397,6 @@
398397
<Compile Include="$(BclSourcesRoot)\System\Reflection\MdFieldInfo.cs" />
399398
<Compile Include="$(BclSourcesRoot)\System\Reflection\MdImport.cs" />
400399
<Compile Include="$(BclSourcesRoot)\System\Reflection\MemberInfo.Internal.cs" />
401-
<Compile Include="$(BclSourcesRoot)\System\Reflection\MemberSerializationStringGenerator.cs" />
402400
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodBase.CoreCLR.cs" />
403401
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodBody.cs" />
404402
<Compile Include="$(BclSourcesRoot)\System\Reflection\RtFieldInfo.cs" />
@@ -736,4 +734,4 @@
736734
<Win32Resource Condition="'$(GenerateNativeVersionInfo)'=='true'">$(IntermediateOutputPath)\System.Private.CoreLib.res</Win32Resource>
737735
</PropertyGroup>
738736
<Import Project="GenerateCompilerResponseFile.targets" />
739-
</Project>
737+
</Project>

src/mscorlib/shared/System.Private.CoreLib.Shared.projitems

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@
229229
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ManifestResourceInfo.cs" />
230230
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberFilter.cs" />
231231
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberInfo.cs" />
232-
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberInfoSerializationHolder.cs" />
233232
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberTypes.cs" />
234233
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodAttributes.cs" />
235234
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodBase.cs" />
@@ -416,7 +415,6 @@
416415
<Compile Include="$(MSBuildThisFileDirectory)System\UnauthorizedAccessException.cs"/>
417416
<Compile Include="$(MSBuildThisFileDirectory)System\UnhandledExceptionEventArgs.cs"/>
418417
<Compile Include="$(MSBuildThisFileDirectory)System\UnhandledExceptionEventHandler.cs"/>
419-
<Compile Include="$(MSBuildThisFileDirectory)System\UnitySerializationHolder.cs"/>
420418
<Compile Include="$(MSBuildThisFileDirectory)System\ValueTuple.cs"/>
421419
<Compile Include="$(MSBuildThisFileDirectory)System\Version.cs"/>
422420
<Compile Include="$(MSBuildThisFileDirectory)System\Void.cs"/>

src/mscorlib/shared/System/ApplicationException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ namespace System
2323
// ApplicationException extends but adds no new functionality to
2424
// RecoverableException.
2525
//
26-
[Serializable]
2726
public class ApplicationException : Exception
2827
{
2928
// Creates a new ApplicationException with its message string set to
@@ -51,6 +50,9 @@ public ApplicationException(String message, Exception innerException)
5150
HResult = __HResults.COR_E_APPLICATION;
5251
}
5352

54-
protected ApplicationException(SerializationInfo info, StreamingContext context) : base(info, context) { }
53+
protected ApplicationException(SerializationInfo info, StreamingContext context) : base(info, context)
54+
{
55+
throw new PlatformNotSupportedException();
56+
}
5557
}
5658
}

src/mscorlib/shared/System/ArgumentException.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace System
2020
// the contract of the method. Ideally it should give a meaningful error
2121
// message describing what was wrong and which parameter is incorrect.
2222
//
23-
[Serializable]
2423
public class ArgumentException : SystemException
2524
{
2625
private String _paramName;
@@ -65,13 +64,12 @@ public ArgumentException(String message, String paramName)
6564
protected ArgumentException(SerializationInfo info, StreamingContext context)
6665
: base(info, context)
6766
{
68-
_paramName = info.GetString("ParamName");
67+
throw new PlatformNotSupportedException();
6968
}
7069

7170
public override void GetObjectData(SerializationInfo info, StreamingContext context)
7271
{
7372
base.GetObjectData(info, context);
74-
info.AddValue("ParamName", _paramName, typeof(String));
7573
}
7674

7775
public override String Message

src/mscorlib/shared/System/ArgumentNullException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace System
1818
// The ArgumentException is thrown when an argument
1919
// is null when it shouldn't be.
2020
//
21-
[Serializable]
2221
public class ArgumentNullException : ArgumentException
2322
{
2423
// Creates a new ArgumentNullException with its message
@@ -48,6 +47,9 @@ public ArgumentNullException(String paramName, String message)
4847
HResult = __HResults.E_POINTER;
4948
}
5049

51-
protected ArgumentNullException(SerializationInfo info, StreamingContext context) : base(info, context) { }
50+
protected ArgumentNullException(SerializationInfo info, StreamingContext context) : base(info, context)
51+
{
52+
throw new PlatformNotSupportedException();
53+
}
5254
}
5355
}

src/mscorlib/shared/System/ArgumentOutOfRangeException.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace System
1818
{
1919
// The ArgumentOutOfRangeException is thrown when an argument
2020
// is outside the legal range for that argument.
21-
[Serializable]
2221
public class ArgumentOutOfRangeException : ArgumentException
2322
{
2423
private Object _actualValue;
@@ -62,13 +61,12 @@ public ArgumentOutOfRangeException(String paramName, Object actualValue, String
6261
protected ArgumentOutOfRangeException(SerializationInfo info, StreamingContext context)
6362
: base(info, context)
6463
{
65-
_actualValue = info.GetValue("ActualValue", typeof(Object));
64+
throw new PlatformNotSupportedException();
6665
}
6766

6867
public override void GetObjectData(SerializationInfo info, StreamingContext context)
6968
{
7069
base.GetObjectData(info, context);
71-
info.AddValue("ActualValue", _actualValue, typeof(Object));
7270
}
7371

7472
public override String Message

src/mscorlib/shared/System/ArithmeticException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace System
1818
// The ArithmeticException is thrown when overflow or underflow
1919
// occurs.
2020
//
21-
[Serializable]
2221
public class ArithmeticException : SystemException
2322
{
2423
// Creates a new ArithmeticException with its message string set to
@@ -46,6 +45,9 @@ public ArithmeticException(String message, Exception innerException)
4645
HResult = __HResults.COR_E_ARITHMETIC;
4746
}
4847

49-
protected ArithmeticException(SerializationInfo info, StreamingContext context) : base(info, context) { }
48+
protected ArithmeticException(SerializationInfo info, StreamingContext context) : base(info, context)
49+
{
50+
throw new PlatformNotSupportedException();
51+
}
5052
}
5153
}

src/mscorlib/shared/System/ArrayTypeMismatchException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace System
1818
// The ArrayMismatchException is thrown when an attempt to store
1919
// an object of the wrong type within an array occurs.
2020
//
21-
[Serializable]
2221
public class ArrayTypeMismatchException : SystemException
2322
{
2423
// Creates a new ArrayMismatchException with its message string set to
@@ -46,6 +45,9 @@ public ArrayTypeMismatchException(String message, Exception innerException)
4645
HResult = __HResults.COR_E_ARRAYTYPEMISMATCH;
4746
}
4847

49-
protected ArrayTypeMismatchException(SerializationInfo info, StreamingContext context) : base(info, context) { }
48+
protected ArrayTypeMismatchException(SerializationInfo info, StreamingContext context) : base(info, context)
49+
{
50+
throw new PlatformNotSupportedException();
51+
}
5052
}
5153
}

src/mscorlib/shared/System/AttributeUsageAttribute.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
namespace System
1717
{
1818
/* By default, attributes are inherited and multiple attributes are not allowed */
19-
[Serializable]
2019
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
2120
public sealed class AttributeUsageAttribute : Attribute
2221
{

0 commit comments

Comments
 (0)