protected static async Task <TextAndVersion> LoadTextAsync(TextLoader loader, DocumentId documentId, SolutionServices services, bool reportInvalidDataException, CancellationToken cancellationToken) { try { using (ExceptionHelpers.SuppressFailFast()) { var result = await loader.LoadTextAndVersionAsync(services.Workspace, documentId, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); return(result); } } catch (OperationCanceledException) { // if load text is failed due to a cancellation, make sure we propagate it out to the caller throw; } catch (IOException e) { services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId)); return(TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, documentId.GetDebuggerDisplay())); } catch (InvalidDataException e) { // TODO: Adjust this behavior in the future if we add support for non-text additional files if (reportInvalidDataException) { services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId)); } return(TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, documentId.GetDebuggerDisplay())); } }
protected static TextAndVersion LoadTextSynchronously(TextLoader loader, DocumentId documentId, SolutionServices services, bool reportInvalidDataException, CancellationToken cancellationToken) { int retries = 0; while (true) { try { return(loader.LoadTextAndVersionSynchronously(services.Workspace, documentId, cancellationToken)); } catch (OperationCanceledException) { // if load text is failed due to a cancellation, make sure we propagate it out to the caller throw; } catch (IOException e) { if (++retries > MaxRetries) { services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId)); return(TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, documentId.GetDebuggerDisplay())); } // fall out to try again } catch (InvalidDataException e) { // TODO: Adjust this behavior in the future if we add support for non-text additional files if (reportInvalidDataException) { services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.Failure, e.Message, documentId)); } return(TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, documentId.GetDebuggerDisplay())); } // try again after a delay Thread.Sleep(RetryDelay); } }
private static async Task <TextAndVersion> LoadTextAsync(TextLoader loader, DocumentId documentId, SolutionServices services, CancellationToken cancellationToken) { try { using (ExceptionHelpers.SuppressFailFast()) { var result = await loader.LoadTextAndVersionAsync(services.Workspace, documentId, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); return(result); } } catch (OperationCanceledException) { // if load text is failed due to a cancellation, make sure we propagate it out to the caller throw; } catch (Exception e) { services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.FileAccessFailure, e.Message, documentId)); return(TextAndVersion.Create(SourceText.From(string.Empty), VersionStamp.Default, documentId.GetDebuggerDisplay())); } }