asp.net-mvcazureazure-devopsazure-pipelines

Azure DevOps CI - Can't Deploy bc System.Text.Json, Version=8.0.0.4 not found


I'm trying to resubmit a question from another author that was closed for lack of details. I have an ASP MVC .NET6 WebApp that has been running fine for a long time. Yesterday, I added some minor code and pushed it to my Devops repository which is linked via Pipeline to a staging slot on my Webapp (via Deployment Center section). This has all been working fine for many months but yesterday, it started failing. My deployment log looks fine until it hits this error

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\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\[MyApp].csproj]
    Done Building Project "C:\home\site\repository\[MyApp].csproj" (default targets) -- FAILED.

I don't even use System.Text.Json in my code although it is certainly a dependency of several other nuget packages (Azure.Storage.Blobs, Azure.Search etc...)

I'm confused on what 'Version=8.0.0.4' is anyway? Why 4 levels? Shouldn't it be 8.0.0? Looking at the project.assets.json, none of the dependencies require that version.

My temp solution was to compile locally and deploy myself. I have to create a brand new slot and, using VS Code's Azure Tools, do an Azure App Service: Deploy to Slot. This only works on a brand new slot - it fails if I try to deploy to the slot that previously failed using the DevOps deployment above above.

Any advice on how to actually fix the problem in my Devops deploy would be welcome.


Solution

  • Based on your description, when you using deployment center to deploy .net6 project, it will show the error:

    Could not load file or assembly 'System.Text.Json, Version=8.0.0.4,...

    I had the exact same problem 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. .net6.0)in your web app or project.

    The issue seems to come from the App service itself. I suggest that you can report this issue to Product Feedback site: Azure Community

    For a workaround, you can define global.json file at the root of your project and set the target .net version.

    For example: .net6.0

    global.json

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

    Here are the available .net version in Web App:

    enter image description here

    In this case, it will use the version set in global.json file to build and deploy your project.