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

Razor Class Library project cannot be referenced by Blazor WASM project: The type or namespace name 'ApplicationPartAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?) #26724

Closed
zxyao145 opened this issue Oct 9, 2020 · 5 comments
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@zxyao145
Copy link

zxyao145 commented Oct 9, 2020

Describe the bug

I'm trying to migrate the blade project to NET 5.0 RC1, but after adding a reference to the Razor Class Library project to the WASM project, the compiler prompts an error:

obj\Debug\net5.0\XXXX\XXXX.MvcApplicationPartsAssemblyInfo.cs(14,54,14,78): error CS0234: The type or namespace name 'ApplicationPartAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Mvc.ApplicationParts' (are you missing an assembly reference?).

When change the SDK Microsoft.NET.Sdk.BlazorWebAssembly to Microsoft.NET.Sdk.Web (similar to using NET Core 3.1), I can build the project success, but It's not generate as the Blazor WASM project. Then I found the solution is in issues 24171:

Add <GenerateMvcApplicationPartsAssemblyAttributes>false</GenerateMvcApplicationPartsAssemblyAttributes> to project props.

And It's helpful. The issue has been closed, and I think this may be a bug, please fix it, thanks a lot!

To Reproduce

Exceptions (if any)

Further technical details

  • Include the output of dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.100-rc.1.20452.10
 Commit:    473d1b592e

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.100-rc.1.20452.10\

Host (useful for support):
  Version: 5.0.0-rc.1.20451.14
  Commit:  38017c3935

.NET SDKs installed:
  2.1.810 [C:\Program Files\dotnet\sdk]
  3.1.402 [C:\Program Files\dotnet\sdk]
  5.0.100-rc.1.20452.10 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-rc.1.20451.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0-rc.1.20451.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0-rc.1.20452.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

  • The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version
    VS 2019 16.8.0 Preview 3.2
@javiercn
Copy link
Member

javiercn commented Oct 9, 2020

@zxyao145 thanks for contacting us.

Most likely you created a razor class library with support for pages and views or referenced a library that targets ASP.NET Core. As such, that is not going to work in Blazor Webassembly.

I suggest you look at your dependencies to identify what is bringing on the ASP.NET Core framework and remove it or factor it out of your library.

@javiercn javiercn added area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question labels Oct 9, 2020
@ghost ghost added the Status: Resolved label Oct 9, 2020
@zxyao145
Copy link
Author

zxyao145 commented Oct 9, 2020

@javiercn
Yes, my application has two modes: Blazor Server and Blazor WASM, I reuse the razor pages in Blazor Server project and Blazor WASM project, and I think this situation may be more common. Is there any deficiency in the current scheme, or is there a better solution?

Thank you very much!

@javiercn
Copy link
Member

javiercn commented Oct 9, 2020

No, this is just how dependencies work. You need to factor your app to avoid bringing in server dependencies on the wasm payload.

@zxyao145
Copy link
Author

@javiercn OK, thank you very much!

@ghost
Copy link

ghost commented Oct 11, 2020

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Oct 11, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Nov 10, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

2 participants