-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
XmlSerializer support for IsDynamicCodeSupported=false #59386
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9a82ac3
XmlSerializer support for IsDynamicCodeSupported=false
eerhardt ccb3aa0
Fix a bug in XmlSerializer.CanDeserialize when in ReflectionOnly mode.
eerhardt cdd1d14
Port UAP code for CanDeserialize
eerhardt f1b0cac
PR feedback
eerhardt d6fb135
Add a linker test to ensure linker option '--enable-opt sealer' works…
eerhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/libraries/System.Private.Xml/tests/TrimmingTests/XmlSerializer.Deserialize.SealerOpt.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace System.Xml.Serialization.TrimmingTests | ||
{ | ||
/// <summary> | ||
/// Tests that using XmlSerializer with linker option '--enable-opt sealer' works | ||
/// when IsDynamicCodeSupported==false. | ||
/// </summary> | ||
internal class Program | ||
{ | ||
// Preserve these types until XmlSerializer is fully trim-safe. | ||
// see https://github.com/dotnet/runtime/issues/44768 | ||
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Response))] | ||
public static int Main() | ||
{ | ||
// simulate IsDynamicCodeSupported==false by setting the SerializationMode to ReflectionOnly | ||
const int ReflectionOnly = 1; | ||
typeof(XmlSerializer).GetField("s_mode", BindingFlags.NonPublic | BindingFlags.Static) | ||
.SetValue(null, ReflectionOnly); | ||
|
||
using StringReader stringReader = new StringReader(@"<?xml version=""1.0"" encoding=""UTF-8""?> | ||
<Response DataType=""Data""> | ||
</Response>"); | ||
|
||
Response obj = (Response)new XmlSerializer(typeof(Response)).Deserialize(stringReader); | ||
if (obj.DataType == "Data") | ||
{ | ||
return 100; | ||
} | ||
|
||
return -1; | ||
} | ||
} | ||
|
||
[Serializable] | ||
[XmlType(AnonymousType = true)] | ||
[XmlRoot(Namespace = "", IsNullable = false)] | ||
public class Response | ||
{ | ||
[XmlAttribute] | ||
public string DataType { get; set; } | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit, because we want to restructure this RefEmit/Reflection-Based dichotomy in 7.0... but SOAP mappings also trigger using reflection-based serialization. Perhaps consider using
if (!ShouldUseReflectionBasedSerialization(_mapping))
in these three constructors?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.
Since we are late in 6.0, I wanted to make the least risk change that fixes the issue. The least risk (IMO) is to use what worked in UAP and in the NativeAOT branch.
This suggestion would affect SOAP in "normal" applications, not just when
IsDynamicCodeSupported=false
. I can log an issue for someone to investigate taking this approach in 7.0.