dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.04k stars 4.03k forks source link

Wrong CS2021 is reported for *.resources files #27045

Closed osdm closed 6 years ago

osdm commented 6 years ago

Investigation A change in src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs made in https://github.com/dotnet/roslyn/commit/d23cc53f65501798ae46e8ab9f3aa74077a7586d 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

osdm commented 6 years ago

@OmarTawfik please take a look

OmarTawfik commented 6 years ago

@osdm thanks for reporting! will take a look. @jaredpar @jcouv to confirm triage.

leonpierre commented 6 years ago

@OmarTawfik This bug is reported to be fixed with milestone 15.8! When do you plan to rollout this update to Visual Studio?

jmarolf commented 6 years ago

@leonpierre this fix is in the latest 15.8 preview. We can't talk about exact dates for when 15.8 will be released in non-preview form.