-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] Support HandleKind.TypeSpecification (#…
…9373) Fixes: #9369 [C# 11 added support for generic custom attributes][0]: [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)] public class GenericTestAttribute<T> : Attribute { } which means generic types can now be used as assembly-level attributes: [assembly: GenericTestAttribute<string>] Unfortunately, attempting to do this would result in an `InvalidCastException` from the `<FilterAssemblies/>` task: System.InvalidCastException: Die angegebene Umwandlung ist ungültig. error XAFLT7007: bei System.Reflection.Throw.InvalidCast() error XAFLT7007: bei System.Reflection.Metadata.TypeReferenceHandle.op_Explicit(EntityHandle handle) error XAFLT7007: bei Xamarin.Android.Tasks.MetadataExtensions.GetCustomAttributeFullName(MetadataReader reader, CustomAttribute attribute) error XAFLT7007: bei Xamarin.Android.Tasks.FilterAssemblies.IsAndroidAssembly(AssemblyDefinition assembly, MetadataReader reader) error XAFLT7007: bei Xamarin.Android.Tasks.FilterAssemblies.ProcessAssembly(ITaskItem assemblyItem, List`1 output) error XAFLT7007: bei Xamarin.Android.Tasks.FilterAssemblies.RunTask() error XAFLT7007: bei Microsoft.Android.Build.Tasks.AndroidTask.Execute() This happens because when System.Reflection.Metadata comes across an Attribute which has a generic type parameter, it does *not* return a [`TypeReferenceHandle`][1], but instead a [`TypeSpecificationHandle`][2]. Update `MetadataExtensions.GetCustomAttributeFullName()` to support [`HandleKind.TypeSpecification`][3] [0]: https://learn.microsoft.com/dotnet/csharp/whats-new/csharp-11#generic-attributes [1]: https://learn.microsoft.com/dotnet/api/system.reflection.metadata.typereferencehandle?view=net-8.0 [2]: https://learn.microsoft.com/dotnet/api/system.reflection.metadata.typespecificationhandle?view=net-8.0 [3]: https://learn.microsoft.com/dotnet/api/system.reflection.metadata.handlekind?view=net-8.0
- Loading branch information
1 parent
4429c52
commit d806eb4
Showing
7 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters