You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LayoutBindings: 'PreserveAttribute' is obsolete warnings #7480
Those look like they are coming from the Xamarin.Android.Support.Design Nuget 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 old Support libraries to AndroidX.
@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.zip
1>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]'
DynamicDependencyAttribute works in the reverse manner to the old PreserveAttribute. The old system you placed the attribute at the code you wanted to preserver. The new DynamicDependencyAttribute you 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 the DynamicDependencyAttribute to the activity where its used.
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]'
Activity
dellis1972 commentedon 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 old
Supportlibraries 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.rgroenewoudt commentedon Oct 21, 2022
@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.zip
dellis1972 commentedon Oct 21, 2022
Ah. Are you using LayoutBindings?
dellis1972 commentedon Oct 21, 2022
Ignore that, yes you are :) sorry.
OK, that is where the issue is then.
[-]'PreserveAttribute' is obsolete warnings[/-][+]LayoutBindings: 'PreserveAttribute' is obsolete warnings[/+]rgroenewoudt commentedon Oct 26, 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#L221
A 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#L1152
dellis1972 commentedon Oct 26, 2022
DynamicDependencyAttributeworks 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.rgroenewoudt commentedon Oct 27, 2022
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.
jpobst commentedon Nov 28, 2022
A little more information on that:
Java.Interop.__TypeRegistrations.cs) should mark themselves as auto-generated java-interop#1051 (comment)rgroenewoudt commentedon Mar 13, 2023
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
jpobst commentedon Mar 13, 2023
This change was too late to make it into .NET 7, I would suspect that it is fixed in .NET 8 Previews.
rgroenewoudt commentedon Nov 23, 2023
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]'[LayoutBindings] LayoutBindings: 'PreserveAttribute' is obsolete warn…
rgroenewoudt commentedon Dec 21, 2023
Would it be possible to backport to .NET 8 if it's a limited change: only adding
<auto-generated>comment?jonathanpeppers commentedon Jan 3, 2024
Yes, we can consider taking this one to .NET 8 servicing after it's merged:
[LayoutBindings] LayoutBindings: 'PreserveAttribute' is obsolete warn…
[LayoutBindings] LayoutBindings: 'PreserveAttribute' is obsolete warn…
[LayoutBindings] LayoutBindings: 'PreserveAttribute' is obsolete warn…
[LayoutBindings] LayoutBindings: 'PreserveAttribute' is obsolete warn…
[LayoutBindings] LayoutBindings: 'PreserveAttribute' is obsolete warn…
[LayoutBindings] Fix '[Preserve]' is obsolete warnings (#8529)