2

I'm trying to reference a class library from a Blazor WebAssembly project but getting an error that Blazor WebAssembly projects cannot reference ASP.NET Core shared framework projects. I've tried changing the class library target to .Net Framework but that breaks it. I'm at a loss here. How do I get this class library referenced?

Class Library project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.9">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.9">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Piranha" Version="9.1.1" />
    <PackageReference Include="Piranha.AspNetCore" Version="9.1.0" />
  </ItemGroup>

</Project>

enter image description here

3
  • Which version of ".Net Framework" did you change it to? Commented Sep 14, 2021 at 16:35
  • 4.5.1, Kirk. But I'm beginning to think that's not the problem. I started an entirely new Blazor project and instead of trying to reference the scaffolded class library, I scaffolded the database into the BlazorWebAssembly.Shared class library. That seems to work, but I'm not too happy about not being able to reuse a class library. Kind of defeats the whole DRY principle. Commented Sep 14, 2021 at 19:02
  • Well, since 4.5.1 would absolutely never work for this, that is indeed at least part of your problem. At this point all of your projects (including the class library) should be targeting .NET5 (and soon .NET6). Commented Sep 14, 2021 at 19:39

1 Answer 1

3

I'm trying to reference a class library from a Blazor WebAssembly project

WebAssembly supports a subset of .net[5/core]. And that subset does not inlcude the SqlServer classes.

The direct error may point at some other cause, it's not clear. But this setup is not going to work. All Database operations have to happen on the Server.

That is why we have the [x] asp.net core hosted option in the New Project wizard.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.