diff --git a/src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs index 497e5049139cf..f6f3d36f2505d 100644 --- a/src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/CodeRefactorings/InlineTemporary/InlineTemporaryCodeRefactoringProvider.cs @@ -142,7 +142,6 @@ private static async Task InlineTemporaryAsync(Document document, Vari // Annotate the variable declarator so that we can get back to it later. document = await document.ReplaceNodeAsync(declarator, declarator.WithAdditionalAnnotations(DefinitionAnnotation), cancellationToken).ConfigureAwait(false); - var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); declarator = await FindDeclaratorAsync(document, cancellationToken).ConfigureAwait(false); @@ -155,7 +154,6 @@ private static async Task InlineTemporaryAsync(Document document, Vari (o, n) => n.WithAdditionalAnnotations(ReferenceAnnotation), cancellationToken).ConfigureAwait(false); - semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); declarator = await FindDeclaratorAsync(document, cancellationToken).ConfigureAwait(false); allReferences = await FindReferenceAnnotatedNodesAsync(document, cancellationToken).ConfigureAwait(false); @@ -172,7 +170,6 @@ private static async Task InlineTemporaryAsync(Document document, Vari var newScope = ReferenceRewriter.Visit(scope, conflictReferences, nonConflictReferences, expressionToInline, cancellationToken); document = await document.ReplaceNodeAsync(scope, newScope, cancellationToken).ConfigureAwait(false); - semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); declarator = await FindDeclaratorAsync(document, cancellationToken).ConfigureAwait(false); newScope = GetScope(declarator); @@ -183,7 +180,6 @@ private static async Task InlineTemporaryAsync(Document document, Vari // No semantic conflicts, we can remove the definition. document = await document.ReplaceNodeAsync( newScope, RemoveDeclaratorFromScope(declarator, newScope), cancellationToken).ConfigureAwait(false); - semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); } // Finally, check all the places we inlined an expression and add some final warnings there if appropriate. @@ -192,6 +188,8 @@ private static async Task InlineTemporaryAsync(Document document, Vari .OfType() .Select(e => GetTopMostParentingExpression(e)); + var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); + // Make each topmost parenting statement or Equals Clause Expressions semantically explicit. document = await document.ReplaceNodesAsync(topmostParentingExpressions, (o, n) => {