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

Commit fc728f2

Browse files
committed
Add #if FEATURE_SERIALIZATION around non-functional [Serializable]
We're adding BinaryFormatter to corefx. At present, ISerializable and friends are declared in corefx rather than being exported from System.Private.Corelib. As a result, there are a fair number of types in mscorlib that try to customize their serialization, but because they're doing so using interfaces that aren't exported (and in some cases, aren't even currently compiled in), a formatter outside of Corelib sees a type as serializable but then tries to serialize it using the default rules and fails. This commit ifdefs the [Serializable] attribute on types that try to customize their serialization. If in the future we decide we want to expose ISerializable and friends from Corelib in order to enable the serialization of these types (which we'll likely want to), e.g Delegate, Exception, etc. we'll need to turn on FEATURE_SERIALIZATION for coreclr, and these will all come back automatically.
1 parent d177083 commit fc728f2

File tree

180 files changed

+719
-281
lines changed

Some content is hidden

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

180 files changed

+719
-281
lines changed

src/mscorlib/src/System/AccessViolationException.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ namespace System
1717
using System;
1818
using System.Runtime.Serialization;
1919
[System.Runtime.InteropServices.ComVisible(true)]
20+
#if FEATURE_SERIALIZATION
2021
[Serializable]
22+
#endif
2123
public class AccessViolationException : SystemException
2224
{
2325
public AccessViolationException()

src/mscorlib/src/System/AggregateException.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ namespace System
2929
/// <see cref="AggregateException"/> is used to consolidate multiple failures into a single, throwable
3030
/// exception object.
3131
/// </remarks>
32+
#if FEATURE_SERIALIZATION
3233
[Serializable]
34+
#endif
3335
[DebuggerDisplay("Count = {InnerExceptionCount}")]
3436
public class AggregateException : Exception
3537
{

src/mscorlib/src/System/AppDomain.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,21 @@ public AssemblyLoadEventArgs(Assembly loadedAssembly)
111111
#if FEATURE_CORECLR
112112
[System.Security.SecurityCritical] // auto-generated
113113
#endif
114+
#if FEATURE_SERIALIZATION
114115
[Serializable]
116+
#endif
115117
[ComVisible(true)]
116118
public delegate Assembly ResolveEventHandler(Object sender, ResolveEventArgs args);
117119

120+
#if FEATURE_SERIALIZATION
118121
[Serializable]
122+
#endif
119123
[ComVisible(true)]
120124
public delegate void AssemblyLoadEventHandler(Object sender, AssemblyLoadEventArgs args);
121125

126+
#if FEATURE_SERIALIZATION
122127
[Serializable]
128+
#endif
123129
[ComVisible(true)]
124130
public delegate void AppDomainInitializer(string[] args);
125131

src/mscorlib/src/System/AppDomainUnloadedException.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ namespace System {
1515

1616
using System.Runtime.Serialization;
1717

18-
[System.Runtime.InteropServices.ComVisible(true)]
18+
[System.Runtime.InteropServices.ComVisible(true)]
19+
#if FEATURE_SERIALIZATION
1920
[Serializable]
21+
#endif
2022
public class AppDomainUnloadedException : SystemException {
2123
public AppDomainUnloadedException()
2224
: base(Environment.GetResourceString("Arg_AppDomainUnloadedException")) {

src/mscorlib/src/System/ApplicationException.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ namespace System {
2222
// ApplicationException extends but adds no new functionality to
2323
// RecoverableException.
2424
//
25-
[System.Runtime.InteropServices.ComVisible(true)]
25+
[System.Runtime.InteropServices.ComVisible(true)]
26+
#if FEATURE_SERIALIZATION
2627
[Serializable]
28+
#endif
2729
public class ApplicationException : Exception {
2830

2931
// Creates a new ApplicationException with its message string set to

src/mscorlib/src/System/ArgumentException.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ namespace System {
2323
// the contract of the method. Ideally it should give a meaningful error
2424
// message describing what was wrong and which parameter is incorrect.
2525
//
26-
[System.Runtime.InteropServices.ComVisible(true)]
26+
[System.Runtime.InteropServices.ComVisible(true)]
27+
#if FEATURE_SERIALIZATION
2728
[Serializable]
29+
#endif
2830
public class ArgumentException : SystemException, ISerializable {
2931
private String m_paramName;
3032

src/mscorlib/src/System/ArgumentNullException.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ namespace System {
2121
// The ArgumentException is thrown when an argument
2222
// is null when it shouldn't be.
2323
//
24-
[System.Runtime.InteropServices.ComVisible(true)]
25-
[Serializable] public class ArgumentNullException : ArgumentException
24+
[System.Runtime.InteropServices.ComVisible(true)]
25+
#if FEATURE_SERIALIZATION
26+
[Serializable]
27+
#endif
28+
public class ArgumentNullException : ArgumentException
2629
{
2730
// Creates a new ArgumentNullException with its message
2831
// string set to a default message explaining an argument was null.

src/mscorlib/src/System/ArgumentOutOfRangeException.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ namespace System {
2222

2323
// The ArgumentOutOfRangeException is thrown when an argument
2424
// is outside the legal range for that argument.
25-
[System.Runtime.InteropServices.ComVisible(true)]
25+
[System.Runtime.InteropServices.ComVisible(true)]
26+
#if FEATURE_SERIALIZATION
2627
[Serializable]
28+
#endif
2729
public class ArgumentOutOfRangeException : ArgumentException, ISerializable {
2830

2931
private static volatile String _rangeMessage;

src/mscorlib/src/System/ArithmeticException.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ namespace System {
1818
// The ArithmeticException is thrown when overflow or underflow
1919
// occurs.
2020
//
21-
[System.Runtime.InteropServices.ComVisible(true)]
22-
[Serializable] public class ArithmeticException : SystemException
21+
[System.Runtime.InteropServices.ComVisible(true)]
22+
#if FEATURE_SERIALIZATION
23+
[Serializable]
24+
#endif
25+
public class ArithmeticException : SystemException
2326
{
2427
// Creates a new ArithmeticException with its message string set to
2528
// the empty string, its HRESULT set to COR_E_ARITHMETIC,

src/mscorlib/src/System/ArrayTypeMismatchException.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ 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-
[System.Runtime.InteropServices.ComVisible(true)]
21+
[System.Runtime.InteropServices.ComVisible(true)]
22+
#if FEATURE_SERIALIZATION
2223
[Serializable]
24+
#endif
2325
public class ArrayTypeMismatchException : SystemException {
2426

2527
// Creates a new ArrayMismatchException with its message string set to

0 commit comments

Comments
 (0)