Skip to content

Wrong CS2021 is reported for *.resources files #27045

@osdm

Description

@osdm

Investigation
A change in src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs made in d23cc53 causes a bug.

There, PathUtilities.IsValidFilePath is called for a fileName instead of a filePath. Inside it,
new FileInfo(fileName) is created, and there is no parent directory in fileName, so current directory is used. In our case current directory is a path to compiler binaries, and it is rather long. If path to compiler binaries length + file name length exceed 260 characters, then PathTooLongException is thrown and that results in CS2021 error.

Compiler errors should not depend on a path to compiler binaries, only on path to files being compiled.

Version Used:
2.8 (from dev15.7)

Steps to Reproduce:

  1. Place compiler binaries into a folder with a path length >=127 characters (say, C:\Users\SomeUserAtSomeCompany\AppData\Local\MyFolder1~\Toolset\A367E15E0EE028AF\MyFolder1.Toolset.Roslyn.2.8.20180511.192024)
  2. Make a resource file with a name length >= 135 characters (say, MyCompany.SomeNamespace.SubNamespace.MoreNamespace.OneMoreNamespace.EvenMoreNamespace.Control.ShowMeSomeOptionsOptionsPagePanel.resources) and place it in your project with a short folder name so that a full path length to resource file would not exceed 260 characters.
  3. Compile your project with a said resource file using a compiler run from its folder from step 1.

Expected Behavior:
No errors are produced

Actual Behavior:
CSC : error CS2021: File name '...\MyCompany.SomeNamespace.SubNamespace.MoreNamespace.OneMoreNamespace.EvenMoreNamespace.Control.ShowMeSomeOptionsOptionsPagePanel.resources' is empty, contains invalid characters, has a drive specification without an absolute path, or is too long

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions