roslyn-sdk
roslyn-sdk copied to clipboard
Multi line markup location is not found when parsing source code
trafficstars
For the posted source code no markup location is found. Instead I get a stacktrace and an Exception message:
Message:
System.InvalidOperationException : The markup location '#0' was not found in the input.
Stack Trace:
DiagnosticResult.WithAppliedMarkupLocations(ImmutableDictionary`2 markupLocations) line 357
SolutionState.WithProcessedMarkup(MarkupOptions markupOptions, DiagnosticDescriptor defaultDiagnostic, ImmutableArray`1 supportedDiagnostics, ImmutableArray`1 fixableDiagnostics, String defaultPath) line 276
CodeFixTest`1.RunAsync(CancellationToken cancellationToken) line 232
CSharpCodeFixVerifier`2.VerifyCodeFixAsync(String source, DiagnosticResult[] expected, String fixedSource) line 52
CSharpCodeFixVerifier`2.VerifyCodeFixAsync(String source, DiagnosticResult expected, String fixedSource) line 41
UseThrowIfCancellationRequestedTests.SingleFix_IfBlock() line 117
--- End of stack trace from previous location where exception was thrown ---
[Fact]
public async Task SingleFix_IfBlock()
{
await VerifyCS.VerifyCodeFixAsync(@"
using System;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApplication1
{
class TypeName
{
public async Task Test(CancellationToken ct)
{
{|#0:if(ct.IsCancellationRequested)
{
throw new Exception();
}|}
}
}
}", VerifyCS.Diagnostic(UseThrowIfCancellationRequestedAnalyzer.DefaultRule).WithLocation(0),
@"using System;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApplication1
{
class TypeName
{
public async Task Test(CancellationToken ct)
{
ct.ThrowIfCancellationRequested();
}
}
}");
}
My guess on the cause of this is the code fix provider specified in the alias for VerifyCS does not report UseThrowIfCancellationRequestedAnalyzer.DefaultRule as a supported diagnostic. This scenario would cause VerifyCodeFixAsync to expect the diagnostic in both the test code and the fixed code, but only the test code provides location 0.