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
@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.
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
GetTextmethod.