-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Make corefx exceptions serializable and add typeforwards #24427
Make corefx exceptions serializable and add typeforwards #24427
Conversation
1d9e797
to
01ee0cc
Compare
@weshaggard ZLibException is internal in System.IO.Compression. Should we add InternalsVisible to that package or do we need to find another way? Maybe make the exception public only in the impl? |
@@ -12,6 +12,8 @@ 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] | |||
[System.Runtime.CompilerServices.TypeForwardedFrom("Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? It is still in that same assembly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good points. I will remove it
@@ -20,6 +18,8 @@ | |||
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Collections.Generic.ShortEnumEqualityComparer<>))] | |||
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Collections.Generic.LongEnumEqualityComparer<>))] | |||
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Collections.ListDictionaryInternal))] | |||
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.CultureAwareComparer))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to reorder the forwards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need and leave it as it is.
@@ -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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helpUrl [](start = 45, length = 7)
I suppose casing here is like that in order to match Desktop. Should we add a comment or something so that it doesn't get renamed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casing of the field or the string? The string matches Desktop, correct. The HelpUrl field/property is from the base type Exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the string, helpUrl
. I thought you were adding comments in other serializable types so that people won't rename strings since it would cause a compatibility with desktop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jep I will do that with another cleanup change that Stephen suggested (replacing the assemblyqualifiednames in the typeforwards with consts) in a separate PR after I finished the tests and hopefully merged it into the servicing release.
[Fact] | ||
public void AssertExceptionDeserializationFails() | ||
{ | ||
BinaryFormatterHelpers.AssertExceptionDeserializationFails<RuntimeBinderException>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be replaced with valid tests now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be replaced with generic tests in System.Runtime.Serialization.Formatters.Tests that check for the correct ctor behavior
Why are we making all the internal exceptions serializable? I'm not sure I like exposing them publicly. |
I think we can support at least some of these safely without making any new types serializable, so long as we can use defaults that the implementation would accept, and would not leave the objects in a bad state. (And what bad state is is not well defined, since this is serialization input that anyone could already give the types today -- in this context it probably means, the exception can be rethrown, and message/stack trace at least read off it.) SecurityException we csan support by just using null for AssemblyName, and default value for SecurityAction and SecurityZone (we do not have those enums, but you can have dummy private ones with just a single value to serialize). In the SecurityException serialization constructor, it already falls back to null and defaults in the error path, so it implicitly considers this a valid payload even. SqlException you just need to serialize null for "Errors". Again it looks like the code accepts null ReflectionTypeLoadException it is fine for Types to be null: the regular constructor accepts it. Similar argument for LicenseException. Also for OdbcException, the regular constructor accepts null. You would need to fake ODBC32.RETCODE by having a dummy private enum. InvalidPrinterExceptoin regular constructor throws on null, but nevertheless I think it would be reasonable to use. Of thse I think we only care about Securityexception and SqlException and possibly ReflectionTypeLoadException . |
Do you plan to include tests in this checkin? I suggest writing all the necessary tests before committing either corelib or corefx. Then commit corelib. Then roll the tests into this PR and they will pass when it picks up coreclr. |
We try to support serialization of all exceptions. This includes internal ones... |
Yes |
0ddb564
to
1afce60
Compare
Not ready for review yet I'm currently hitting a bug when compiling the System.Runtime.Serialization.Formatters.Tests project and Wes is looking into it. |
@@ -486,7 +486,7 @@ private static void SanityCheckBlob(object obj, string[] blobs) | |||
} | |||
|
|||
// Exceptions in Net Native can't be reflected and therefore skipping blob sanity check | |||
if (obj is Exception && PlatformDetection.IsNetNative) | |||
if (obj is Exception/* && PlatformDetection.IsNetNative*/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
@@ -43,7 +45,7 @@ internal SocketException(SocketError socketError) : base(GetNativeErrorForSocket | |||
protected SocketException(SerializationInfo serializationInfo, StreamingContext streamingContext) | |||
: base(serializationInfo, streamingContext) | |||
{ | |||
throw new PlatformNotSupportedException(); | |||
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"{NativeErrorCode}:{Message}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may be right, but it doesn't match desktop
All exceptions are now serializable from Desktop to Core except a few mentioned below. I had to use reflection for some. Note: I made OdbcErrorCollection serializable to support OdbcException. I think making that type serializable is safe as there aren't any other dependencies on it.
|
7a6c867
to
2e0ab37
Compare
@weshaggard I can't fix the last error happening here on my own and need your help. It seems to be related to the System.ComponentModel.DataAnnotations shim that gets created when building for uap. The shim can't be loaded, I guess something is faulted inside the testhost configuration.
|
These are the remaining errors. Everything seems related to shims... @weshaggard
|
Tracking disabled uap/uapaot because of shim assembly loading issues here: https://github.com/dotnet/corefx/issues/24916 |
They nightly uapaot build will fail with an error indicating that an exception type isn't marked as serializable. This should be fixed when this change gets ingested with the next ProjectN build into corefx: dotnet/coreclr#14716 |
* 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
* 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
* 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
* 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
…rds (#25047) * Make corefx exceptions serializable and add typeforwards (#24427) * 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 * Cleanup code in System.Runtime.Serialization.Formatters.Tests (#23940) * Cleanup code in System.Runtime.Serialization.Formatters.Tests * Moved UnitySerializationHolder serialization test to System.Runtime.Tests * Fix UpdateBlobs regression, reenabling ValueTuple tests on Core, add Dictionary<string,string> serialization test case (#24962) * Update non NetCoreApp package versions and build them
…fx#24427) * 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 Commit migrated from dotnet/corefx@e3f74de
Related: https://github.com/dotnet/corefx/issues/24424
Exceptions that are partially supported:
Exceptions that aren't supported: