Skip to content
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

MSBuildWorkspace does not cleanly load blazorwasm project #72015

Closed
JoeRobich opened this issue Feb 9, 2024 · 12 comments · Fixed by #72057
Closed

MSBuildWorkspace does not cleanly load blazorwasm project #72015

JoeRobich opened this issue Feb 9, 2024 · 12 comments · Fixed by #72057
Assignees
Labels

Comments

@JoeRobich
Copy link
Member

Version Used: 4.10 Preview 1

Reported in #69225

Steps to Reproduce:

  1. dotnet new blazorwasm (or blazor or blazorwasm-empty)
  2. use MSBuildWorkspace.OpenProjectAsync to load the newly created project

Expected Behavior:
Project loads without any workspace diagnostics and compilation reports no compiler diagnostics.

Actual Behavior:
Compilation reports "CS0246: The type or namespace name {'csharp_blazor_project'|'App'} could not be found (are you missing a using directive or an assembly reference?)"

Possibly unrelated
I noticed that the C# extension in VS Code reports the following when opening the blazorwasm project.

Generator 'RazorSourceGenerator' failed to initialize. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'TypeLoadException' with message 'Type 'Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.HostOutputNode`1[TInput]' from assembly 'Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler, Version=4.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is attempting to implement an inaccessible interface.'.
System.TypeLoadException: Type 'Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.HostOutputNode`1[TInput]' from assembly 'Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler, Version=4.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is attempting to implement an inaccessible interface.
   at Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.GeneratorExtensions.RegisterHostOutput[TSource](IncrementalGeneratorInitializationContext& this, IncrementalValuesProvider`1 source, Action`3 action)
   at Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator.Initialize(IncrementalGeneratorInitializationContext context)
   at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken) in /_/src/Compilers/Core/Portable/SourceGeneration/GeneratorDriver.cs:line 226
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 9, 2024
@jasonmalinowski
Copy link
Member

@jaredpar @chsienki @jjonescz I'm wondering if this was broken by #71579. The generator being loaded from the SDK is one that still expects the ExternalAccess to be there, but we don't have it any more for newer Roslyn builds.

This seems like fallout for how the razor generator is expected to load:

  • in a dotnet build, the SDK bits are all matched.
  • in VS for Windows, we're loading the generator that ships in the IDE so it's matched with the compiler bits there
  • for VS Code we're discussing doing the same thing, but we're not doing that yet, which might explain the error @JoeRobich saw
  • for MSBuildWorkspace we'll do...what? We're not shipping a Razor generator to load from anywhere that may match the Roslyn version the user's app is.

@jasonmalinowski jasonmalinowski added IDE-MSBuildWorkspace MSBuildWorkspace and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 10, 2024
@jjonescz
Copy link
Contributor

jjonescz commented Feb 12, 2024

If I read the error message correctly, the ExternalAccess.RazorCompiler dll is present, it just cannot implement internal CodeAnalysis interface anymore. I think we could just keep the IVT around to solve this (#71579 (comment)).

@jasonmalinowski
Copy link
Member

@jjonescz Does that mean at this point the expectation is the core compiler binaries are always maintaining the APIs that the old ExternalAccess was accessing?

@JoeRobich
Copy link
Member Author

Verified locally that the fix @jjonescz proposes will resolve this issue.

@jjonescz
Copy link
Contributor

jjonescz commented Feb 13, 2024

Does that mean at this point the expectation is the core compiler binaries are always maintaining the APIs that the old ExternalAccess was accessing?

Hm, good question. It should be enough if we keep them as stubs (if we want to remove or rename them in the future) - because the razor compiler doesn't rely on them working (the machinery was supposed to be used by razor IDE to get design-time outputs out of the razor compiler).

@jonashendrickx
Copy link

When can we expect the fix to be released?

@jjonescz
Copy link
Contributor

jjonescz commented Feb 19, 2024

When can we expect the fix to be released?

Visual Studio 17.10 Preview 2 (and .NET SDK 8.0.300 I think). In about a month.

@jonashendrickx
Copy link

jonashendrickx commented Feb 19, 2024

When can we expect the fix to be released?

Visual Studio 17.10 Preview 3 (and .NET SDK 8.0.300 I think). In about a month.

Doesn't it affect also Visual Studio / MSBuild 17.9? My Blazor project has been broken since 17.9 when running dotnet format. Can you backport the fix 17.9? Feel free to clone bitwarden/passwordless-server. We are open-source.

@jjonescz
Copy link
Contributor

Doesn't it affect also Visual Studio / MSBuild 17.9?

I don't think that's possible, the issue described here was introduced in VS 17.10 Preview 1 by #71579 which didn't get into VS 17.9 nor SDK 8.0.200.

Can you backport the fix 17.9?

The IVT has never been removed from the 17.9 branch, so there's nothing to fix there:

<InternalsVisibleTo Include="Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler" />

@jasonmalinowski
Copy link
Member

@jonashendrickx Can you share the error you're getting just to make sure we're discussing the same bug?

@jjonescz
Copy link
Contributor

@jasonmalinowski see dotnet/format#2119

@jonashendrickx
Copy link

jonashendrickx commented Feb 21, 2024

@jasonmalinowski https://github.com/bitwarden/passwordless-server/actions/runs/7989471492/job/21816103177

It's here saying the directives are unused and cannot be removed, but they are in fact being used.

The source code for workflow below: https://github.com/bitwarden/passwordless-server/tree/fix/is-app-id-available-endpoint-is-returning-a-500-in-admin-console

2024-02-21T13:01:29.7919720Z [command]/home/runner/work/_actions/actions/setup-dotnet/4d6c8fcf3c8f7a60068d26b594648e99df24cee3/externals/install-dotnet.sh --skip-non-versioned-files --runtime dotnet --channel LTS
2024-02-21T13:01:30.3940233Z dotnet-install: .NET Core Runtime with version '8.0.2' is already installed.
2024-02-21T13:01:30.3969568Z [command]/home/runner/work/_actions/actions/setup-dotnet/4d6c8fcf3c8f7a60068d26b594648e99df24cee3/externals/install-dotnet.sh --skip-non-versioned-files --version 8.0.101
2024-02-21T13:01:31.4632143Z dotnet-install: Attempting to download using primary link https://dotnetcli.azureedge.net/dotnet/Sdk/8.0.101/dotnet-sdk-8.0.101-linux-x64.tar.gz
2024-02-21T13:01:32.7210288Z dotnet-install: Remote file https://dotnetcli.azureedge.net/dotnet/Sdk/8.0.101/dotnet-sdk-8.0.101-linux-x64.tar.gz size is 214222713 bytes.
2024-02-21T13:01:32.7215881Z dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/8.0.101/dotnet-sdk-8.0.101-linux-x64.tar.gz
2024-02-21T13:01:37.5465832Z dotnet-install: Downloaded file size is 214222713 bytes.
2024-02-21T13:01:37.5467562Z dotnet-install: The remote and local file sizes are equal.
2024-02-21T13:01:37.8158346Z dotnet-install: Installed version is 8.0.101
2024-02-21T13:01:37.8220046Z dotnet-install: Adding to current process PATH: `/usr/share/dotnet`. Note: This change will be visible only when sourcing script.
2024-02-21T13:01:37.8221990Z dotnet-install: Note that the script does not resolve dependencies during installation.
2024-02-21T13:01:37.8224241Z dotnet-install: To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
2024-02-21T13:01:37.8226063Z dotnet-install: Installation finished successfully.
2024-02-21T13:01:37.8420197Z ##[group]Run dotnet format --verify-no-changes
2024-02-21T13:01:37.8420697Z �[36;1mdotnet format --verify-no-changes�[0m
2024-02-21T13:01:37.8463900Z shell: /usr/bin/bash -e {0}
2024-02-21T13:01:37.8464208Z env:
2024-02-21T13:01:37.8464417Z   TERM: xterm
2024-02-21T13:01:37.8464741Z   DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: true
2024-02-21T13:01:37.8465162Z   DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
2024-02-21T13:01:37.8465487Z   DOTNET_NOLOGO: true
2024-02-21T13:01:37.8465742Z   DOTNET_CLI_TELEMETRY_OPTOUT: true
2024-02-21T13:01:37.8466060Z   DOTNET_ROOT: /usr/share/dotnet
2024-02-21T13:01:37.8466364Z ##[endgroup]
2024-02-21T13:03:12.1957172Z ##[warning]/home/runner/work/passwordless-server/passwordless-server/src/AdminConsole/Program.cs(6,1): warning IDE0005: Using directive is unnecessary. [/home/runner/work/passwordless-server/passwordless-server/src/AdminConsole/AdminConsole.csproj]
2024-02-21T13:03:12.1967471Z ##[warning]/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/Components/Pages/App/ReportingComponents/TotalUsersCountChartTests.cs(6,1): warning IDE0005: Using directive is unnecessary. [/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/AdminConsole.Tests.csproj]
2024-02-21T13:03:12.1971605Z ##[warning]/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/Components/Pages/App/Settings/AuthenticatorsTests.cs(7,1): warning IDE0005: Using directive is unnecessary. [/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/AdminConsole.Tests.csproj]
2024-02-21T13:03:12.1976024Z ##[warning]/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/Components/Pages/App/ReportingComponents/TotalCredentialsCountChartTests.cs(6,1): warning IDE0005: Using directive is unnecessary. [/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/AdminConsole.Tests.csproj]
2024-02-21T13:03:12.1979942Z ##[warning]/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/Components/Shared/BreadCrumbTests.cs(3,1): warning IDE0005: Using directive is unnecessary. [/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/AdminConsole.Tests.csproj]
2024-02-21T13:03:12.1983544Z ##[warning]/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/Components/Shared/SecureScriptTests.cs(6,1): warning IDE0005: Using directive is unnecessary. [/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/AdminConsole.Tests.csproj]
2024-02-21T13:03:12.1987192Z ##[warning]/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/Components/Shared/SecureStylesheetTests.cs(6,1): warning IDE0005: Using directive is unnecessary. [/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/AdminConsole.Tests.csproj]
2024-02-21T13:03:12.1990922Z ##[warning]/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/Components/Shared/Stats/SimpleCardsStatsTests.cs(2,1): warning IDE0005: Using directive is unnecessary. [/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/AdminConsole.Tests.csproj]
2024-02-21T13:03:12.1994619Z ##[warning]/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/Components/Shared/Stats/TrendingCardsStatsTests.cs(2,1): warning IDE0005: Using directive is unnecessary. [/home/runner/work/passwordless-server/passwordless-server/tests/AdminConsole.Tests/AdminConsole.Tests.csproj]
2024-02-21T13:03:23.1086926Z ##[error]Process completed with exit code 2.
2024-02-21T13:03:23.1171351Z Post job cleanup.

If you are in doubt, create a new Blazor project, apply an editorconfig with dotnet_diagnostic.IDE0005.severity set to warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants