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

"InvalidOperationException: Object not initialized" when building .NET Framework project #1232

Closed
KavenBreton-eaton opened this issue Oct 23, 2023 · 2 comments

Comments

@KavenBreton-eaton
Copy link

Product and Version Used:
Roslynator.Analyzers 4.6.0, Roslynator.CodeAnalysis.Analyzers 4.6.0 and Roslynator.Formatting.Analyzers 4.6.0
.NET Framework 4.8
Visual Studio 2022

Steps to Reproduce:
We upgraded from 4.5.0 to 4.6.0 and this error started popping when building our project.

Actual Behavior:
This error is thrown when building the project.

Error AD0001	Analyzer 'Roslynator.CSharp.Analysis.InvocationExpressionAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'Object is not initialized.'.
Exception occurred with following context:
SyntaxNode: sb.AppendLine() [InvocationExpressionSyntax]@[5364..5379) (134,16)-(134,31)

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)
-----

Suppress the following diagnostics to disable this analyzer: RCS1015, RCS1068, RCS1077, RCS1080, RCS1097, RCS1107, RCS1112, RCS1112FadeOut, RCS1128, RCS1151, RCS1155, RCS1186, RCS1197, RCS1198, RCS1200, RCS1201, RCS1202, RCS1235, RCS1246

From the following code.

StringBuilder sb = new();
if (bPrintWarnings && HasWarning) { <------ Line 134
    sb.AppendLine(); <------
    sb.AppendFormat(CultureInfo.InvariantCulture, "{0} configuration warning{1} found", m_warnings.Count, m_warnings.Count > 1 ? "s" : string.Empty).AppendLine();
    sb.AppendLine(ToStringSeparator);
    foreach (ConfigurationWarning warning in m_warnings) {
        sb.AppendLine(warning.ToString());
        sb.AppendLine(ToStringSeparator);
    }
}

Expected Behavior:
No error

@josefpihrt
Copy link
Collaborator

Duplicate of #1226

@josefpihrt josefpihrt marked this as a duplicate of #1226 Oct 23, 2023
@josefpihrt
Copy link
Collaborator

@josefpihrt josefpihrt closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2023
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

No branches or pull requests

2 participants