-
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 has Type.GetMethod extension method that is not trim-safe #42754
Comments
FWIW, .NET Framework called the Type.GetMethod directly https://referencesource.microsoft.com/#System.Runtime.Serialization/System/Runtime/Serialization/XmlFormatGeneratorStatics.cs . This method is left-over from .NET Core 1.0 era reduced reflection surface that made people to introduce stub implementations like this in many places.
The calls to this method are long and verbose already because of the need to create array of types. The .NET Framework implementation passed in the extra nulls and it looks just fine to me. |
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
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 #41525 Fix #42754
…link (#42911) * DataContractSerialization doesn't work with TrimMode - link 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 * add copyright header Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
We have some reflection code in DataContractSerialization that is not trim-safe:
runtime/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatGeneratorStatics.cs
Line 48 in e17d818
runtime/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatGeneratorStatics.cs
Line 617 in e17d818
On the surface, this appears to be safe since the ILLinker should be able to see this usage of reflection and preserve the referenced methods. However, the issue is that overload of
Type.GetMethod
doesn't exist. (See #42753 for proposal to create it.)Instead, DataContractSerialization has its own extension method that implements this API:
runtime/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Globals.cs
Lines 819 to 824 in e17d818
The ILLinker can't see through this usage of Reflection, so all 41 usages of this method are broken when an application is trimmed.
We should remove this method and call directly into Reflection APIs, so the linker has a chance of preserving these necessary methods.
This is the underlying problem that was discovered in dotnet/aspnetcore#25909. Here's a repro program from that issue that fails when
PublishTrimmed=true
andTrimMode=link
are set.The text was updated successfully, but these errors were encountered: