sofu6

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

There are a couple of projects in my sln, in which two projects used the json.net. One is a webapi project, which is based on webapi 2, the system.web.mvc is 5.0.0.0 and used the json.net with version 4.5 .

Because nuget is not always working fine in every pc. So all of our pojects's reference are adding the dll referdirectly instead of using nuget tools to manage packages.

Unfortunately, another project is using a json.net( 12.0) with a different verison from the webapi project used and this project is referenced by webapi project. When I run the webapi project, it shows error like this:

{"Could not load file or assembly 'Newtonsoft.Json, Version=4.5.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)":"Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"}

I guess it's because of different json versions caused. The last solution is, I upgrade all versions to the same version. 

For webapi, if you only add the higher version json.net to its reference, this is not enough. You should need to change the web.config file. Add or modify the paragraph with the information of json.net like this:

<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>

Another question, when you clean the bin folder, maybe when you run webapi again, it will show the following error on the page:

Server Error in '/' Application.


Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0234: The type or namespace name 'Ajax' does not exist in the namespace 'System.Web.Mvc' (are you missing an assembly reference?)

Source Error:

 
Line 22:     using System.Web.WebPages;
Line 23:     using System.Web.Mvc;
Line 24:     using System.Web.Mvc.Ajax;
Line 25:     using System.Web.Mvc.Html;
Line 26:     using System.Web.Optimization;


Source File: c:\Users\Backend Developer\AppData\Local\Temp\Temporary ASP.NET Files\root\cb44be3d\fc06c785\App_Web_index.cshtml.a8d08dba.ulovhbvh.0.cs    Line: 24






Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4075.0

 

The solution is referencing the stack page: https://stackoverflow.com/questions/14824228/cs0234-mvc-does-not-exist-in-the-system-web-namespace

please see the highest praise answer.

 

posted on 2020-05-23 21:35  sofu6  阅读(423)  评论(0编辑  收藏  举报