0

I created two fresh new projects a Blazor Web Assembly without checking the option of ASP.NET Core hosted because I did not want to create the other two projects that get created. Followed by a fresh new ASP.NET Core Web API project. After creating this project and writing any code, I added a few nuget packages to my web api project that I plan on using. I then expanded the Blazor Web Assembly project and right clicked on Dependencies, clicked on Add Project Reference and selected my Web API project. Then when building both projects, the web api passes and the blazor web assembly fails because of Error NETSDK1082. The exact error is shown below.

C:\Program Files\dotnet\sdk\6.0.100-preview.3.21202.5\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(391,5): error NETSDK1082: There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'browser-wasm'.

I looked up online for that error and attempted the solution where I add two lines of code into my .csproj file inbetween the <PropertyGroup> section, but even after adding this it failed. I even deleted the obj folder and rebuilt the blazor project but it produced the same error.

<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<UseBlazorWebAssembly>true</UseBlazorWebAssembly>

Blazor Web Assembly Project:

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.10" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.10" PrivateAssets="all" />
    <PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\PolkWebAPI\PolkWebAPI.csproj" />
  </ItemGroup>

</Project>

ASP.NET Core Web API Project:

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.10">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.2" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
  </ItemGroup>

</Project>

I have not added any code to any of the projects I just installed a few nuget packages to the web api project and added the project reference to the blazor web assembly which produced the error.

Following up to request:

in the project.assets.json file I see two other sections that include browser-wasm:

 "downloadDependencies": [
      {
        "name": "Microsoft.NETCore.App.Runtime.browser-wasm",
        "version": "[5.0.4, 5.0.4]"
      }
    ],
    "frameworkReferences": {
      "Microsoft.NETCore.App": {
        "privateAssets": "all"
      }
    },
    "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.100-preview.3.21202.5\\RuntimeIdentifierGraph.json"
  }
},
"runtimes": {
  "browser-wasm": {
    "#import": []
  }
}

Which section are you talking about to uninstall each nuget package manually ?

1 Answer 1

2

Update: It seems you were trying to add a reference to the Web API to the blazor web assembly (WA) project. You do not need to do that. There are two WA models:

  1. .net core hosted: You can create this type of project by ticking the ".net core" hosted when creating your WA project. It creates three projects by default. Client, server (mostly API controllers) and shared. Client and server both refer to the shared project. The shared project has all the classes that both WA application and controllers in server.
  2. Standalone: In this case, you get two projects. Note that you can add another shared project like in (1) above to use classes that both can use. However, in this case the API controller need not even know it is talking to a blazor app.

You see the 'browser-wasm' error because of nuget packages that are incompatible with blazor wasm. You got the error because you added the server project reference to the WA project.

Read more here

If cleanly opting for (1) or (2) does not work, search for project.assets.json in your project folder and search the section with browser-wasm. Check the list of packages in that section and try uninstalling those nuget packages one by one.

https://github.com/dotnet/aspnetcore/issues/36711

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

10 Comments

I see, I guess even the standard web api nuget packages that came pre-installed are incompatible because I just created the same two projects but this time without adding any nuget packages and just adding the web api project as a project reference in the blazor web assembly. But I found the project.assets.json file and searched for browser-asm I see a section named net5.0/browser-wasm which begins on line 1797 to 3600. Is it that super long section I have to uninstall all those nuget packages one by one?
I also see two sections that show the following in the original post. Please check that out as well.
You seem to have two different targets (.net5 and .net6). Can you do a clean start in either one of them and see if it works?
I just created a brand new blazor web assembly and made sure the target framework is .NET 5.0 (Current) and only selecting Configure for HTTPS. Then under the same solution, I added a ASP.NET Core Web API with Target Framework of .NET 5.0 (Current), Selected Configure for HTTPS and clicked on Enable OpenAPI support. I then build them individually and ran them individually. The blazor wa was ran on IIS express which worked. I then ran the web api as IIS Express and that worked as well.
This time, I did not add any nuget packages either for these sets of projects. After running them individually on the blazor wa I right clicked -> add -> project reference -> selected WebApi. Then right clicked on the solution (2 projects) -> set startup projects -> made sure "Start" was selected for both projects. Hit the play button but I get the same error NETSDK1082. But how is it two different targets if both projects were selected with .NET 5.0?
|

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.