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=6.0.0.0, 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=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
(Fully-specified)
LOG: Appbase = file:///E:/approot/bin
LOG: Initial PrivatePath = E:\approot\bin
Calling assembly : System.Net.Http.Formatting, Version=5.2.7.0, 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:
Newtonsoft.Json
nugets in all referencing projectsMicrosoft.AspNet.WebApi.Client
nugetUpdate-Package
command)csproj
manually for referencing old Newtonsoft.Json
version.web.config
file contains (and have always contained) correct bindingRedirect
for Newtonsoft.Json
None of the solution worked and I still get this strange message. My questions are:
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?)Any hint to find the issue will be appreciated.
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 https://docs.microsoft.com/en-us/archive/blogs/cie/cloud-services-roles-recycling-with-the-error-system-io-fileloadexception-could-not-load-file-or-assembly.
User contributions licensed under CC BY-SA 3.0