Visual studio 2012 project - Not able to load 'Newtonsoft.Json'

久未见 提交于 2019-12-06 12:09:04

问题


On running a windows phone project in VS 2012, I was getting this error:

    {System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
File name: 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
   at MobileConnection.SSCClient.SSCConnection.GetHostNameAndPort()
   at MobileConnection.SSCClient.SSCConnection.InitializeSSCConnection(Boolean runningState)}

The corresponding entries in .csproj file is:

    <Reference Include="Newtonsoft.Json">
  <HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\sl4-windowsphone71\Newtonsoft.Json.dll</HintPath>
</Reference>

And, in packages.config:

  <package id="Newtonsoft.Json" version="4.5.11" targetFramework="wp80" />

I debugged it for a while, re-installed the newtonsoft.json package through nuget.
But the solution that worked for me is setting the 'private' property to 'True'.

Updated entry in .csproj file:

<Reference Include="Newtonsoft.Json">
  <HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\sl4-windowsphone71\Newtonsoft.Json.dll</HintPath>
   <Private>True</Private>
</Reference>

I am not able to understand how it worked or what the issue was. The description on msdn documentation didn't help much either http://msdn.microsoft.com/en-us/library/vstudio/bb629388.aspx.


回答1:


When running the program, it pulls in dlls from the output directory. Originally, Newtonsoft.Json wasn't being copied to the output directory, but by specifying Private to True, you told Visual Studio to copy the Newtonsoft.Json dll to the output folder along with your program.

For completeness, the documentation on Private:

Optional boolean. Specifies whether the reference should be copied to the output folder. This attribute matches the Copy Local property of the reference that's in the Visual Studio IDE.



来源:https://stackoverflow.com/questions/16999777/visual-studio-2012-project-not-able-to-load-newtonsoft-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!