0
votes

I have a web api project targeting 4.6.1 framework and deploying it as cloud service on Azure. Getting below error while deploying.

Web.Config details:

  <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>

Error from event viewer:

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 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

I don't have reference of System.Web.Http, Version=4.0.0.0 in my solution. Please let me know what am I doing wrong.

1

1 Answers

3
votes

We may get the answer from this blog. It elaborates the root reason and resolution. The following is the snippet from the blog.

Solution:

1) Open the .dll.config located in your project bin folder.

2) Check if there is the BindingRedirect entry that you need. If not, follow one of the two options below: a) Copy the web.config or app.config content (considering one of these two configuration files has the information that you need) and paste it into the .dll.config file. b) Manually create an Assembly Binding entry:

3) Add the .dll.config file to your Solution (same level as the web.config or app.config) and set the Copy to Output Directory property to “Copy Always”.

Root reason:

Usually, when a new assembly is added to your project, Visual Studio will automatically create a bindingRedirect entry in your web.config (Web Role) or app.config (Worker Role) just to avoid the wrong assembly version issue.

However, in Azure Cloud Services, the assembly bindings from web.config and app.config does not have effect, due to the fact that WaIISHost (Web Role) and WaWorkerHost (Worker Role) are not able to read these two configuration files, instead, they read the .dll.config file, and this is the file where the assembly binding configuration need to be