Skip to content

[code analysis] potential bug with implicit using directives #7

Description

@khemichew

C# introduced implicit using directives in C# 6.0, but code analysis with Roslyn requires the using directives to be specified upfront for it to be able to deduce the types from the namespace included.

https://learn.microsoft.com/en-gb/dotnet/core/project-sdk/overview#implicit-using-directives

An example includes:

public class C {
    public void M() {
        int x = 0;
    }
}

which would compile without the using System; directive, but:

public class C {
    public void M() {
        Int32 x = 0; // will not compile
    }
}

with error CS0246: The type or namespace name 'Int32' could not be found (are you missing a using directive or an assembly reference?)

To make the code compile, the directive should be added:

using System;

public class C {
    public void M() {
        Int32 x = 0; 
    }
}

A task is to explore how this would affect code analysis: the solution would involve discovering if the project has the ImplicitUsings setting enabled, and explicitly adding the using statements to the compilation before analysis takes place.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededquestionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions