Skip to content

Commit

Permalink
Scale back [Serializable] CoreFX types (dotnet#19742)
Browse files Browse the repository at this point in the history
* Remove SerializableAttribute from many CoreFX types that will not be serializable.

* Removes serialization tests for types that are no longer serializable and fixes serializing a couple of types. Includes marking some internal serializable types as public so that they'll be reflectible with .NET Native.

* Remove unneeded pragmas

* Update based on review comments
  • Loading branch information
morganbr authored and stephentoub committed May 16, 2017
1 parent b0900bb commit 6dd451f
Show file tree
Hide file tree
Showing 460 changed files with 42 additions and 858 deletions.
2 changes: 1 addition & 1 deletion CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Rule Id="CA2229" Action="Error" /> <!-- Serializable type doesn't have a serialization constructor -->
<Rule Id="CA2235" Action="None" /> <!-- Serializable type has non serializable field -->
<Rule Id="CA2231" Action="None" /> <!-- Overload operator equals when overriding ValueType.Equals -->
<Rule Id="CA2237" Action="Error" /> <!-- Add [Serializable] to types that implement ISerializable -->
<Rule Id="CA2237" Action="None" /> <!-- Add [Serializable] to types that implement ISerializable -->

<Rule Id="CA2200" Action="None"/> <!-- Rethrowing caught exception changes stack information -->

Expand Down
1 change: 0 additions & 1 deletion src/Common/src/System/CodeDom/CodeObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace System.CodeDom
namespace System.Runtime.Serialization
#endif
{
[Serializable]
#if !FEATURE_SERIALIZATION
public class CodeObject
#else
Expand Down
1 change: 0 additions & 1 deletion src/Common/src/System/CodeDom/CodeTypeReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ internal enum CodeTypeReferenceOptions
GenericTypeParameter = 0x00000002
}

[Serializable]
#if !FEATURE_SERIALIZATION
public class CodeTypeReference : CodeObject
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace System.CodeDom
namespace System.Runtime.Serialization
#endif
{
[Serializable]
#if !FEATURE_SERIALIZATION
public class CodeTypeReferenceCollection : CollectionBase
#else
Expand Down
1 change: 0 additions & 1 deletion src/Common/src/System/Collections/CompatibleComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace System.Collections
{
[Serializable]
internal sealed class CompatibleComparer : IEqualityComparer
{
private readonly IHashCodeProvider _hcp;
Expand Down
1 change: 0 additions & 1 deletion src/Common/src/System/Data/Common/NameValuePair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace System.Data.Common
{
[Serializable]
internal sealed class NameValuePair
{
readonly private string _name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace System.Net.NetworkInformation
/// Provides NetworkInformation exceptions to the application.
/// </para>
/// </devdoc>
[Serializable]
public class NetworkInformationException : Win32Exception
{
/// <devdoc>
Expand Down
1 change: 0 additions & 1 deletion src/Common/src/System/Text/DBCSDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace System.Text
{
[Serializable]
internal sealed class DecoderDBCS : Decoder
{
private readonly Encoding _encoding;
Expand Down
1 change: 0 additions & 1 deletion src/Common/src/System/Text/OSEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace System.Text
{
[Serializable]
internal sealed class OSEncoder : Encoder
{
private char _charLeftOver;
Expand Down
1 change: 0 additions & 1 deletion src/Common/src/System/Text/OSEncoding.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace System.Text
{
[Serializable]
internal sealed class OSEncoding : Encoding
{
private readonly int _codePage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public abstract partial class IEnumerable_Generic_Tests<T> : TestBase<T>
public void IGenericSharedAPI_SerializeDeserialize(int count)
{
IEnumerable<T> expected = GenericIEnumerableFactory(count);

// Not all IEnumerables are intended to be Serializable
if (!expected.GetType().IsSerializable)
{
return;
}

IEnumerable<T> actual = BinaryFormatterHelpers.Clone(expected);

if (Order == EnumerableOrder.Sequential)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Microsoft.CSharp.RuntimeBinder
/// <see cref="RuntimeBinderException"/> represents a failure to bind in the sense of a usual compiler error, whereas <see cref="RuntimeBinderInternalCompilerException"/>
/// represents a malfunctioning of the runtime binder itself.
/// </summary>
[Serializable]
public class RuntimeBinderException : Exception
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Microsoft.CSharp.RuntimeBinder
/// <see cref="RuntimeBinderException"/> represents a failure to bind in the sense of a usual compiler error, whereas <see cref="RuntimeBinderInternalCompilerException"/>
/// represents a malfunctioning of the runtime binder itself.
/// </summary>
[Serializable]
public class RuntimeBinderInternalCompilerException : Exception
{
/// <summary>
Expand Down
3 changes: 0 additions & 3 deletions src/Microsoft.CSharp/tests/RuntimeBinderExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public void NullaryCtor()
Assert.Empty(rbe.Data);
Assert.True((rbe.HResult & 0xFFFF0000) == 0x80130000); // Error from .NET
Assert.Contains(rbe.GetType().FullName, rbe.Message); // Localized, but should contain type name.
BinaryFormatterHelpers.AssertRoundtrips(rbe);
}

[Fact]
Expand All @@ -34,7 +33,6 @@ public void StringCtor()
Assert.Same(message, rbe.Message);
rbe = new RuntimeBinderException(null);
Assert.Equal(new RuntimeBinderException().Message, rbe.Message);
BinaryFormatterHelpers.AssertRoundtrips(rbe);
}


Expand All @@ -45,7 +43,6 @@ public void InnerExceptionCtor()
Exception inner = new Exception("This is a test exception");
RuntimeBinderException rbe = new RuntimeBinderException(message, inner);
Assert.Same(inner, rbe.InnerException);
BinaryFormatterHelpers.AssertRoundtrips(rbe);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public void NullaryCtor()
Assert.Empty(rbe.Data);
Assert.True((rbe.HResult & 0xFFFF0000) == 0x80130000); // Error from .NET
Assert.Contains(rbe.GetType().FullName, rbe.Message); // Localized, but should contain type name.
BinaryFormatterHelpers.AssertRoundtrips(rbe);
}

[Fact]
Expand All @@ -32,7 +31,6 @@ public void StringCtor()
Assert.Same(message, rbe.Message);
rbe = new RuntimeBinderInternalCompilerException(null);
Assert.Equal(new RuntimeBinderInternalCompilerException().Message, rbe.Message);
BinaryFormatterHelpers.AssertRoundtrips(rbe);
}


Expand All @@ -43,7 +41,6 @@ public void InnerExceptionCtor()
Exception inner = new Exception("This is a test exception");
RuntimeBinderInternalCompilerException rbe = new RuntimeBinderInternalCompilerException(message, inner);
Assert.Same(inner, rbe.InnerException);
BinaryFormatterHelpers.AssertRoundtrips(rbe);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace System.ComponentModel
/// <devdoc>
/// <para>The exception that is thrown for a Win32 error code.</para>
/// </devdoc>
[Serializable]
public partial class Win32Exception : ExternalException, ISerializable
{
/// <devdoc>
Expand Down
17 changes: 0 additions & 17 deletions src/Microsoft.Win32.Primitives/tests/Win32Exception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,6 @@ public static void InstantiateExceptionWithLongErrorString()
}
}

public static IEnumerable<object[]> SerializeDeserialize_MemberData()
{
yield return new object[] { new Win32Exception() };
yield return new object[] { new Win32Exception(42) };
yield return new object[] { new Win32Exception(-42) };
yield return new object[] { new Win32Exception("some message") };
yield return new object[] { new Win32Exception(42, "some message") };
yield return new object[] { new Win32Exception("some message", new InvalidOperationException()) };
}

[Theory]
[MemberData(nameof(SerializeDeserialize_MemberData))]
public static void SerializeDeserialize(Win32Exception exception)
{
BinaryFormatterHelpers.AssertRoundtrips(exception, e => e.NativeErrorCode, e => e.ErrorCode);
}

[Fact]
public static void GetObjectData_InvalidArgs_Throws()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeArgumentReferenceExpression : CodeExpression
{
private string _parameterName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeArrayCreateExpression : CodeExpression
{
private readonly CodeExpressionCollection _initializers = new CodeExpressionCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeArrayIndexerExpression : CodeExpression
{
private CodeExpressionCollection _indices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeAssignStatement : CodeStatement
{
public CodeAssignStatement() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeAttachEventStatement : CodeStatement
{
private CodeEventReferenceExpression _eventRef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeAttributeArgument
{
private string _name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeAttributeArgumentCollection : CollectionBase
{
public CodeAttributeArgumentCollection() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeAttributeDeclaration
{
private string _name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeAttributeDeclarationCollection : CollectionBase
{
public CodeAttributeDeclarationCollection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeBaseReferenceExpression : CodeExpression
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeBinaryOperatorExpression : CodeExpression
{
public CodeBinaryOperatorExpression() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeCastExpression : CodeExpression
{
private CodeTypeReference _targetType;
Expand Down
1 change: 0 additions & 1 deletion src/System.CodeDom/src/System/CodeDom/CodeCatchClause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeCatchClause
{
private CodeStatementCollection _statements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeCatchClauseCollection : CollectionBase
{
public CodeCatchClauseCollection() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeChecksumPragma : CodeDirective
{
private string _fileName;
Expand Down
1 change: 0 additions & 1 deletion src/System.CodeDom/src/System/CodeDom/CodeComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeComment : CodeObject
{
private string _text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeCommentStatement : CodeStatement
{
public CodeCommentStatement() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeCommentStatementCollection : CollectionBase
{
public CodeCommentStatementCollection() { }
Expand Down
1 change: 0 additions & 1 deletion src/System.CodeDom/src/System/CodeDom/CodeCompileUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeCompileUnit : CodeObject
{
private StringCollection _assemblies = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeConditionStatement : CodeStatement
{
public CodeConditionStatement() { }
Expand Down
1 change: 0 additions & 1 deletion src/System.CodeDom/src/System/CodeDom/CodeConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeConstructor : CodeMemberMethod
{
public CodeConstructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeDefaultValueExpression : CodeExpression
{
private CodeTypeReference _type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeDelegateCreateExpression : CodeExpression
{
private CodeTypeReference _delegateType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeDelegateInvokeExpression : CodeExpression
{
public CodeDelegateInvokeExpression() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeDirectionExpression : CodeExpression
{
public CodeDirectionExpression() { }
Expand Down
1 change: 0 additions & 1 deletion src/System.CodeDom/src/System/CodeDom/CodeDirective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace System.CodeDom
{
[Serializable]
public class CodeDirective : CodeObject
{
}
Expand Down
Loading

0 comments on commit 6dd451f

Please sign in to comment.