FileLoadException was unhandled by user code

后端 未结 4 1390
无人共我
无人共我 2021-01-02 23:52

I am setting up the API for my MVC-4 app and when I uncommented this line in Globals.asax.cs:

WebApiConfig.Register(GlobalConfiguration.Configuration);


        
相关标签:
4条回答
  • 2021-01-03 00:14

    It looks like that you don't have Newtonsoft.Json installed/referenced. Web API relies on this and won't work correctly until you resolve this dependency. You can install it via NuGet.

    0 讨论(0)
  • 2021-01-03 00:16

    Simply delete your Newtonsoft.Json dll from bin folder then open package.config file and remove your Newtonsoft.Json entry from there then reinstalled your Newtonsoft.Json by command but don't installed newer version if you face this problem with newer version find old version command

    like Install-Package Newtonsoft.Json -Version 6.0.8 now Install-Package Newtonsoft.Json -Version 7.0.1 is also aviable but i suggest to you installed 6.0.8 version its working

    0 讨论(0)
  • 2021-01-03 00:23

    This also occured to me today. Seems like there had been an update for json.net (now version 6.0.3), causing nuget to download the latest version after build. However references to old json.net libs might not get updated when there are depencies to other libs.

    Solution: Manually open the manage nuget packages for solution window and uninstall old version(s) of json.net. Then take the latest version and install for all needed projects. That fixed the exact error you had for me...

    -- edit --
    Ok, so I found out that this solution worked for me locally, but remotely this did not solve my issues. Seems like there are some old dependencies from other libs hard referencing the 4.5.0.0 version of json.net. More topics on Stackoverflow.com provide the following solution.

    Add this assembly binding redirect to your web.config file:

    <configuration>
        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <dependentAssembly>
                    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
                    <bindingRedirect oldVersion="1.0.0.0-4.5.0.0" newVersion="6.0.0.0"/>
                </dependentAssembly>
            </assemblyBinding>
        </runtime>
    </configuration>
    
    0 讨论(0)
  • 2021-01-03 00:27

    Most probably Newtonsoft.Json DLL is not properly deployed.

    Make sure you have the Newtonsoft.Json DLL in your (IIS / project) bin folder.
    Alternatively, you can also install that DLL to GAC if you plan to use it across multiple projects.

    0 讨论(0)
提交回复
热议问题