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

SA1133CodeFixProvider crash #1878

Closed
vbfox opened this issue Dec 1, 2015 · 5 comments
Closed

SA1133CodeFixProvider crash #1878

vbfox opened this issue Dec 1, 2015 · 5 comments
Assignees
Milestone

Comments

@vbfox
Copy link

vbfox commented Dec 1, 2015

Given the following code :

namespace Stylecop_rc1_bug_repro
{
    using System;

    internal class Program
    {
        [Foo, Bar]
        private static void Main(string[] args)
        {
        }
    }

    internal class FooAttribute : Attribute
    {
    }

    internal class BarAttribute : Attribute
    {
    }
}

SA1133 is raised on Bar usage but activating the CodeFix throw an exception :

Exception thrown: 'System.InvalidCastException' in StyleCop.Analyzers.CodeFixes.dll

Additional information: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax'.

   at StyleCop.Analyzers.ReadabilityRules.SA1133CodeFixProvider.<GetTransformedDocumentAsync>d__5.MoveNext()

(VS2015 update 1, StyleCop 1.0 RC1)

@sharwell
Copy link
Member

sharwell commented Dec 1, 2015

Thanks for the report!

I am very much hoping this reproduces the problem in our unit tests. 😄

@NikolayIT
Copy link
Member

This code is enough to reproduce the problem.

I've created a new branch in my fork in order to try fixing the issue. Here is the regression test: https://github.com/NikolayIT/StyleCopAnalyzers/commit/f25bde0e7eb2efa9e6a936e72dcbaf112606a968

The test is failing with

System.InvalidCastException

Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.AttributeListSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax'.

   at StyleCop.Analyzers.ReadabilityRules.SA1133CodeFixProvider.<GetTransformedDocumentAsync>d__5.MoveNext() in C:\Dev\2015\StyleCopAnalyzers\StyleCop.Analyzers\StyleCop.Analyzers.CodeFixes\ReadabilityRules\SA1133CodeFixProvider.cs:line 54
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.CodeActions.CodeAction.<GetChangedSolutionAsync>d__9.MoveNext()

@NikolayIT
Copy link
Member

Well, that was very easy to fix. I am sending a pull request in a minute.

@sharwell
Copy link
Member

sharwell commented Dec 1, 2015

@NikolayIT Make sure to send your pull request to the stabilization branch instead of the default master branch.

@NikolayIT
Copy link
Member

@sharwell did it 😄

@sharwell sharwell modified the milestones: 1.0.0 RC 2, 1.0.0 Dec 1, 2015
sharwell added a commit that referenced this issue Dec 2, 2015
Fix #1878 (SA1133CodeFixProvider crash with System.InvalidCastException)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants