Skip to content
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

DataContractSerialization doesn't work with TrimMode - link #42824

Merged
merged 2 commits into from
Sep 30, 2020

Conversation

eerhardt
Copy link
Member

DataContractSerialization has some Reflection "shim" methods that the ILLinker can't see through. This causes critical methods to be trimmed and applications to fail. These methods were put in place in .NET Core 1.0 when the full Reflection API wasn't available.

The fix is to remove these "shim" Reflection APIs and use Reflection directly.

Fix #41525
Fix #42754

DataContractSerialization has some Reflection "shim" methods that the ILLinker can't see through. This causes critical methods to be trimmed and applications to fail. These methods were put in place in .NET Core 1.0 when the full Reflection API wasn't available.

The fix is to remove these "shim" Reflection APIs and use Reflection directly.

Fix dotnet#41525
Fix dotnet#42754
@@ -38,7 +38,7 @@ private static MethodInfo ObjectEquals
{
if (s_objectEquals == null)
{
s_objectEquals = Globals.TypeOfObject.GetMethod("Equals", BindingFlags.Public | BindingFlags.Static);
s_objectEquals = typeof(object).GetMethod("Equals", BindingFlags.Public | BindingFlags.Static);
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to delete Globals.TypeOfObject and all other typeof caches from the Globals type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. I've opened #42861 to do this.

@eerhardt
Copy link
Member Author

@HongGit @StephenMolloy @mconnew - thoughts on this? I'd like to propose this to be backported to 5.0 since it blocks any usage of DataContractSerializer in trimmed applications like Blazor WASM.

@github-actions
Copy link
Contributor

Started backporting to release/5.0-rc2: https://github.com/dotnet/runtime/actions/runs/280964515

@jkotas jkotas merged commit 118eee9 into dotnet:master Sep 30, 2020
@eerhardt eerhardt deleted the Fix42754 branch September 30, 2020 22:02
@jkoritzinsky
Copy link
Member

@eerhardt I'm seeing failures building master across the board from this PR. There's a number of trim analysis warnings due to this PR.

eerhardt added a commit to eerhardt/runtime that referenced this pull request Sep 30, 2020
Changes dotnet#40691 and dotnet#42824 conflicted. One added a new ILLink suppress warnings file, while the other added more warnings. This causes the build to break.

The fix is to regenerate the suppressions file with the latest code.

Fix dotnet#42926
eerhardt added a commit that referenced this pull request Oct 1, 2020
Changes #40691 and #42824 conflicted. One added a new ILLink suppress warnings file, while the other added more warnings. This causes the build to break.

The fix is to regenerate the suppressions file with the latest code.

Fix #42926
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants