Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AD0001 when using StringBuilder.AppendLine() #1225

Closed
daze99 opened this issue Oct 19, 2023 · 3 comments · Fixed by #1226
Closed

AD0001 when using StringBuilder.AppendLine() #1225

daze99 opened this issue Oct 19, 2023 · 3 comments · Fixed by #1226

Comments

@daze99
Copy link

daze99 commented Oct 19, 2023

Product and Version Used:
Roslynator 4.6.0 in Visual Studio 17.7.5

Steps to Reproduce:

public static string Test()
{
    var strBuilder = new StringBuilder();
    _ = strBuilder.AppendLine();

    return strBuilder.ToString();
}

Actual Behavior:
There is a warning AD0001

System.InvalidOperationException: Object is not initialized.
   at Roslynator.CSharp.Syntax.SimpleMemberInvocationExpressionInfo.get_Name()
   at Roslynator.CSharp.Syntax.SimpleMemberInvocationExpressionInfo.get_NameText()
   at Roslynator.CSharp.Analysis.OptimizeStringBuilderAppendCallAnalysis.Analyze(SyntaxNodeAnalysisContext context, SimpleMemberInvocationExpressionInfo& invocationInfo)
   at Roslynator.CSharp.Analysis.InvocationExpressionAnalyzer.AnalyzeInvocationExpression(SyntaxNodeAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__49`1.<ExecuteSyntaxNodeAction>b__49_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)

Expected Behavior:
No warning should occur.

@daze99 daze99 changed the title AD0001 when using StrinngBuilder.AppendLine() AD0001 when using StringBuilder.AppendLine() Oct 19, 2023
@bdovaz
Copy link
Contributor

bdovaz commented Oct 20, 2023

@josefpihrt are you going to release a patch soon? Thanks!

@josefpihrt
Copy link
Collaborator

@bdovaz Patch will be released soon.

@josefpihrt
Copy link
Collaborator

https://github.com/dotnet/roslynator/releases/tag/v4.6.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants