Skip to content

Fix exceptions for non-VS hosting of Roslyn#60979

Merged
davidwengier merged 1 commit intodotnet:mainfrom
davidwengier:SourceLinkExceptions
Apr 27, 2022
Merged

Fix exceptions for non-VS hosting of Roslyn#60979
davidwengier merged 1 commit intodotnet:mainfrom
davidwengier:SourceLinkExceptions

Conversation

@davidwengier
Copy link
Copy Markdown
Member

Fixes #60908

First chance exceptions are a little more noticeable in other IDEs.

@davidwengier davidwengier requested a review from a team as a code owner April 27, 2022 07:00
@ghost ghost added the Area-IDE label Apr 27, 2022
[SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code")]
public PdbSourceDocumentLoaderService(
[Import(AllowDefault = true)] Lazy<ISourceLinkService?> sourceLinkService,
[Import(AllowDefault = true)] Lazy<ISourceLinkService?>? sourceLinkService,
Copy link
Copy Markdown
Member Author

@davidwengier davidwengier Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just incorrect. VS Mac doesn't have an implementation of this service (yet!), so this would null ref

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidwengier Should this be Lazy<ISourceLinkService>? instead? Because I don't see how you the lazy could return a null if we're allowing the lazy itself to be null?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh good point. That is probably how this bug slipped in, the question mark was just put in the wrong place.


static FileStream? ReadFileIfExists(string fileName)
{
if (File.Exists(fileName))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEReader handled the FileNotFoundException fine, but the first chance exception is very common, so easy enough to avoid it.

@davidwengier davidwengier enabled auto-merge (squash) April 27, 2022 07:15
@davidwengier davidwengier merged commit 173d2c4 into dotnet:main Apr 27, 2022
@ghost ghost added this to the Next milestone Apr 27, 2022
@davidwengier davidwengier deleted the SourceLinkExceptions branch April 27, 2022 09:12
@RikkiGibson RikkiGibson modified the milestones: Next, 17.3 P3 Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullReferenceException in PdbSourceDocumentLoaderService.cs line 130

4 participants