Repository navigation
LayoutBindings: 'PreserveAttribute' is obsolete warnings #7480
Description
Activity
- addedArea: App+Library BuildIssues when building Library projects or Application projects.Issues when building Library projects or Application projects.needs-triageIssues that need to be assigned.Issues that need to be assigned.
on Oct 21, 2022 Those look like they are coming from the
Xamarin.Android.Support.DesignNuget Package.
I believe the recomendation now is to upgrade to use AndroidX rather than the old packages.
So you will need to migrate the code away from the oldSupportlibraries to AndroidX.See https://learn.microsoft.com/en-us/xamarin/android/platform/androidx for more details.
The
PreserveAttributeis going to be removed in a future version of .net so migrating is the best option.@dellis1972 I don't have any nuget packages Xamarin.Android.Support or any referencing it. Only AndroidX.
Example project. I created a new .NET 6 Android project, changed activity_main.xml to AndroidBoundlayout and added an ID.
AndroidApp2.zip1>C:\git\AndroidApp2\AndroidApp2\obj\Debug\net6.0-android\generated\Binding.activity_main.g.cs(12,4,12,45): warning CS0618: 'PreserveAttribute' is obsolete: 'Please use [System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute]' 1>C:\git\AndroidApp2\AndroidApp2\obj\Debug\net6.0-android\generated\Binding.activity_main.g.cs(19,4,19,45): warning CS0618: 'PreserveAttribute' is obsolete: 'Please use [System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute]'Ah. Are you using LayoutBindings?
Ignore that, yes you are :) sorry.
OK, that is where the issue is then.
- removedneeds-triageIssues that need to be assigned.Issues that need to be assigned.
on Oct 21, 2022 - changed the title
[-]'PreserveAttribute' is obsolete warnings[/-][+]LayoutBindings: 'PreserveAttribute' is obsolete warnings[/+]on Oct 21, 2022 I would guess that there would need to be an if added to support both classic with PreserveAttribute and .NET 6 with DynamicDependencyAttribute.
https://github.com/xamarin/xamarin-android/blob/ab6712a48e4b93e9c3d605c7b393814d477e2bc8/src/Xamarin.Android.Build.Tasks/Tasks/GenerateLayoutBindings.CSharpBindingGenerator.cs#L221A additional property would be probably be needed to feed the MsBuild task, perhaps UsingAndroidNETSdk?
https://github.com/xamarin/xamarin-android/blob/ab6712a48e4b93e9c3d605c7b393814d477e2bc8/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets#L1152DynamicDependencyAttributeworks in the reverse manner to the oldPreserveAttribute. The old system you placed the attribute at the code you wanted to preserver. The newDynamicDependencyAttributeyou have to place it where the type is consumed. So we need to figure out the best way to deal with this without requiring the user to add theDynamicDependencyAttributeto the activity where its used.Is the attribute even needed? This is the C# binding which is used by the developer so if unused constructors are removed it shouldn't be a problem?
The file should also contain the autogenerated comment so any warnings would be ignored.
The file should also contain the autogenerated comment so any warnings would be ignored.
A little more information on that:
I'm still seeing this issue in NET 7 Android 33, even though #1051 is resolved.
There is no autogenerated comment in generated/Binding.xxx.g.cs
This change was too late to make it into .NET 7, I would suspect that it is fixed in .NET 8 Previews.
Same issue in .NET 8.
xxxx\obj\Debug\net8.0-android\codebehind\Binding.StartWorkShift.g.cs(19,4,19,45): warning CS0618: 'PreserveAttribute' is obsolete: 'Please use [System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute]'- added a commit that references this issue
on Nov 30, 2023 Would it be possible to backport to .NET 8 if it's a limited change: only adding
<auto-generated>comment?Yes, we can consider taking this one to .NET 8 servicing after it's merged:
- added a commit that references this issue
on Jan 4, 2024 - added 2 commits that reference this issue
on Feb 16, 2024 - added 2 commits that reference this issue
on Mar 1, 2024 - added a commit that references this issue
on Mar 27, 2024 - locked and limited conversation to collaborators
on Apr 27, 2024
Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
VS2022 17.3.6
Description
We are using a lot of AndroidBoundLayout in our app but this results in 2 warnings per layout file:
We would like to get to 0 build warnings :)
Steps to Reproduce
Did you find any workaround?
No response
Relevant log output
No response