-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Conversation
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
src/libraries/System.Runtime.Serialization.Xml/tests/TrimmingTests/EndToEndTest.cs
Show resolved
Hide resolved
@@ -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); |
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.
It would be nice to delete Globals.TypeOfObject
and all other typeof caches from the Globals
type.
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.
Agreed. I've opened #42861 to do this.
@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. |
Started backporting to release/5.0-rc2: https://github.com/dotnet/runtime/actions/runs/280964515 |
@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. |
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
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