0

I am trying to use Json.net in c# to write a json file. When I build the code it builds fine and creates a parser.exe fine. but when I try to run that parser.exe on a seperate server where it needs to run it gives me an error

System.IO.FileNotFoudException: Could not load file or assembly 
'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4f...' 
or one of its dependencies. The system cannot file the file specified. 

Do I need to copy Newtonsoft dll to the server it needs to run. Any help will be greatly appreciated.

jarus
  • 1,853
  • 11
  • 44
  • 76
  • Yes.. You need to copy all the dependent assemblies, libraries and dlls to the target location from where you run the exe. – Chetan Jul 25 '17 at 13:55
  • What type of IDE are you using? – EasyE Jul 25 '17 at 13:56
  • I'm using a visual studio community edition 2015 – jarus Jul 25 '17 at 13:58
  • Does the output contain a file with the name 'Newtonsoft.Json.dll' ? – Kees Jul 25 '17 at 14:03
  • I copied the dll onto the same path on the server it runs but it still gives me the same error C:\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll – jarus Jul 25 '17 at 14:38
  • @jarus it is giving you that error because it is looking for that dll and not finding it. You have to place that file in the Bin folder like my example says. – EasyE Jul 25 '17 at 15:54
  • @EasyE The dll file is inside the bin folder in my local computer from where I rebuild the code. I am copying just the exe file and uploading it to the server, where do I place the dll if I need to copy the dll to the server. – jarus Jul 25 '17 at 16:01
  • You have to copy the whole folder, not just the exe. You see the exe looks for those folders in order to get the library. So if you built it in debug or release you must copy the entire folder not just the exe. Please refer to my answer – EasyE Jul 25 '17 at 22:41

3 Answers3

2

Make sure the referenced DLL is set to be deployed to the bin folder by right clicking on the reference, selecting Properties and setting Copy Local to True.

UPDATE:

What's happening is that you have the DLL referenced locally but when you deploy your program, it's missing from the target machine.

By setting the reference to always be copied, your bin folder will have a copy of it so as long as you deploy it properly (including the bin folder), it should work.

JuanR
  • 7,405
  • 1
  • 19
  • 30
  • If you downvote something, it's common courtesy to at least leave a note explaining why or contributing in some way to improve the answer. – JuanR Jul 25 '17 at 14:05
  • 1
    I was down voted myself i do not know why? Smh – EasyE Jul 25 '17 at 22:46
1

Yes you will need to copy the entire Debug or Release folder which are located in in the Bin folder. Word of advice makes sure you rebuild your solution in order to get all recent changes made.

Example

C:\Folder\Projects\ConsoleAppTest\ConsoleAppTest\bin\Release

-OR-

C:\Folder\Projects\ConsoleAppTest\ConsoleAppTest\bin\Debug

EasyE
  • 560
  • 5
  • 26
  • You think he really forgot to copy all files? – Kees Jul 25 '17 at 14:05
  • @KeesdeWit Yes I am sure he did, I am familiar with what he is trying to do, specially with that message that he is receiving. – EasyE Jul 25 '17 at 14:06
0

There is probably a difference in the version. A dependency assembly requires 10.0.0.0 but you have referenced another version. Add this to your application config:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

Versions mentioned are just an example

Also make sure that the settings of the reference are as follows: enter image description here

Kees
  • 1,408
  • 1
  • 15
  • 27
  • Visual Studios add the those keys to the config file when installed through nuget. – EasyE Jul 25 '17 at 14:09
  • Thats true, but not without nuget – Kees Jul 25 '17 at 14:09
  • Hi @Kees de Wit does the visual studio need to be installed in the server where it needs to run the parser.exe – jarus Jul 25 '17 at 15:23
  • @KeesdeWit guess I am from mars, why will you go out of your way not to use nuget or brower in visual studio app. – EasyE Jul 26 '17 at 02:56
  • I can't explain the logic of the crazy ;) – Kees Jul 26 '17 at 09:36
  • Compiling against one assembly version and running against another will not show the error shown, but _"the located assembly's manifest does not match..."_. So the assembly redirect config doesn't apply to this scenario. – CodeCaster Jul 26 '17 at 13:47