Skip to content

Commit 589baca

Browse files
Guard DynamicDependency processing against TypeSystemExceptions (#85285)
Works around dotnet/fsharp#15140 and it's also just good hygiene.
1 parent 876ab8b commit 589baca

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DynamicDependencyAttributesOnEntityNode.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,22 @@ public static void AddDependenciesDueToDynamicDependencyAttribute(ref Dependency
5555
public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory factory)
5656
{
5757
DependencyList dependencies = null;
58-
switch (_entity)
58+
try
5959
{
60-
case EcmaMethod method:
61-
foreach (var attribute in method.GetDecodedCustomAttributes("System.Diagnostics.CodeAnalysis", "DynamicDependencyAttribute"))
62-
{
63-
AddDependenciesDueToDynamicDependencyAttribute(ref dependencies, factory, method, method.OwningType, attribute);
64-
}
65-
break;
60+
(TypeDesc owningType, IEnumerable<CustomAttributeValue<TypeDesc>> attributes) = _entity switch
61+
{
62+
EcmaMethod method => (method.OwningType, method.GetDecodedCustomAttributes("System.Diagnostics.CodeAnalysis", "DynamicDependencyAttribute")),
63+
_ => (((EcmaField)_entity).OwningType, ((EcmaField)_entity).GetDecodedCustomAttributes("System.Diagnostics.CodeAnalysis", "DynamicDependencyAttribute")),
64+
};
6665

67-
case EcmaField field:
68-
foreach (var attribute in field.GetDecodedCustomAttributes("System.Diagnostics.CodeAnalysis", "DynamicDependencyAttribute"))
69-
{
70-
AddDependenciesDueToDynamicDependencyAttribute(ref dependencies, factory, field, field.OwningType, attribute);
71-
}
72-
break;
66+
foreach (CustomAttributeValue<TypeDesc> attribute in attributes)
67+
{
68+
AddDependenciesDueToDynamicDependencyAttribute(ref dependencies, factory, _entity, owningType, attribute);
69+
}
70+
}
71+
catch (TypeSystemException)
72+
{
73+
// Ignore entities with custom attributes that don't work.
7374
}
7475

7576
return dependencies;

0 commit comments

Comments
 (0)