-
Notifications
You must be signed in to change notification settings - Fork 10.3k
RDG file name mismatch between SyntaxTree.FilePath and [CallerFilePath] causes runtime KeyNotFoundException #47918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It looks to me like one was generated on a Linux machine, and the other was generated on a Windows machine. This might be a hole in our lookup strategy for interception. In the case o MapIdentityApi(...), its producing a DLL which is built on Linux and we are using it in a test which is presumably being built on Windows. At this point I would say that our approach can't support what you are trying to do here with MapIdentityApi. /cc @captainsafia |
I don't think this is a Windows vs Linux thing. That's why I made such a big point in the issue about how both file paths strings are being compiled into the same into the same Microsoft.AspNetCore.Identity.dll assembly. This is all being built on our Windows CI machine. The test project is not referencing RDG at all. It's simply using the endpoints defined by MapIdentityApi(...) using RDG that have already been compiled into the non-test Microsoft.AspNetCore.Identity.dll assembly. This is not just a test issue. This breaks anyone trying to call @jaredpar @cston Do you have any idea why |
This can happen with
|
Is there a way to reliably get something that matches what the |
There is not a public API for this. 😦 Short term you can either reflect into @RikkiGibson can you get a bug filed for that + track it through API review? |
SyntaxTree.GetDisplayPath is the method responsible for this. It happens to be implemented in terms of public APIs. /// <summary>
/// Returns a path for particular location in source that is presented to the user.
/// </summary>
/// <remarks>
/// Used for implementation of <see cref="System.Runtime.CompilerServices.CallerFilePathAttribute"/>
/// or for embedding source paths in error messages.
///
/// Unlike Dev12 we do account for #line and #ExternalSource directives when determining value for
/// <see cref="System.Runtime.CompilerServices.CallerFilePathAttribute"/>.
/// </remarks>
internal string GetDisplayPath(TextSpan span, SourceReferenceResolver? resolver)
{
var mappedSpan = GetMappedLineSpan(span);
if (resolver == null || mappedSpan.Path.IsEmpty())
{
return mappedSpan.Path;
}
return resolver.NormalizePath(mappedSpan.Path, baseFilePath: mappedSpan.HasMappedPath ? FilePath : null) ?? mappedSpan.Path;
} This also affects interceptors a bit, and relates to this prototype comment in the interceptors feature spec.
I think interceptors should apply pathmap substitution but not Usually, pathmap is just about eliminating machine-specific elements of paths, so even if the error we give only contains a mapped path, it's still pretty easy to use it to navigate to the appropriate file in your project. |
Whyyyyy did I convince myself that SyntaxTree.FilePath have already applied |
SyntaxTree.FilePath
and[CallerFilePath]
can give different filenames for the same compilation on our own public AzDO PR build pipeline which ultimately causes runtime KeyNotFoundExceptions in code relying on RDG.Example runtime stack trace:
https://dev.azure.com/dnceng-public/public/_build/results?buildId=253772&view=ms.vss-test-web.build-test-results-tab&runId=4932292&resultId=111661&paneView=debug
The disassembly of Microsoft.AspNetCore.Identity.dll from the PR shows RDG used "D:\a_work\1\s\src\Identity\Core\src\IdentityApiEndpointRouteBuilderExtensions.cs" from
SyntaxTree.FilePath
as the filename for the source key:aspnetcore/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Endpoint.cs
Lines 164 to 170 in 58940e3
But Roslyn used a different filename at the call site of the generated
MapPost
method for its[CallerFilePath]
parameter. It used "/_/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs" instead inside the same assembly:The text was updated successfully, but these errors were encountered: