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
Make corefx exceptions serializable and add typeforwards (#24427)
Browse files Browse the repository at this point in the history
* Add serializable attribute and typeforward and adding serialization impl
* Expose ZLibException in impl assembly
* Remove deserialization negative tests
* Adding tests for exceptions
* Adding SqlError data to base exception data table
* System Data Facade
* Add netfx471 blob diffs for Hashtable and ListDictionary
* Build Microsoft.NETCore.App.deps.json after manual shims
* Disable currently failing uap/uapaot tests because of shim assembly load errors
  • Loading branch information
ViktorHofer authored Oct 27, 2017
1 parent b7b3439 commit e3f74de
Show file tree
Hide file tree
Showing 112 changed files with 1,860 additions and 422 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace System.Net.NetworkInformation
/// Provides NetworkInformation exceptions to the application.
/// </para>
/// </devdoc>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public class NetworkInformationException : Win32Exception
{
/// <devdoc>
Expand All @@ -36,7 +38,6 @@ public NetworkInformationException(int errorCode) : base(errorCode)

protected NetworkInformationException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
{
throw new PlatformNotSupportedException();
}

internal NetworkInformationException(SocketError socketError) : base((int)socketError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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 Expand Up @@ -49,7 +50,6 @@ public RuntimeBinderException(string message, Exception innerException)
protected RuntimeBinderException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
throw new PlatformNotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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 Expand Up @@ -49,7 +50,6 @@ public RuntimeBinderInternalCompilerException(string message, Exception innerExc
protected RuntimeBinderInternalCompilerException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
throw new PlatformNotSupportedException();
}
}
}
5 changes: 1 addition & 4 deletions src/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='netstandard-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
<Link>Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs</Link>
</Compile>
<Compile Include="ArrayHandling.cs" />
<Compile Include="BindingErrors.cs" />
<Compile Include="CSharpArgumentInfoTests.cs" />
Expand All @@ -23,4 +20,4 @@
<Compile Include="UserDefinedShortCircuitOperators.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>
9 changes: 0 additions & 9 deletions src/Microsoft.CSharp/tests/RuntimeBinderExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Formatters.Tests;
using Xunit;

namespace Microsoft.CSharp.RuntimeBinder.Tests
Expand Down Expand Up @@ -112,11 +109,5 @@ public void NonTypeToCtor()
Func<CallSite, object, object> targ = site.Target;
AssertExtensions.Throws<ArgumentException>("Type Argument", () => targ.Invoke(site, 23));
}

[Fact]
public void AssertExceptionDeserializationFails()
{
BinaryFormatterHelpers.AssertExceptionDeserializationFails<RuntimeBinderException>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.Serialization.Formatters.Tests;
using Xunit;

namespace Microsoft.CSharp.RuntimeBinder.Tests
Expand Down Expand Up @@ -42,11 +41,5 @@ public void InnerExceptionCtor()
RuntimeBinderInternalCompilerException rbe = new RuntimeBinderInternalCompilerException(message, inner);
Assert.Same(inner, rbe.InnerException);
}

[Fact]
public void AssertExceptionDeserializationFails()
{
BinaryFormatterHelpers.AssertExceptionDeserializationFails<RuntimeBinderInternalCompilerException>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace System.ComponentModel
/// <summary>
/// The exception that is thrown for a Win32 error code.
/// </summary>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public partial class Win32Exception : ExternalException, ISerializable
{
private const int E_FAIL = unchecked((int)0x80004005);
Expand Down Expand Up @@ -53,7 +55,16 @@ public Win32Exception(string message, Exception innerException) : base(message,
NativeErrorCode = Marshal.GetLastWin32Error();
}

protected Win32Exception(SerializationInfo info, StreamingContext context) : base(info, context) { }
protected Win32Exception(SerializationInfo info, StreamingContext context) : base(info, context)
{
NativeErrorCode = info.GetInt32(nameof(NativeErrorCode));
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(NativeErrorCode), NativeErrorCode);
}

/// <summary>
/// Represents the Win32 error code associated with this exception. This field is read-only.
Expand Down
6 changes: 0 additions & 6 deletions src/Microsoft.Win32.Primitives/tests/Win32ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,5 @@ public static void InstantiateExceptionWithLongErrorString()
Assert.Equal(expected: "Unknown error (0x23)", actual: ex.Message);
}
}

[Fact]
public static void Deserialize_NetCore_ThrowsPlatformNotSupportedException()
{
BinaryFormatterHelpers.AssertExceptionDeserializationFails<Win32Exception>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@

<Target Name="GenerateTestSharedFrameworkDepsFile" DependsOnTargets="ReplaceTestingSharedFrameworkWithRestoredPackages">
<MSBuild Targets="GenerateTestSharedFrameworkDepsFile"
Projects="$(MSBuildThisFileDirectory)\..\src.builds"
Projects="$(MSBuildThisFileDirectory)\..\dirs.proj"
ContinueOnError="ErrorAndStop" />
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace System.ComponentModel.DataAnnotations
/// <summary>
/// Exception used for validation using <see cref="ValidationAttribute" />.
/// </summary>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
public class ValidationException : Exception
{
private ValidationResult _validationResult;
Expand Down Expand Up @@ -77,7 +79,6 @@ public ValidationException(string message, Exception innerException)
protected ValidationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
throw new PlatformNotSupportedException();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs">
<Link>Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs</Link>
</Compile>
<Compile Include="UIHintAttributeTests.cs" />
<Compile Include="FilterUIHintAttributeTests.cs" />
<Compile Include="DisplayAttributeTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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.Formatters.Tests;
using Xunit;

namespace System.ComponentModel.DataAnnotations.Tests
Expand Down Expand Up @@ -79,13 +78,5 @@ public static void Ctor_String_ValidationAttribute_Object(string errorMessage)
Assert.Same(validatingAttribute, ex.ValidationAttribute);
Assert.Same(value, ex.Value);
}


[Fact]
public void AssertExceptionDeserializationFails()
{
BinaryFormatterHelpers.AssertExceptionDeserializationFails<ValidationException>();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace System.ComponentModel
/// <summary>
/// <para>The exception that is thrown when using invalid arguments that are enumerators.</para>
/// </summary>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public class InvalidEnumArgumentException : ArgumentException
{
/// <summary>
Expand Down Expand Up @@ -57,7 +59,6 @@ public InvalidEnumArgumentException(string argumentName, int invalidValue, Type
/// </summary>
protected InvalidEnumArgumentException(SerializationInfo info, StreamingContext context) : base(info, context)
{
throw new PlatformNotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,6 @@ public void Ctor_NullEnumClass_ThrowsNullReferenceException()
Assert.Throws<NullReferenceException>(() => new InvalidEnumArgumentException("argumentName", 1, null));
}

[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
[ActiveIssue("https://github.com/dotnet/corefx/issues/21214", TargetFrameworkMonikers.UapAot)]
public void Deserialize_ThrowsPlatformNotSupportedException()
{
var binaryFormatter = new BinaryFormatter();
using (var stream = new MemoryStream())
{
binaryFormatter.Serialize(stream, new SubException());
stream.Position = 0;
Exception ex = Assert.Throws<TargetInvocationException>(() => binaryFormatter.Deserialize(stream));
Assert.IsType<PlatformNotSupportedException>(ex.InnerException);
}
}

[Serializable]
public class SubException : InvalidEnumArgumentException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace System.ComponentModel.Design
/// a source control program.
/// </para>
/// </summary>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public class CheckoutException : ExternalException
{
private const int E_ABORT = unchecked((int)0x80004004);
Expand Down Expand Up @@ -70,7 +72,6 @@ public CheckoutException(string message, int errorCode)
/// </summary>
protected CheckoutException(SerializationInfo info, StreamingContext context) : base(info, context)
{
throw new PlatformNotSupportedException();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace System.ComponentModel
/// <summary>
/// <para>The exception that is thrown when a thread that an operation should execute on no longer exists or is not pumping messages</para>
/// </summary>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public class InvalidAsynchronousStateException : ArgumentException
{
/// <summary>
Expand Down Expand Up @@ -38,7 +40,6 @@ public InvalidAsynchronousStateException(string message, Exception innerExceptio

protected InvalidAsynchronousStateException(SerializationInfo info, StreamingContext context) : base(info, context)
{
throw new PlatformNotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace System.ComponentModel
/// <summary>
/// <para>Represents the exception thrown when a component cannot be granted a license.</para>
/// </summary>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")] // must not, a Type is required in all constructors.
public class LicenseException : SystemException
{
Expand Down Expand Up @@ -58,7 +60,6 @@ public LicenseException(Type type, object instance, string message, Exception in
/// </summary>
protected LicenseException(SerializationInfo info, StreamingContext context) : base(info, context)
{
throw new PlatformNotSupportedException();
}

/// <summary>
Expand All @@ -72,6 +73,8 @@ protected LicenseException(SerializationInfo info, StreamingContext context) : b
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("type", null); // Type is not serializable.
info.AddValue("instance", _instance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace System.ComponentModel
/// <summary>
/// <para>Specifies an exception that is handled as a warning instead of an error.</para>
/// </summary>
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public class WarningException : SystemException
{
/// <summary>
Expand Down Expand Up @@ -66,7 +68,8 @@ public WarningException(string message, string helpUrl, string helpTopic)
/// </summary>
protected WarningException(SerializationInfo info, StreamingContext context) : base(info, context)
{
throw new PlatformNotSupportedException();
HelpUrl = (string)info.GetValue("helpUrl", typeof(string));
HelpTopic = (string)info.GetValue("helpTopic", typeof(string));
}

/// <summary>
Expand All @@ -81,12 +84,11 @@ protected WarningException(SerializationInfo info, StreamingContext context) : b
/// </summary>
public string HelpTopic { get; }

/// <summary>
/// Need this since Exception implements ISerializable.
/// </summary>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("helpUrl", HelpUrl);
info.AddValue("helpTopic", HelpTopic);
}
}
}
Loading

0 comments on commit e3f74de

Please sign in to comment.