-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ReflectionOnly as serialization mode in case dynamic code runtime feature is not supported #56604
Merged
MaximLipnin
merged 6 commits into
dotnet:main
from
MaximLipnin:use_refelectiononly_for_xmlserializer
Aug 3, 2021
Merged
Use ReflectionOnly as serialization mode in case dynamic code runtime feature is not supported #56604
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee62aa7
Use ReflectionOnly as serialization mode in case dynamic code runtime…
MaximLipnin 168004e
Update src/libraries/System.Private.Xml/src/System/Xml/Serialization/…
MaximLipnin 58df21e
Remove an unnecessary internal call
MaximLipnin 88144ed
Revert Mode to usual property
MaximLipnin ffa032a
Merge branch 'main' into use_refelectiononly_for_xmlserializer
MaximLipnin 426ad9f
Make Mode property linker-friendly
MaximLipnin 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
48 changes: 48 additions & 0 deletions
48
src/tests/FunctionalTests/iOS/Simulator/XmlSerializer_Deserialize/Program.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; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Threading.Tasks; | ||
using System.Xml; | ||
using System.Xml.Schema; | ||
using System.Xml.Serialization; | ||
|
||
public static class Program | ||
{ | ||
[DllImport("__Internal")] | ||
public static extern void mono_ios_set_summary (string value); | ||
|
||
public static async Task<int> Main(string[] args) | ||
{ | ||
mono_ios_set_summary($"Starting functional test"); | ||
MaximLipnin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
using StringReader stringReader = new StringReader(@"<?xml version=""1.0"" encoding=""UTF-8""?> | ||
<TestClass> | ||
<TestData>sample</TestData> | ||
</TestClass>"); | ||
|
||
var serializer = new XmlSerializer(typeof(TestClass)); | ||
TestClass obj = (TestClass)serializer.Deserialize(stringReader); | ||
|
||
var result = obj.TestData == "sample" ? 42 : 1; | ||
|
||
Console.WriteLine("Done!"); | ||
await Task.Delay(5000); | ||
|
||
return result; | ||
} | ||
|
||
[XmlType("TestClass", AnonymousType = true, Namespace = "")] | ||
public class TestClass | ||
{ | ||
public TestClass() | ||
{ | ||
} | ||
|
||
[XmlElement("TestData")] | ||
public string TestData { get; set; } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...S/Simulator/XmlSerializer_Deserialize/iOS.Simulator.XmlSerializer_Deserialize.Test.csproj
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" TreatAsLocalProperty="MonoForceInterpreter"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<MonoForceInterpreter>false</MonoForceInterpreter> | ||
<RunAOTCompilation>true</RunAOTCompilation> | ||
<TestRuntime>true</TestRuntime> | ||
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks> | ||
<TargetOS Condition="'$(TargetOS)' == ''">iOSSimulator</TargetOS> | ||
<MainLibraryFileName>iOS.Simulator.XmlSerializer_Deserialize.Test.dll</MainLibraryFileName> | ||
<IncludesTestRunner>false</IncludesTestRunner> | ||
<ExpectedExitCode>42</ExpectedExitCode> | ||
<EnableAggressiveTrimming>true</EnableAggressiveTrimming> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
</ItemGroup> | ||
</Project> |
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.
Is it possible to return the constant directly instead of caching it in a static variable, to enable linker to trim the unreachable code?
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.
There are some tests checking for the
Mode
setter, e.g. https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs#L22-L27There 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.
Are those even used? Where are these compilation constants set?
runtime/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs
Line 21 in 8190713
cc: @StephenMolloy
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.
Ah, nevermind, there's a separate project that sets at least one of them:
runtime/src/libraries/System.Private.Xml/tests/XmlSerializer/ReflectionOnly/System.Xml.XmlSerializer.ReflectionOnly.Tests.csproj
Line 3 in 8190713
It'd be good at some point to find a way to test this while not negatively impacting the size of what we ship.
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.
Yeah, at this stage of the game, I'd stick with the original proposed change that caches the value at initialization so we maintain the ability to override when needed. (Which I believe is pretty much just testing right now.) We have a desire to potentially make the reflection-based serializer the primary option in the future, but we've got work to do to bring it up to par with the ILGen serializer before we can do that. Having a switch that is not stuck in one position is helpful.