我的 CodeFix 返回一个文档,我可以通过 Roslyn 跟踪它,直到 GetChangeSolutionAsync。当我在调试器中查看时 ChangedDocument 有一个带有正确文本的文档。但是下一行比较 ChangedDocument == null 并且它是 null 并退出返回 null 而不是我的文档的例程。
我已经逐步完成 GetChangedSoultionAsync 并看到它在调试器中返回正确的值,但随后看到它返回 null
protected async virtual Task<Solution> GetChangedSolutionAsync(CancellationToken cancellationToken)
{
var changedDocument = await GetChangedDocumentAsync(cancellationToken).ConfigureAwait(false);
if (changedDocument == null)
{
return null;
}
return changedDocument.Project.Solution;
}
在等待后的调试器中 changedDocument 如下所示
?changedDocument Test0.vb DocumentState: {Microsoft.CodeAnalysis.DocumentState} FilePath: null Id: (DocumentId, #860a1da9-991f-4262-9428-c50c7a9a912e - Test0.vb) Name: "Test0.vb" Project: TestProject Services: { Microsoft.CodeAnalysis.DefaultTextDocumentServiceProvider} SourceCodeKind: Regular State: {Microsoft.CodeAnalysis.DocumentState} 但if语句为真,函数返回null