asp.net-coreazure-web-app-service

Azure App Service Deployment fails with System.Text.Json


I have setup an Azure Deployment

Deployment config

And when I deploy it failed

Deploy fails

The error is

"C:\home\site\repository\WebProject.Api\WebProject.Api.csproj" (default target) (1:7) ->
(ResolvePackageAssets target) -> 
  C:\Program Files (x86)\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1060: Error reading assets file: Error loading lock file 'C:\home\site\repository\YoureOnTime.Api\obj\project.assets.json' : Could not load file or assembly 'System.Text.Json, Version=8.0.0.4, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. [C:\home\site\repository\WebProject.Api\WebProject.Api.csproj]

    111 Warning(s)
    1 Error(s)

I have included this project in with Nuget

  <ItemGroup>
    ...
    <PackageReference Include="System.Text.Json" Version="8.0.4" />
    ...
  </ItemGroup>

But still get the error. Any ideas on how to resolve?


Solution

  • From your screenshot of the Deployment Center, it seems your the project is using .net8. But the build step in Deployment Center is using .net 9 version(9.0.100).

    C:\Program Files (x86)\dotnet\sdk\9.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1060: Error reading assets file ....

    I had the exact same issue on my recent deployments.

    The root cause of the issue is that the Azure Web App Service will keep using the .net9(.net 9.0.100) by default and will ignore the custom .net version (e.g. .net8.0)in your web app or project.

    The issue seems to come from the App service itself. We can monitoring this ticket from Azure Feedback site: Using Azure DevOps CI, I Can't Deploy .Net 6 WebApp bc System.Text.Json, Version=8.0.0.4 not found

    To workaround this issue, we can define global.json file at the root of your project to force build using the correct .net version.

    For example:

    global.json

    {
      "sdk": {
        "version": "8.0.400",
        "rollForward": "latestFeature"
      }
    }
    

    Then it will use the version set in global.json file to build and deploy your project.