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

DbNull serialization with tests and forward #23897

Merged
merged 2 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ private static IEnumerable<object[]> SerializableObjects()
yield return new object[] { new SqlString(CultureInfo.InvariantCulture.LCID, SqlCompareOptions.BinarySort, new byte[] { 65, 66, 67 }, true), new string[] { "AAEAAAD/////AQAAAAAAAAAMAgAAAE5TeXN0ZW0uRGF0YSwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAAB5TeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxTdHJpbmcFAAAAB21fdmFsdWUJbV9jbXBJbmZvBm1fbGNpZAZtX2ZsYWcKbV9mTm90TnVsbAEDAAQAIFN5c3RlbS5HbG9iYWxpemF0aW9uLkNvbXBhcmVJbmZvCCZTeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxDb21wYXJlT3B0aW9ucwIAAAABAgAAAAYDAAAABuSJge+/vQp/AAAABfz///8mU3lzdGVtLkRhdGEuU3FsVHlwZXMuU3FsQ29tcGFyZU9wdGlvbnMBAAAAB3ZhbHVlX18ACAIAAAAAgAAAAQs=", "AAEAAAD/////AQAAAAAAAAAMAgAAAE5TeXN0ZW0uRGF0YSwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAAB5TeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxTdHJpbmcFAAAAB21fdmFsdWUJbV9jbXBJbmZvBm1fbGNpZAZtX2ZsYWcKbV9mTm90TnVsbAEDAAQAIFN5c3RlbS5HbG9iYWxpemF0aW9uLkNvbXBhcmVJbmZvCCZTeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxDb21wYXJlT3B0aW9ucwIAAAABAgAAAAYDAAAABuSJge+/vQp/AAAABfz///8mU3lzdGVtLkRhdGEuU3FsVHlwZXMuU3FsQ29tcGFyZU9wdGlvbnMBAAAAB3ZhbHVlX18ACAIAAAAAgAAAAQs=" } };
yield return new object[] { new SqlString(CultureInfo.InvariantCulture.LCID, SqlCompareOptions.BinarySort, new byte[] { 65, 66, 67 }, 0, 3), new string[] { "AAEAAAD/////AQAAAAAAAAAMAgAAAE5TeXN0ZW0uRGF0YSwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAAB5TeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxTdHJpbmcFAAAAB21fdmFsdWUJbV9jbXBJbmZvBm1fbGNpZAZtX2ZsYWcKbV9mTm90TnVsbAEDAAQAIFN5c3RlbS5HbG9iYWxpemF0aW9uLkNvbXBhcmVJbmZvCCZTeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxDb21wYXJlT3B0aW9ucwIAAAABAgAAAAYDAAAABuSJge+/vQp/AAAABfz///8mU3lzdGVtLkRhdGEuU3FsVHlwZXMuU3FsQ29tcGFyZU9wdGlvbnMBAAAAB3ZhbHVlX18ACAIAAAAAgAAAAQs=", "AAEAAAD/////AQAAAAAAAAAMAgAAAE5TeXN0ZW0uRGF0YSwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAAB5TeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxTdHJpbmcFAAAAB21fdmFsdWUJbV9jbXBJbmZvBm1fbGNpZAZtX2ZsYWcKbV9mTm90TnVsbAEDAAQAIFN5c3RlbS5HbG9iYWxpemF0aW9uLkNvbXBhcmVJbmZvCCZTeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxDb21wYXJlT3B0aW9ucwIAAAABAgAAAAYDAAAABuSJge+/vQp/AAAABfz///8mU3lzdGVtLkRhdGEuU3FsVHlwZXMuU3FsQ29tcGFyZU9wdGlvbnMBAAAAB3ZhbHVlX18ACAIAAAAAgAAAAQs=" } };
yield return new object[] { new SqlString(CultureInfo.InvariantCulture.LCID, SqlCompareOptions.BinarySort, new byte[] { 65, 66, 67 }, 0, 3, true), new string[] { "AAEAAAD/////AQAAAAAAAAAMAgAAAE5TeXN0ZW0uRGF0YSwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAAB5TeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxTdHJpbmcFAAAAB21fdmFsdWUJbV9jbXBJbmZvBm1fbGNpZAZtX2ZsYWcKbV9mTm90TnVsbAEDAAQAIFN5c3RlbS5HbG9iYWxpemF0aW9uLkNvbXBhcmVJbmZvCCZTeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxDb21wYXJlT3B0aW9ucwIAAAABAgAAAAYDAAAABuSJge+/vQp/AAAABfz///8mU3lzdGVtLkRhdGEuU3FsVHlwZXMuU3FsQ29tcGFyZU9wdGlvbnMBAAAAB3ZhbHVlX18ACAIAAAAAgAAAAQs=", "AAEAAAD/////AQAAAAAAAAAMAgAAAE5TeXN0ZW0uRGF0YSwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAAB5TeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxTdHJpbmcFAAAAB21fdmFsdWUJbV9jbXBJbmZvBm1fbGNpZAZtX2ZsYWcKbV9mTm90TnVsbAEDAAQAIFN5c3RlbS5HbG9iYWxpemF0aW9uLkNvbXBhcmVJbmZvCCZTeXN0ZW0uRGF0YS5TcWxUeXBlcy5TcWxDb21wYXJlT3B0aW9ucwIAAAABAgAAAAYDAAAABuSJge+/vQp/AAAABfz///8mU3lzdGVtLkRhdGEuU3FsVHlwZXMuU3FsQ29tcGFyZU9wdGlvbnMBAAAAB3ZhbHVlX18ACAIAAAAAgAAAAQs=" } };
yield return new object[] { DBNull.Value, new string[] { "AAEAAAD/////AQAAAAAAAAAEAQAAAB9TeXN0ZW0uVW5pdHlTZXJpYWxpemF0aW9uSG9sZGVyAwAAAAREYXRhCVVuaXR5VHlwZQxBc3NlbWJseU5hbWUBAAEICgIAAAAGAgAAAAAL", "AAEAAAD/////AQAAAAAAAAAEAQAAAB9TeXN0ZW0uVW5pdHlTZXJpYWxpemF0aW9uSG9sZGVyAwAAAAREYXRhCVVuaXR5VHlwZQxBc3NlbWJseU5hbWUBAAEICgIAAAAGAgAAAAAL" } };

yield return new object[] { new BigInteger(), new string[] { "AAEAAAD/////AQAAAAAAAAAMAgAAAEFTeXN0ZW0uTnVtZXJpY3MsIFZlcnNpb249NC4wLjAuMCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OQUBAAAAGlN5c3RlbS5OdW1lcmljcy5CaWdJbnRlZ2VyAgAAAAVfc2lnbgVfYml0cwAHCA8CAAAAAAAAAAoL", "AAEAAAD/////AQAAAAAAAAAMAgAAAFJTeXN0ZW0uTnVtZXJpY3MsIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAAAaU3lzdGVtLk51bWVyaWNzLkJpZ0ludGVnZXICAAAABV9zaWduBV9iaXRzAAcIDwIAAAAAAAAACgs=" } };
yield return new object[] { new BigInteger(10324176), new string[] { "AAEAAAD/////AQAAAAAAAAAMAgAAAEFTeXN0ZW0uTnVtZXJpY3MsIFZlcnNpb249NC4wLjAuMCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OQUBAAAAGlN5c3RlbS5OdW1lcmljcy5CaWdJbnRlZ2VyAgAAAAVfc2lnbgVfYml0cwAHCA8CAAAA0IidAAoL", "AAEAAAD/////AQAAAAAAAAAMAgAAAFJTeXN0ZW0uTnVtZXJpY3MsIFZlcnNpb249NC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAAAaU3lzdGVtLk51bWVyaWNzLkJpZ0ludGVnZXICAAAABV9zaWduBV9iaXRzAAcIDwIAAADQiJ0ACgs=" } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class BinaryFormatterTests : RemoteExecutorTestBase
public void ValidateBasicObjectsRoundtrip(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat)
{
object clone = BinaryFormatterHelpers.Clone(obj, null, assemblyFormat, filterLevel, typeFormat);
if (!ReferenceEquals(obj, string.Empty)) // "" is interned and will roundtrip as the same object
if (!ReferenceEquals(obj, string.Empty) && !(obj is DBNull)) // "" is interned and will roundtrip as the same object
{
Assert.NotSame(obj, clone);
}
Expand Down
1 change: 1 addition & 0 deletions src/shims/manual/mscorlib.forwards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
[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.UnitySerializationHolder))]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And any idea why I didn't need a TypeForwardedFrom attribute on the UnitySerializationHolder? Is it because it sets the type itself with SerializationInfo.SetType(Type)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'm fine with this change as it is along the lines as the other ones here. As for the TypeForwardedFrom question I'm not sure I would expect if you serialize on core it would end up with System.Private.CoreLib as the assembly it is from, is that not what is happening?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what's so interesting about it. It doesn't contain the QualifiedAssemblyName, so it's the optimized version without the attribute:

�����ÿÿÿÿ��������������System.UnitySerializationHolder�����Data UnityType
AssemblyName����
����������

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting I don't know why that is. Your the expert here now :) My only guess is that the binary serializer omits assembly names for the core assembly? Not sure though. It is probably worth debugging though the code to understand further.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a guess but need to verify it. Thanks Wes :)


// This is temporary as we are building the mscorlib shim against netfx461 which doesn't contain ValueTuples.
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.ValueTuple))]
Expand Down