Joerg
Joerg

Reputation: 237

Blazor WASM error referencing Razor Class Library

We have one project that includes both a Razor Class Library and a WASM project. Both are .NET 5.0.

We test and demo the RCL using the WASM project which is published regularly and works fine.

We have created a nuget package of the RCL some time ago and used that successfully in a Blazor server-side project.

Now I am trying to reference the RCL in a new WASM project (also .NET 5.0) and I'm strangely getting this error:

  <Target Name="_FailIfReferencingAspNetCoreApp" BeforeTargets="ResolveRuntimePackAssets">
    <Error
      Code="BLAZORSDK1001"
      Text="The project references the ASP.NET Core shared framework, which is not supported by Blazor WebAssembly apps. Remove the framework reference if directly referenced, or the package reference that adds the framework reference."
      Condition="'@(FrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App')->Count())' != '0'" />
  </Target>

Is there something I'm missing? This is the .csproj of the RCL, which I guess is relevant:

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

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <PackageId>BlazorUI5</PackageId>
    <Version>1.0.39</Version>
    <Authors>CEO Dev Team</Authors>
    <Company>CEO Consultoría</Company>
    <PackageDescription>Blazor UI5 component package</PackageDescription>
    <RepositoryUrl>https://*******</RepositoryUrl>
    <AssemblyVersion>1.0.39.0</AssemblyVersion>
    <FileVersion>1.0.39.0</FileVersion>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="Helper\**" />
    <Content Remove="Helper\**" />
    <EmbeddedResource Remove="Helper\**" />
    <None Remove="Helper\**" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.3" />
  </ItemGroup>
  
  <ItemGroup>
    <SupportedPlatform Include="browser" />
  </ItemGroup>

</Project>

I find it strange that the reference works in the same solution, but it doesn't work using the package in another WASM solution, yet it does in another Blazor-server solution...

Any suggestions on what to check here?

Thanks,

Joerg

Upvotes: 1

Views: 1333

Answers (3)

Abubakar Salisu
Abubakar Salisu

Reputation: 1

Go to the Package Reference (Your Project > Dependencies > Packages) in visual studio and check the exact name of the dll. The name is case sensitive. In my .csproj file the name is "iTextSharp" , but in the Package Reference its "itextsharp.dll". The error was cleared when i changed it to "itextsharp.dll". Hope this helps someone

Upvotes: 0

Ahmed Khalil
Ahmed Khalil

Reputation: 1

I have the same problem too, it is a problem of microsoft doesn't send the right exception details, so you can publish your blazor wasm app using

dotnet publish -v detailed

so you will see the right exception

Upvotes: 0

JkAlombro
JkAlombro

Reputation: 1834

I think I have the same problem but slightly different situation. I have a Blazor WASM and I also created a RCL for my reusable components. I transferred all of my components to RCL and also downloaded Blazorise lib to that RCL then when I try reference it to my Blazor WASM, I got the same error like you did. I tried different online solution like restarting VS, deleting .vs folder, deleting bin folder, etc but nothing seems to work.

HOW I SOLVED IT

I created a new RCL and referenced it to my Blazor WASM app right away to see if it reacts the same but there's no error. I transferred my components one by one to see where the error will trigger but no error was found. Lastly, I installed Blazorise to my RCL and still no error. So basically I have a working RCL now that is basically the same one that got an error. The only difference was I referenced it first before transferring my components. I have no idea why the other one have an error but this solution might help others.

Upvotes: 0

Related Questions