Skip to content

Make XmlSerializer work with NativeAOT #593

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

Merged
merged 2 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -228,6 +228,9 @@ The .NET Foundation licenses this file to you under the MIT license.
<IlcArg Include="@(_IlcRootedAssemblies->'--root:%(Identity)')" />
<IlcArg Include="@(_IlcConditionallyRootedAssemblies->'--conditionalroot:%(Identity)')" />

<!-- The Emit-based XmlSerializer won't work -->
<IlcArg Include="--feature:System.Xml.Serialization.XmlSerializer.IsReflectionOnly=true" />

<!-- Workaround for https://github.com/dotnet/corefx/issues/36723 -->
<IlcArg Include="--removefeature:SerializationGuard" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ protected override void ProcessField(FieldDesc field)

private object TryCreateSubstitution(TypeDesc type, string value)
{
switch (type.Category)
switch (type.UnderlyingType.Category)
{
case TypeFlags.Int32:
if (string.IsNullOrEmpty(value))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<linker>
<type fullname="System.Xml.Serialization.XmlSerializer" featurevalue="true" feature="System.Xml.Serialization.XmlSerializer.IsReflectionOnly">
<method signature="System.Xml.Serialization.SerializationMode get_Mode()" body="stub" value="1" />
</type>
</linker>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ILLinkSubstitutionsXmls Include="ILLink\ILLink.Substitutions.xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(CommonPath)System\Text\StringBuilderCache.cs" Link="Common\System\StringBuilderCache.cs" />
<Compile Include="$(CommonPath)System\HexConverter.cs" Link="Common\System\HexConverter.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ public XmlSerializer(Type type, string? defaultNamespace)
_primitiveType = type;
return;
}

if (Mode == SerializationMode.ReflectionOnly)
{
return;
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to also execute GetTopLevelMapping at the very bottom of the method in ReflectionOnly mode?

Copy link
Member Author

Choose a reason for hiding this comment

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

}

_tempAssembly = s_cache[defaultNamespace, type];
if (_tempAssembly == null)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to fix XmlSerializer(XmlTypeMapping xmlTypeMapping) constructor in the same way?

Copy link
Member Author

Choose a reason for hiding this comment

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

Welp, I haven't done a full audit of what were all of the deleted ifdefs doing. This is more of an emergency fix to see what else the partner team is going to hit. We could file an issue to do a full audit.

Copy link
Member Author

Choose a reason for hiding this comment

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

{
Expand Down