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

Scale back [Serializable] on CoreCLR types #11765

Merged
merged 2 commits into from
May 24, 2017

Conversation

morganbr
Copy link

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).

This is the first CoreCLR portion of https://github.com/dotnet/corefx/issues/19119.

Please do not merge until dotnet/corefx#20035 is merged since those are the test changes that match this change.

…erializable as well as adding special handling to MulticastDelegate to prevent serializing delegates (which can't be correctly serialized cross platform/runtime).
@morganbr morganbr added this to the 2.0.0 milestone May 20, 2017
@morganbr morganbr self-assigned this May 20, 2017
@morganbr
Copy link
Author

CC @dotnet/corert-contrib

Copy link
Member

@danmoseley danmoseley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I checked the types you removed it from but not which ones you didn't.

@@ -9,7 +9,6 @@
namespace System
{
//Marked serializable even though it has no state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is no longer applicable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@@ -18,9 +18,6 @@ namespace System.Diagnostics.Tracing
/// <summary>
/// Exception that is thrown when an error occurs during EventSource operation.
/// </summary>
#if !ES_BUILD_PCL
[Serializable]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think that this should stay, but under different ifdef. @brianrob ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the EventSourceException is Serializable because we require all Exceptions to be serializable on the Desktop runtime to support Exceptions traveling across AppDomain boundaries.

EventSource is unusual, in that at least at one time we tried to keep the source code the same on Desktop and CoreCLR (however because shiproom would wanted only changes that were in response to a particular request to change the desktop, the code bases are NOT in sync today). Still it may still be useful to keep open the option of a 'bulk update' (I think it is still true that we COULD simply copy the contents to the desktop and it would be 'correct'. Removing [Serializable] for the desktop build would break that.

I looked and we don't have a #ifdef that means' Desktop. The closest thing we have is 'not coreCLR or Project N or not Portable'

#if !CORECLR && !ES_BUILD_PN && !ES_BUILD_PCL

This is my recommendation. Simply surround the [serialable] with this instead.

Copy link
Member

@brianrob brianrob May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of things to be aware of:

  1. This is shared source so it will sync to CoreRT and ProjectN as well. You'll want to make sure that you have the proper !CORERT ifdef as well if you care about CoreRT.
  2. EventSource tests are located in CoreFx. Before you submit, you should request that CoreFX tests be run against this change. These are the trigger phrases you want to use:

@dotnet-bot test Ubuntu x64 corefx_baseline
@dotnet-bot test Windows_NT x64 corefx_baseline

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've added @vancem 's suggested ifdef along with !CORERT.

@brianrob , I've been testing this against CoreFX and modified tests appropriately so that it works. That change was dotnet/corefx#20035.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks.

@@ -134,7 +132,6 @@ public override int Compare(T x, T y)
// since we want to serialize as ObjectComparer for
// back-compat reasons (see below).

[Serializable]
internal sealed class Int32EnumComparer<T> : Comparer<T>, ISerializable where T : struct
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these need to remain serializable to make the Comparer<T> serialization work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect so. I seem to remember adding these explicitly in response to a bug, and adding tests for them in corefx.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks plausible. I've added them.

@@ -12,7 +12,6 @@

namespace System
{
[Serializable]
// Holds classes (Empty, Null, Missing) for which we guarantee that there is only ever one instance of.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole file should be deleted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll include that with general ISerializable cleanup (I've updated https://github.com/dotnet/corefx/issues/19119 to include that)

@@ -9,7 +9,6 @@

namespace System.Reflection
{
[Serializable]
#if CORECLR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole file should be deleted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll include that with general ISerializable cleanup (I've updated dotnet/corefx#19119 to include that)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you get rid of this file, you can get rid of

src\System\Reflection\MemberSerializationStringGenerator.cs

too. There are versions of this file in both CoreCLR and CoreRT.

Copy link
Member

@ViktorHofer ViktorHofer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked into all changes - LGTM

@morganbr
Copy link
Author

@dotnet-bot test Windows_NT x64 CoreCLR Perf Tests Correctness
@dotnet-bot test Windows_NT x64 CoreCLR Perf Tests Correctness

@brianrob
Copy link
Member

FYI, the perf correctness failures are tracked by https://github.com/dotnet/coreclr/issues/11856.

@morganbr
Copy link
Author

@brianrob , thanks. I'll go ahead and merge then since previous CIs succeeded and #11856 hasn't been fixed yet.

@morganbr morganbr merged commit ebda0e6 into dotnet:master May 24, 2017
dotnet-bot pushed a commit to dotnet/corert that referenced this pull request May 24, 2017
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).

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
jkotas pushed a commit to dotnet/corert that referenced this pull request May 24, 2017
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).

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
krwq pushed a commit to krwq/coreclr that referenced this pull request May 31, 2017
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).
ViktorHofer pushed a commit that referenced this pull request Jun 1, 2017
* 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)
aignas added a commit to aignas/mathnet-numerics that referenced this pull request Aug 21, 2017
Apparently, the serialization support for `System.Random` is not present
in `netstandard1.3` and even though it was added at some point, it is
again removed from the future `netstandard` versions.

See the following PR for more info:
dotnet/coreclr#11765
@karelz karelz modified the milestones: 2.1.0, 2.0.0 Aug 28, 2017
@karelz
Copy link
Member

karelz commented Aug 28, 2017

Ported to 2.0.0 in #12020

aignas added a commit to aignas/mathnet-numerics that referenced this pull request Nov 2, 2017
Apparently, the serialization support for `System.Random` is not present
in `netstandard1.3` and even though it was added at some point, it is
again removed from the future `netstandard` versions.

See the following PR for more info:
dotnet/coreclr#11765
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants