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

CC0022: System.InvalidCastException thrown on Initializer Expression #1020

Open
jeffreympolk opened this issue Mar 26, 2019 · 0 comments
Open

Comments

@jeffreympolk
Copy link

The following default code for a new Windows Service (.NET Framework) project shows waring CC0022 but throws the exception below when viewing potential fixes.

namespace WindowsService1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new Service1()
            };
            ServiceBase.Run(ServicesToRun);
        }
    }
}
System.InvalidCastException : Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.InitializerExpressionSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionStatementSyntax'.
   at CodeCracker.CSharp.Usage.DisposableVariableNotDisposedCodeFixProvider.CreateUsing(SyntaxNode root,ObjectCreationExpressionSyntax objectCreation,SemanticModel semanticModel)
   at async CodeCracker.CSharp.Usage.DisposableVariableNotDisposedCodeFixProvider.CreateUsingAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.<GetPreviewAsync>b__0(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)
@jeffreympolk jeffreympolk changed the title System.InvalidCastException thrown on object initializer CC0022: System.InvalidCastException thrown on object initializer Mar 26, 2019
@jeffreympolk jeffreympolk changed the title CC0022: System.InvalidCastException thrown on object initializer CC0022: System.InvalidCastException thrown on Initializer Expression Mar 26, 2019
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

1 participant