-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Building in VS from aspnetcore repo, .razor files failing with CS0649 (Field is never assigned to) and RZ9991 (Attribute names could not be inferred) #31023
Comments
cc @pranavkm and @captainsafia for opinions on whether this might be related to source generator work, or @NTaylorMullen in case this is a known issue in the VS Razor tooling |
Update It's not only on VS. It happens in command line builds too, but only sometimes! What I'm getting at the moment is:
|
@SteveSandersonMS It looks like you might've run into #30720. I'd marked that as investigate until I could get a reliable repro out of it, but it looks like it's reproing reliably now for you. Can you share the SDK version you're on? The delta between the version I last tried to repro on and the current one might have made the repro more reliable. Edit: Nevermind. Just saw that you're doing this on the aspnetcore repo so I can pull out the SDK version. |
Dupe of #30720. I think it's got something to do with the compiler that gets used. Killing the compiler seems to fix it at times, but don't quote me on it. |
Yeah, it's currently 6.0.100-preview.3.21160.5 for me. |
Thanks for contacting us. |
A further data point. I got into this state again just now, this time on the command line. I tried following @pranavkm's suggestion to kill all running .NET Core processes on the machine (including by closing all VS + VS Code instances, and terminating related processes like |
This reproduces around 50% of the time when executing the following script on the CLI. # in src/Components
for i in {0..9}; do ./build.sh ; done However, the same behavior doesn't repro when using the activated build in the # in src/Components/test/testassets/BasicTestApp
for i in {0..9}; do dotnet build; done Furthermore, the same behavior doesn't repro when invoking the compiler directly. cd test/testassets/BasicTestApp
for i in {0..9}
do
/Users/captainsafia/github.com/dotnet/aspnetcore/.dotnet/dotnet exec "/Users/captainsafia/.nuget/packages/microsoft.net.compilers.toolset/3.8.0-5.20519.18/tasks/netcoreapp3.1/bincore/csc.dll" {args here}
done I'm wondering if something in particular about the way we setup our build scripts is causing thing. As a next step, I'm going to see if I can repeat the same issue with a fresh Blazor WASM template that includes some of the components triggering the error here. |
Some other things I tried:
I did both of these while the project was open in VS Code in case the bug has something to do with O#/the language server. Next thing is to try the minimal project used above in Visual Studio in case the bug is specific to that. |
Alright -- it doesn't look like this is particular to VS at all (but maybe specific to our build scripts). It looks like the offending state is stored in the intermediate directory. |
OK -- it looks like this is actually a variant of #20137 but somehow the RSG has exasperated the issue. |
Dumping some notes on this. So, because I can't have nice things, getting a good debugging setup for this is fairly annoying. I set up the goal of wanting to be able to debug this end-to-end from the
I spent some time (probably way more than necessary) trying to get this dream E2E debugging setup working. It included:
Then I stepped back and tried to focus on what particular aspect of the problem. The tag helpers that we care about are defined in the Microsoft.AspNetCore.Components.Web assembly -- so is there something particular going on with resolving tag helpers from this assembly? I hacked together a test scenario to validate this: [Fact]
public void Execute_EventHandler_CreatesDescriptor()
{
// Arrange
var compilation = BaseCompilation.AddSyntaxTrees(Parse(@"
using System;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
namespace Test
{
[EventHandler(""onclick"", typeof(Action<MouseEventArgs>))]
public class EventHandlers
{
}
}
"));
Assert.Empty(compilation.GetDiagnostics());
var context = TagHelperDescriptorProviderContext.Create();
var location = "/Users/captainsafia/aspnetcore/artifacts/bin/Microsoft.AspNetCore.Components.Web/Debug/net6.0/ref/Microsoft.AspNetCore.Components.Web.dll";
var reference = MetadataReference.CreateFromFile(location);
var compilation2 = compilation.AddReferences(new[] { reference });
context.Items.SetTargetAssembly((IAssemblySymbol) compilation.GetAssemblyOrModuleSymbol(reference));
context.SetCompilation(compilation2);
var provider = new EventHandlerTagHelperDescriptorProvider();
// Act
provider.Execute(context);
} When debugging through this, I discovered that this check tends to fail in the test scenario aspnetcore/src/Razor/Microsoft.CodeAnalysis.Razor/src/EventHandlerTagHelperDescriptorProvider.cs Line 81 in f7e8896
Because This was an interesting lead and I decided to see if the same thing could possibly be happening in some occasions when we we build on the CLI. On Pranav's recommendation, I ended up just copying the required assemblies we build in our repo to the installed SDK. $ cp ./artifacts/bin/Microsoft.AspNetCore.Mvc.Razor.Extensions/Debug/netstandard2.0/*.dll ./.dotnet/sdk/<version-number>/Sdks/Microsoft.NET.Sdk.Razor/tools/*.dll Weirdly enough, the issue did not repro with the development assemblies. I chatted with Pranav about this and he mentioned that perhaps the distinction is caused by the difference in configuration between the assemblies that actually get used in the SDK ( I had debated this originally but I found this to be extremely unlikely. Unless we're dealing with an extremely opaque issue that difference in configuration shouldn't be causing the behavior we see here. Then again, maybe there's an ifdef buried deep in the Razor compiler that is resulting on this. In any case, it doesn't hurt to try. So I built the Razor dependencies in a release configuration: $ cd src/Razor
$ ./build.sh -c Release Copied over the assemblies into the locally installed .dotnet and tried again. No dice, the issue still didn't repro. On a whim, I decided to remove a modification that I had made inside the - while (!System.Diagnostics.Debugger.IsAttached)
- {
- System.Console.WriteLine($"Waiting to attach on ${System.Diagnostics.Process.GetCurrentProcess().Id}");
- System.Threading.Thread.Sleep(1000);
- } Maybe suspending the thread in the code above was removing whatever factor caused the issue to repro. Doesn't hurt to try. I removed this and the issue reproed. Aha! I still needed to be able to debug though so I added the following property to the <_RazorSourceGeneratorDebug>true</_RazorSourceGeneratorDebug> Alongside this, I added a function breakpoint at I stepped through until we were discovering descriptors in the The descriptors are resolved from the cache. And the correct descriptors are resolved from the cache. Perhaps attaching via the debugger was causing the issue not to repro? I disabled the attach to debug code and managed to get a repro once, but wasn't able to reproduce after I added some file logging in Once again, running: # in src/Components
$ for i in {0..9}; do ./build.sh ; done doesn't surface any exceptions when using the locally built packages. So, the issue deepens. So far:
|
Thanks to @HaoK and @javiercn for the help rubber ducking this. The issue seems to be related to the caching implementation that we use to cache tag helper descriptors in the Razor source generator. This implementation is temporary and will be usurped by the work that we do in #31244 to migrate to the new incremental source generator API. Another hunch we had is that the issue might not repro on CI because of the Sooooooo, for now, I say we wait to see how things shake out when we migrate to the incremental source generator API. |
Update: I've added a way to support override the |
This seems to be a new issue since yesterday, as far as I can tell. Note that it works fine when building from the command line.
Repro: Open
ComponentsNoDeps.slnf
in Visual Studio and try to buildBasicTestApp
This happens in other sample projects too if I add a
[Parameter]
property.I'm unsure why this would only affect building inside VS and not the command line. Might it be something to do with source generator changes? I tried the following VS versions:
... with the same results on both.
The text was updated successfully, but these errors were encountered: