This project is read-only.
1

Resolved

AddAttributeList throws if provided an empty list

description

var attributes = new AttributeListSyntax[0];
SyntaxFactory
.MethodDeclaration(type, name)
.AddAttributeLists(attributes); // throws the following exception

Message:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Stack Trace:
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List1.get_Item(Int32 index)
at Microsoft.CodeAnalysis.SyntaxList
1.InsertRange(Int32 index, IEnumerable1 nodes)
at Microsoft.CodeAnalysis.SyntaxList
1.AddRange(IEnumerable`1 nodes)
at Microsoft.CodeAnalysis.CSharp.Syntax.MethodDeclarationSyntax.AddAttributeLists(AttributeListSyntax[] items)
at <usercode>

comments

justinc wrote May 4, 2014 at 6:59 PM

The same is true of ConstructorDeclaration, and others, fwiw.

justinc wrote May 4, 2014 at 7:03 PM

Also CompilationUnit.AddUsings.

angocke wrote May 8, 2014 at 11:12 PM

Fixed in changeset 938dd2f3467d5887de632510400e211d99d5927f

justinc wrote May 9, 2014 at 4:02 PM

Thanks! I have to say I'm pretty excited to see that you have fixed a bug reported here in a timely fashion, committed the fix directly to codeplex and included a unit test with the fix! Well done :)