Home > Net >  Getting System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json'
Getting System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json'

Time:02-10

I've implemented Azure Pipelines to my GitHub repository. I haven't got any issues with deployment, but after running the application, I get 'HTTP Error 500.30 - ASP.NET Core app failed to start'. The 'Diagnose and solve problems' page shows me this:

HTTP Server Errors Page

Proceeding to Application Exceptions shows me this exception log:

  Application startup exception

  System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

   ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.

  File name: 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

  at Microsoft.AspNetCore.Mvc.MvcNewtonsoftJsonOptions..ctor()

I use "Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.2" package in this app, but not the Newtonsoft.Json, and the app works locally. There are a lot of posts with the same issues with Newtonsoft, but I didn't find any post about this error on Azure. Despite this I tried suggested solutions to solve this problem, like installing this package by Nuget or adding it to project folder and manually referencing it; changing version in .csproj file to '13.0.0.0' which, as Nuget page shows, does not exist (only 13.0.1 is available), but nothing helped - I still receive the same error.

Also, my project works not only locally, but on another Azure App Service (which was created accidentally with .NET 3.1 Build version, while my project is on the net6.0 and new App Service has .NET 6.0 Build), which I deployed manually, so I can assume that error can be related to .NET version. Could you, please, suggest any solutions or possible error causes?

CodePudding user response:

Troubleshooting Steps

1. Please share your .csproj file without any sensitive info.

We just want to doublecheck the .net version.

Next Action : Install the extension like below. And keep the RuntimeFrameworkVersion same as azure environment.

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <RuntimeFrameworkVersion>6.0.2</RuntimeFrameworkVersion>
    <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
    <OutputType>WinExe</OutputType>
    <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
  </PropertyGroup>
</Project>

enter image description here

2. Please share your .csproj file without any sensitive info.

Follow the tips to check the .Net Core Startup Failures.

  •  Tags:  
  • Related