zoukankan      html  css  js  c++  java
  • 一个关于Newton.soft 的json.net版本不一致的问题。

    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:UsersBackend DeveloperAppDataLocalTempTemporary ASP.NET Files ootcb44be3dfc06c785App_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.

  • 相关阅读:
    HUSTOJ:Transit Tree Path
    HUSTOJ:5500 && 洛谷:P1412:经营与开发
    hdu:2036.改革春风吹满地
    hdu:2030.汉字统计
    Leetcode:338. Bit位计数
    【学习笔记】圆方树(CF487E Tourists)
    BZOJ3238 [Ahoi2013]差异
    CF 187D BRT Contract
    CF 36E Two Paths
    CF 49E Common ancestor
  • 原文地址:https://www.cnblogs.com/dusf/p/12944566.html
Copyright © 2011-2022 走看看