diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Populators/TypeContainerVisitor.cs b/csharp/extractor/Semmle.Extraction.CSharp/Populators/TypeContainerVisitor.cs index 2bd5a9f4e031..3a2caff6102c 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Populators/TypeContainerVisitor.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Populators/TypeContainerVisitor.cs @@ -89,8 +89,10 @@ public override void VisitAttributeList(AttributeListSyntax node) SyntaxKind.ModuleKeyword => Entities.AttributeKind.Module, _ => throw new InternalError(node, "Unhandled global target") }; - foreach (var attribute in node.Attributes) + var attributes = node.Attributes; + for (var i = 0; i < attributes.Count; i++) { + var attribute = attributes[i]; if (attributeLookup.Value(attribute) is AttributeData attributeData) { var ae = Entities.Attribute.Create(Cx, attributeData, outputAssembly, kind); diff --git a/csharp/ql/test/library-tests/standalone/assemblyattribute/attr.expected b/csharp/ql/test/library-tests/standalone/assemblyattribute/attr.expected new file mode 100644 index 000000000000..a8e2f7d8aeb7 --- /dev/null +++ b/csharp/ql/test/library-tests/standalone/assemblyattribute/attr.expected @@ -0,0 +1,2 @@ +| standalone.cs:3:12:3:29 | [assembly: Attribute1(...)] | +| standalone.cs:9:2:9:11 | [Attribute1(...)] | diff --git a/csharp/ql/test/library-tests/standalone/assemblyattribute/attr.ql b/csharp/ql/test/library-tests/standalone/assemblyattribute/attr.ql new file mode 100644 index 000000000000..f1f82ed8f785 --- /dev/null +++ b/csharp/ql/test/library-tests/standalone/assemblyattribute/attr.ql @@ -0,0 +1,5 @@ +import csharp + +from Attribute a +where a.getType().getName() = "Attribute1Attribute" +select a diff --git a/csharp/ql/test/library-tests/standalone/assemblyattribute/options b/csharp/ql/test/library-tests/standalone/assemblyattribute/options new file mode 100644 index 000000000000..7ba3811b2afb --- /dev/null +++ b/csharp/ql/test/library-tests/standalone/assemblyattribute/options @@ -0,0 +1 @@ +semmle-extractor-options: --standalone diff --git a/csharp/ql/test/library-tests/standalone/assemblyattribute/standalone.cs b/csharp/ql/test/library-tests/standalone/assemblyattribute/standalone.cs new file mode 100644 index 000000000000..a03550d040e0 --- /dev/null +++ b/csharp/ql/test/library-tests/standalone/assemblyattribute/standalone.cs @@ -0,0 +1,12 @@ +using System; + +[assembly: global::Attribute1] + +class Attribute1Attribute : Attribute +{ +} + +[Attribute1] +class A +{ +}