Search code examples
.net-coreblazorwebassembly.net-standard-2.1.net-5

How do I share a class between Blazor wasm and .Net 5?


I have a Blazor wasm app (.net standard 2.1), and i want to share a .Net 5 class library. I thought that when .Net 5 came out that there would be harmony among the .net core and .net standard universes, but i'm not seeing it in the latest versions of my .Net 5 SDKs, runtimes, and VS 2019.

I get a project ref error in my Blazor app when i reference the .net 5 libs, but all is fine if i reference a .net standard 2.1 lib.

Do i have to downgrade my shared libs to .net standard 2.1?

I'm running: .Net SDK:

3.1.400-preview-015203
5.0.100-preview.7.20366.6

.Net runtimes:

Microsoft.NETCore.App 3.1.2   
Microsoft.NETCore.App 5.0.0-preview.7.20364.11

VS 2019 Preview:

Version 16.7.0 Preview 6.0

Solution

  • I have a Blazor wasm app (.net standard 2.1)

    You should upgrade that to .net 5 (preview) too of course.

    In the standard Hosted Webassembly template the shared class library is a net5.0 project.

    See the upgrade instructions.