-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
DataContractSerializer is not trimming safe #45559
Comments
Do we know how/why it works today? No code is referencing the |
There are different custom linker steps which are trying to guess what should be kept based on some heuristic. |
I don't believe this is going to be possible without more features from the ILLinker. We could make the exact scenario above work with the current This issue is blocked by getting a serialization story in the ILLinker (dotnet/linker#1087), or implementing a source generator for DCS (#43545). |
If I'm reading the code in MonoDroid.Tuner right, the heuristic basically relies on the DataContract/DataMember attributes to decide what to keep. Those attributes are not mandatory - you can drop them and the DCS will do the same thing for this class. But I assume MonoDroid.Tuner is going to break it the same as NetCore linker. We'll need to decide how we want to treat "regression in a unit test" vs "regression in a scenario". This is a regression in a unit test, but I would assume the scenario (DCS) doesn't work either way. |
Original customer issue is here https://bugzilla.xamarin.com/show_bug.cgi?id=36250 |
Thanks!
The customer actually hit a different issue and this kind of looks like one of those in the bucket of: "can't solve this without introducing |
…for netcore (#5354) This is or will be handled by BCL libraries and XA tooling should try not to interfere with more fine tuned handling done by BCL. Simplifies `[Preserve]` attribute implementation and removes old code to preserve serialization, which doesn't work well with new .NET5/6 runtime libraries. (the old serialization code: https://github.com/xamarin/xamarin-android/blob/master/src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/ApplyPreserveAttribute.cs#L57-L82) The serialization is currently [broken](dotnet/runtime#45559) and will be fixed in runtime libs. Part of `CustomLinkDescriptionPreserve` test is thus disabled. Also the attribute removal is now handled in illink. The serialization fix leads to great reduction of assemblies size in simple XA test app by cca 1MB, apkdiff before/after: Summary: - 1,199,411 Assemblies -55.66% (of 2,154,984) - 1,206,333 Package size difference -13.37% (of 9,024,291) Co-authored-by: Radek Doulik <[email protected]>
@StephenMolloy if this is not serialization, do you have a recommendation? |
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov Issue DetailsFollowing code works today with linker enabled for SDK and user code but breaks with netcore libraries public class Test
{
// [Test]
public static string SerializeSearchRequestWithDictionary ()
{
var req = new SearchRequest () {
Query = "query",
Users = new List<string> () {
"user_a", "user_b"
},
Filters = new List<string> () {
"filter_a", "filter_b"
},
Parameters = new Dictionary<string, string> () {
{ "param_key_b", "param_value_a" },
{ "param_key_a", "param_value_b" },
}
};
using (MemoryStream memoryStream = new MemoryStream ()) {
var dataContractSerializer = new DataContractSerializer (typeof (SearchRequest));
dataContractSerializer.WriteObject (memoryStream, req);
string serializedDataContract = Encoding.UTF8.GetString (memoryStream.ToArray (), 0, (int) memoryStream.Length);
}
}
}
[DataContract]
public class SearchRequest
{
[DataMember]
public string Query { get; set; }
[DataMember]
public List<string> Users { get; set; }
[DataMember]
public List<string> Filters { get; set; }
[DataMember]
public Dictionary<string, string> Parameters { get; set; }
} Exception is thrown at runtime
|
Given dotnet/linker#1087 is closed as "not planned", and the plan on making |
This was actually fixed by grandfathering the MonoDroid behavior under a switch that Xamarin opts into. It doesn't make DCS trimming safe, but usable if you follow the very specific golden path that historically worked in Xamarin: https://github.com/dotnet/linker/blob/main/docs/serialization.md dotnet/linker#1087 would not solve the general DCS serialization patterns either. |
Following code works today with linker enabled for SDK and user code but breaks with netcore libraries
Exception is thrown at runtime
@eerhardt @vitek-karas
The text was updated successfully, but these errors were encountered: