Skip to content

fix(annotations): format generic arguments with curly braces in doc cref - #2592

Open
reginaldalfret wants to merge 1 commit into
aws:masterfrom
reginaldalfret:fix/issue-2587-escape-generic-cref
Open

reginaldalfret wants to merge 1 commit into
aws:masterfrom
reginaldalfret:fix/issue-2587-escape-generic-cref

Conversation

@reginaldalfret

Copy link
Copy Markdown

Description

In Amazon.Lambda.Annotations.SourceGenerator, XML documentation comments generated on the Lambda function handler class and method use <see cref="..." referencing the containing type and method signature with parameter types.

When a parameter type or containing type is generic (e.g. IEnumerable<string>, IList<IList<int>>, SqsBatchProcessor<Payload, Handler>), the type name was previously emitted with angle brackets < and > into the XML attribute cref="...". This produces unescaped XML inside an attribute value, leading to CS1570, CS1584, and CS1658 compiler warnings whenever consuming projects have <GenerateDocumentationFile>true</GenerateDocumentationFile> enabled.

In C# XML documentation comments, generic type arguments in cref attributes must use curly braces {...} (e.g. IEnumerable{string}).

Changes

  • In LambdaFunctionTemplateCode.cs, added FormatCrefType(string typeName) which replaces < and > with { and } for types formatted in cref attributes.
  • Updated generator snapshots that include generic parameter types to reflect {} in cref comments.

Fixes #2587

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
@reginaldalfret
reginaldalfret requested review from a team as code owners October 9, 2026 11:41

@boblodgett boblodgett left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the build with this PR branch and warnings went from 29 down to 4. These are the warnings I am still getting:

PS C:\Dev\aws-lambda-dotnet-pull-2592\repro> Remove-Item -Recurse -Force obj, bin -ErrorAction SilentlyContinue; dotnet build -p:AnnotationsVersion=2.4.2 -p:PrGenerator=C:/Dev/ai/aws-lambda-dotnet-pull-2592/repro/gen-pr -o out-pr
Restore complete (0.5s)
  Repro net8.0 succeeded with 4 warning(s) (0.4s) → out-pr\Repro.dll
    C:\Dev\aws-lambda-dotnet-pull-2592\repro\obj\Debug\net8.0\generated\Amazon.Lambda.Annotations.SourceGenerator\Amazon.Lambda.Annotations.SourceGenerator.Generator\EdgeCases_TupleArg_Generated.g.cs(46,66): warning CS1584: XML comment has syntactically incorrect cref attribute 'TupleArg((int A, string B), Amazon.Lambda.Core.ILambdaContext)'
    C:\Dev\aws-lambda-dotnet-pull-2592\repro\obj\Debug\net8.0\generated\Amazon.Lambda.Annotations.SourceGenerator\Amazon.Lambda.Annotations.SourceGenerator.Generator\EdgeCases_TupleArg_Generated.g.cs(46,75): warning CS1658: ) expected. See also error CS1026.
    C:\Dev\aws-lambda-dotnet-pull-2592\repro\obj\Debug\net8.0\generated\Amazon.Lambda.Annotations.SourceGenerator\Amazon.Lambda.Annotations.SourceGenerator.Generator\EdgeCases_SayHello_Generated.g.cs(46,66): warning CS1574: XML comment has cref attribute 'SayHello(System.Collections.Generic.IEnumerable{string}, Amazon.Lambda.Core.ILambdaContext)' that could not be resolved
    C:\Dev\aws-lambda-dotnet-pull-2592\repro\obj\Debug\net8.0\generated\Amazon.Lambda.Annotations.SourceGenerator\Amazon.Lambda.Annotations.SourceGenerator.Generator\Functions_Handle_Generated.g.cs(46,66): warning CS1574: XML comment has cref attribute 'Handle(Amazon.Lambda.SQSEvents.SQSEvent, Amazon.Lambda.Core.ILambdaContext, Repro.SqsBatchProcessor{Repro.Payload, Repro.Handler})' that could not be resolved

@bhoradc bhoradc added the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Oct 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

response-requested Waiting on additional info and feedback. Will move to close soon in 7 days.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated XML doc cref contains unescaped generic arguments: CS1584 / CS1658 / CS1570 warnings

3 participants