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

Commit

Permalink
Fix missing ISerializable interface on some types in System.Drawing (#…
Browse files Browse the repository at this point in the history
…22982)

* Fix missing ISerializable interface on some types in System.Drawing. Fixes #22599.

* Fix PR comments

* Fix InvalidPrinterException constructor

* Update System.Drawing.Common refs and ApiCompat file

* Move InvalidPrinterException serialization code into common code compilation itemgroup instead of windows only

* Correctly throw PNSE in unsupported ctor and cleanup code
  • Loading branch information
DonaldHarris authored and danmoseley committed Aug 17, 2017
1 parent 6d7be63 commit 171820d
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 18 deletions.
19 changes: 15 additions & 4 deletions src/System.Drawing.Common/ref/System.Drawing.Common.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ------------------------------------------------------------------------------
// Changes to this file must follow the http://aka.ms/api-review process
// ------------------------------------------------------------------------------

namespace System.Drawing
{
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
Expand Down Expand Up @@ -283,7 +290,7 @@ public enum CopyPixelOperation
Whiteness = 16711778,
}
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public sealed partial class Font : System.MarshalByRefObject, System.ICloneable, System.IDisposable
public sealed partial class Font : System.MarshalByRefObject, System.ICloneable, System.IDisposable, Runtime.Serialization.ISerializable
{
public Font(System.Drawing.Font prototype, System.Drawing.FontStyle newStyle) { }
public Font(System.Drawing.FontFamily family, float emSize) { }
Expand Down Expand Up @@ -340,6 +347,7 @@ public void Dispose() { }
public float GetHeight() { throw null; }
public float GetHeight(System.Drawing.Graphics graphics) { throw null; }
public float GetHeight(float dpi) { throw null; }
void Runtime.Serialization.ISerializable.GetObjectData(Runtime.Serialization.SerializationInfo info, Runtime.Serialization.StreamingContext context) { }
public System.IntPtr ToHfont() { throw null; }
public void ToLogFont(object logFont) { }
public void ToLogFont(object logFont, System.Drawing.Graphics graphics) { }
Expand Down Expand Up @@ -645,7 +653,7 @@ public enum GraphicsUnit
Point = 3,
World = 0,
}
public sealed partial class Icon : System.MarshalByRefObject, System.ICloneable, System.IDisposable
public sealed partial class Icon : System.MarshalByRefObject, System.ICloneable, System.IDisposable, Runtime.Serialization.ISerializable
{
public Icon(System.Drawing.Icon original, System.Drawing.Size size) { }
public Icon(System.Drawing.Icon original, int width, int height) { }
Expand All @@ -668,6 +676,7 @@ public void Dispose() { }
public static System.Drawing.Icon ExtractAssociatedIcon(string filePath) { throw null; }
~Icon() { }
public static System.Drawing.Icon FromHandle(System.IntPtr handle) { throw null; }
void Runtime.Serialization.ISerializable.GetObjectData(Runtime.Serialization.SerializationInfo info, Runtime.Serialization.StreamingContext context) { }
public void Save(System.IO.Stream outputStream) { }
[System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags=(System.Security.Permissions.SecurityPermissionFlag)(128))]
public System.Drawing.Bitmap ToBitmap() { throw null; }
Expand All @@ -684,7 +693,7 @@ public partial interface IDeviceContext : System.IDisposable
}
[System.ComponentModel.ImmutableObjectAttribute(true)]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public abstract partial class Image : System.MarshalByRefObject, System.ICloneable, System.IDisposable
public abstract partial class Image : System.MarshalByRefObject, System.ICloneable, System.IDisposable, Runtime.Serialization.ISerializable
{
internal Image() { }
[System.ComponentModel.BrowsableAttribute(false)]
Expand Down Expand Up @@ -728,6 +737,7 @@ protected virtual void Dispose(bool disposing) { }
public System.Drawing.RectangleF GetBounds(ref System.Drawing.GraphicsUnit pageUnit) { throw null; }
public System.Drawing.Imaging.EncoderParameters GetEncoderParameterList(System.Guid encoder) { throw null; }
public int GetFrameCount(System.Drawing.Imaging.FrameDimension dimension) { throw null; }
void Runtime.Serialization.ISerializable.GetObjectData(Runtime.Serialization.SerializationInfo info, Runtime.Serialization.StreamingContext context) { }
public static int GetPixelFormatSize(System.Drawing.Imaging.PixelFormat pixfmt) { throw null; }
public System.Drawing.Imaging.PropertyItem GetPropertyItem(int propid) { throw null; }
public System.Drawing.Image GetThumbnailImage(int thumbWidth, int thumbHeight, System.Drawing.Image.GetThumbnailImageAbort callback, System.IntPtr callbackData) { throw null; }
Expand Down Expand Up @@ -2530,6 +2540,7 @@ public enum Duplex
}
public partial class InvalidPrinterException : System.SystemException
{
protected InvalidPrinterException(Runtime.Serialization.SerializationInfo info, Runtime.Serialization.StreamingContext context) { }
public InvalidPrinterException(System.Drawing.Printing.PrinterSettings settings) { }
}
public partial class Margins : System.ICloneable
Expand Down Expand Up @@ -3157,4 +3168,4 @@ public ToolboxComponentsCreatingEventArgs(System.ComponentModel.Design.IDesigner
}
*/
*/
4 changes: 4 additions & 0 deletions src/System.Drawing.Common/src/System.Drawing.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<Compile Include="System\Drawing\PropertyItemInternal.cs" />
<Compile Include="System\Drawing\Printing\Duplex.cs" />
<Compile Include="System\Drawing\Printing\InvalidPrinterException.cs" />
<Compile Include="System\Drawing\Printing\InvalidPrinterException.NotSerializable.cs" />
<Compile Include="System\Drawing\Printing\Margins.cs" />
<Compile Include="System\Drawing\Printing\PaperKinds.cs" />
<Compile Include="System\Drawing\Printing\PaperSize.cs" />
Expand Down Expand Up @@ -199,12 +200,15 @@
<Compile Include="System\Drawing\Drawing2D\Matrix.cs" />
<Compile Include="System\Drawing\Drawing2D\PathGradientBrush.cs" />
<Compile Include="System\Drawing\Font.cs" />
<Compile Include="System\Drawing\Font.NotSerializable.cs" />
<Compile Include="System\Drawing\FontFamily.cs" />
<Compile Include="System\Drawing\GdiplusNative.Windows.cs" />
<Compile Include="System\Drawing\Graphics.cs" />
<Compile Include="System\Drawing\GraphicsContext.cs" />
<Compile Include="System\Drawing\Icon.cs" />
<Compile Include="System\Drawing\Icon.NotSerializable.cs" />
<Compile Include="System\Drawing\Image.cs" />
<Compile Include="System\Drawing\Image.NotSerializable.cs" />
<Compile Include="System\Drawing\ImageAnimator.cs" />
<Compile Include="System\Drawing\ImageInfo.cs" />
<Compile Include="System\Drawing\Imaging\BitmapData.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Serialization;

namespace System.Drawing
{
partial class Font
{
void ISerializable.GetObjectData(SerializationInfo si, StreamingContext context)
{
throw new PlatformNotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace System.Drawing
{
[Serializable]
partial class Font : ISerializable
partial class Font
{
private Font(SerializationInfo info, StreamingContext context)
{
Expand Down
3 changes: 2 additions & 1 deletion src/System.Drawing.Common/src/System/Drawing/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
using System.Drawing.Internal;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;

namespace System.Drawing
{
/// <summary>
/// Defines a particular format for text, including font face, size, and style attributes.
/// </summary>
[ComVisible(true)]
public sealed partial class Font : MarshalByRefObject, ICloneable, IDisposable
public sealed partial class Font : MarshalByRefObject, ICloneable, IDisposable, ISerializable
{
private const int LogFontCharSetOffset = 23;
private const int LogFontNameOffset = 28;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Serialization;

namespace System.Drawing
{
partial class Icon
{
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
throw new PlatformNotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace System.Drawing
{
[Serializable]
partial class Icon : ISerializable
partial class Icon
{
private Icon(SerializationInfo info, StreamingContext context)
{
Expand Down
3 changes: 2 additions & 1 deletion src/System.Drawing.Common/src/System/Drawing/Icon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
using System.Drawing.Internal;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Text;

namespace System.Drawing
{
public sealed partial class Icon : MarshalByRefObject, ICloneable, IDisposable
public sealed partial class Icon : MarshalByRefObject, ICloneable, IDisposable, ISerializable
{
#if FINALIZATION_WATCH
private string allocationSite = Graphics.GetAllocationStack();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Serialization;

namespace System.Drawing
{
partial class Image
{
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
throw new PlatformNotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace System.Drawing
{
[Serializable]
partial class Image : ISerializable
partial class Image
{
#pragma warning disable CA2229
internal Image(SerializationInfo info, StreamingContext context)
Expand Down
3 changes: 2 additions & 1 deletion src/System.Drawing.Common/src/System/Drawing/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;

namespace System.Drawing
{
Expand All @@ -17,7 +18,7 @@ namespace System.Drawing
/// </summary>
[ImmutableObject(true)]
[ComVisible(true)]
public abstract partial class Image : MarshalByRefObject, ICloneable, IDisposable
public abstract partial class Image : MarshalByRefObject, ICloneable, IDisposable, ISerializable
{
#if FINALIZATION_WATCH
private string allocationSite = Graphics.GetAllocationStack();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Serialization;

namespace System.Drawing.Printing
{
partial class InvalidPrinterException
{
protected InvalidPrinterException(SerializationInfo info, StreamingContext context) : base(info, context)
{
throw new PlatformNotSupportedException();
}
}
}
9 changes: 1 addition & 8 deletions src/shims/ApiCompatBaseline.netcoreapp.netfx461.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ MembersMustExist : Member 'System.DirectoryServices.Protocols.ModifyDNRequest.To
MembersMustExist : Member 'System.DirectoryServices.Protocols.ModifyRequest.ToXmlNode(System.Xml.XmlDocument)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.DirectoryServices.Protocols.SearchRequest..ctor(System.String, System.Xml.XmlDocument, System.DirectoryServices.Protocols.SearchScope, System.String[])' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.DirectoryServices.Protocols.SearchRequest.ToXmlNode(System.Xml.XmlDocument)' does not exist in the implementation but it does exist in the contract.
Compat issues with assembly System.Drawing:
CannotRemoveBaseTypeOrInterface : Type 'System.Drawing.Bitmap' does not implement interface 'System.Runtime.Serialization.ISerializable' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Drawing.Font' does not implement interface 'System.Runtime.Serialization.ISerializable' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Drawing.Icon' does not implement interface 'System.Runtime.Serialization.ISerializable' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Drawing.Image' does not implement interface 'System.Runtime.Serialization.ISerializable' in the implementation but it does in the contract.
CannotRemoveBaseTypeOrInterface : Type 'System.Drawing.Imaging.Metafile' does not implement interface 'System.Runtime.Serialization.ISerializable' in the implementation but it does in the contract.
MembersMustExist : Member 'System.Drawing.Printing.InvalidPrinterException..ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' does not exist in the implementation but it does exist in the contract.
Compat issues with assembly System.Security:
MembersMustExist : Member 'System.Security.Cryptography.CryptographicAttributeObjectCollection.IsSynchronized.get()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Security.Cryptography.CryptographicAttributeObjectCollection.SyncRoot.get()' does not exist in the implementation but it does exist in the contract.
Expand Down Expand Up @@ -319,4 +312,4 @@ TypesMustExist : Type 'System.Windows.Threading.DispatcherUnhandledExceptionEven
TypesMustExist : Type 'System.Windows.Threading.DispatcherUnhandledExceptionEventHandler' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'System.Windows.Threading.DispatcherUnhandledExceptionFilterEventArgs' does not exist in the implementation but it does exist in the contract.
TypesMustExist : Type 'System.Windows.Threading.DispatcherUnhandledExceptionFilterEventHandler' does not exist in the implementation but it does exist in the contract.
Total Issues: 306
Total Issues: 300

0 comments on commit 171820d

Please sign in to comment.