From 589bacae61a3cf8c162529aef1ce0e33842073c8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 26 Apr 2023 10:09:13 +0900 Subject: [PATCH] Guard DynamicDependency processing against `TypeSystemException`s (#85285) Works around https://github.com/dotnet/fsharp/issues/15140 and it's also just good hygiene. --- .../DynamicDependencyAttributesOnEntityNode.cs | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DynamicDependencyAttributesOnEntityNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DynamicDependencyAttributesOnEntityNode.cs index 95fcd87..7c07dfd 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DynamicDependencyAttributesOnEntityNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DynamicDependencyAttributesOnEntityNode.cs @@ -55,21 +55,22 @@ namespace ILCompiler.DependencyAnalysis public override IEnumerable GetStaticDependencies(NodeFactory factory) { DependencyList dependencies = null; - switch (_entity) + try { - case EcmaMethod method: - foreach (var attribute in method.GetDecodedCustomAttributes("System.Diagnostics.CodeAnalysis", "DynamicDependencyAttribute")) - { - AddDependenciesDueToDynamicDependencyAttribute(ref dependencies, factory, method, method.OwningType, attribute); - } - break; + (TypeDesc owningType, IEnumerable> attributes) = _entity switch + { + EcmaMethod method => (method.OwningType, method.GetDecodedCustomAttributes("System.Diagnostics.CodeAnalysis", "DynamicDependencyAttribute")), + _ => (((EcmaField)_entity).OwningType, ((EcmaField)_entity).GetDecodedCustomAttributes("System.Diagnostics.CodeAnalysis", "DynamicDependencyAttribute")), + }; - case EcmaField field: - foreach (var attribute in field.GetDecodedCustomAttributes("System.Diagnostics.CodeAnalysis", "DynamicDependencyAttribute")) - { - AddDependenciesDueToDynamicDependencyAttribute(ref dependencies, factory, field, field.OwningType, attribute); - } - break; + foreach (CustomAttributeValue attribute in attributes) + { + AddDependenciesDueToDynamicDependencyAttribute(ref dependencies, factory, _entity, owningType, attribute); + } + } + catch (TypeSystemException) + { + // Ignore entities with custom attributes that don't work. } return dependencies; -- 2.7.4