Azure cloud service: System.Net.Http.Formatting.dll requests old Newtonsoft.Json.dll -> role initialization fails


I have pretty big solution with about 80 projects, running on the Azure cloud service server as Web role using WebAPI (v1). I have created new enhancement regarding content negotiation by implementing custom JsonReader/Writer. When I have tried use it by implementing custom MediaTypeFormatter based on the BaseJsonMediaTypeFormatter it fails - to be precise, it fails when published to the Azure. Locally emulated it works perfectly. Once published it fails as:

Role entrypoint could not be created: System.TypeLoadException: Unable to load the role entry point due to the following exceptions:
-- System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Newtonsoft.Json, Version=, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Appbase = file:///E:/approot/bin
LOG: Initial PrivatePath = E:\approot\bin
Calling assembly : System.Net.Http.Formatting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

(Log captured from EventViewer->Application and Services log->Windows Azure).

Until I tried to use my custom MediaTypeFormatter everything worked correctly. I have searched internet and SO for some solution, and although the problem is not as rare as I thought none of the solution helped me. What have I tried:

  • consolidated all versions of Newtonsoft.Json nugets in all referencing projects
  • consolidated all versions of Microsoft.AspNet.WebApi.Client nuget
  • removed all references to both mentioned libraries and replaced these references to dll by referencing the nuget instead
  • upgraded both Nuget packages to the latest version (Json 12.0.3 and Formatting 5.2.7) (I have even tried to use -reinstall parameter in Update-Package command)
  • checked all csproj manually for referencing old Newtonsoft.Json version.
  • Cleaned up solution, bin, obj folders, all cache files
  • my web.config file contains (and have always contained) correct bindingRedirect for Newtonsoft.Json
  • (and probably some other stuff, which I have already forgotten)

None of the solution worked and I still get this strange message. My questions are:

  • How is it possible, that System.Net.Http.Formatting library requires some specific version of Newtonsoft.Json when I explicitly say it should redirect to the 12th version? Is it because it happens during Webrole start (maybe because it doesn't respect web.config yet?)
  • Why does it work on my computer, but does not deployed on the Azure cloud service? Does it somehow find and use also the old verison of Newtonsoft.Json lib on my local computer (and where, so I can try to remove it)?
  • Is there any better way to debug this issue? Maybe log the sequence of loading referenced DLLs to get closer to the error? Or to duplicate the error on my local computer? At the moment it is very time consuming to deploy application, log on the remote desktop and check EventViewer on cloud service...

Any hint to find the issue will be appreciated.

asked on Stack Overflow Jun 24, 2020 by Zoka

1 Answer


You are very close to the solution with your web.config assembly binding. However, the error message says "Unable to load the role entry point". Your role entry point is your binary that hosts the OnStart/Run methods (ie. WebRole1.dll), which is different from your website content hosted in IIS.

To resolve this, open the .dll.config located in your project bin folder and use the same assembly binding information, then redeploy your service.

For more details see

answered on Stack Overflow Jul 21, 2020 by kwill

User contributions licensed under CC BY-SA 3.0