Roslyn-analyzers: DeclarePublicAPIAnalyzer fails with NRE when files are not found

Created on 14 Feb 2017  路  3Comments  路  Source: dotnet/roslyn-analyzers

Due to a local error, the following file didn't exist on disk:
roslyn\src\Compilers\CSharp\Portable\PublicAPI.Unshipped.txt

DeclarePublicAPIAnalyzer.TryGetApiData() would execute unshippedText.GetText(), which would then return null, and diagnostics with the following error:

error CS2001: Source file 'roslyn\src\Compilers\CSharp\Portable\PublicAPI.Unshipped.txt' could not be found.

Instead of checking the diagnostics and asserting for nulls in the analyzer, the returned object sourceText is used directly in the foreach loop in DeclarePublicAPIAnalyzer.ReadApiData(), which would fail with a NRE.

Expectation: diagnostics from compiler interactions should be surfaced through the compilation context.

/cc @srivatsn

Area-DotNetAnalyzers.PublicApiAnalyzer Bug help wanted

Most helpful comment

@mavasani I was looking at the code and I think it is now fixed, if the file is null we no longer call the GetText method.

All 3 comments

@drewnoakes @genlu - do we want to tackle this as part of https://github.com/dotnet/roslyn-analyzers/issues/2622 or track it separately here?

Have also just encountered this in a multi-targeting scenario, when one of the TFM directories is missing.

@mavasani I was looking at the code and I think it is now fixed, if the file is null we no longer call the GetText method.

Was this page helpful?
0 / 5 - 0 ratings