1

am create a desktop application using wpf. am installd newtonsoft.json(using package manager) for json parsing. after am successfully build and run my application.

then iam copy the appliction.exe from project source > bin > debug to my Destop. then am attempt to run exe from Desktop, but i got an error message

like this

could not load file or assembly 'newtonsoft.json' ..... system cannot find the path

what is the issue? any missing

Abdul Manaf
  • 4,933
  • 8
  • 51
  • 95
  • possible duplicate http://stackoverflow.com/questions/22685530/could-not-load-file-or-assembly-newtonsoft-json-or-one-of-its-dependencies-ma – bot Nov 11 '15 at 10:12
  • It's not as simple as pulling an exe from the bin folder and running it from elsewhere. It's referencing a bunch of dlls and other files it depends on, `newtonsoft.json` being one of them, in your case. –  Nov 11 '15 at 10:15
  • Did you copy only your .exe or also all its support files (newtonsoft.json.dll and maybe others)? – Adriano Repetti Nov 11 '15 at 10:15
  • Possible duplicate of [Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'](http://stackoverflow.com/questions/22507189/could-not-load-file-or-assembly-newtonsoft-json-version-4-5-0-0-culture-neutr) – MusicLovingIndianGirl Nov 11 '15 at 10:15
  • am running from bin > debug folder, its working. but from desktop, it produce error message – Abdul Manaf Nov 11 '15 at 10:26
  • i need to run this , any help – Abdul Manaf Nov 11 '15 at 10:27
  • As others have already mentioned, you should copy the *dlls* as well, not only the exe. In any case, executable applications *should never-ever **ever** be placed on the desktop*. Write a proper installer or use ClickOnce to put them in "Program Files". – Panagiotis Kanavos Nov 11 '15 at 10:59
  • What does this have to do with WPF and Visual Studio 2015 lol – Mark Homer Nov 11 '15 at 11:07

1 Answers1

1

The exe needs to be able to link to the dll when you run it. That's why it works in your debug folder (the newtonsoft dll is there if you look), while it's presumably not in your desktop.

You can either:

1) Make sure the dll is included with the exe (copy it to your desktop, for example). If you distribute the exe in a zip file, just include the dll. If you use an installer, make sure it also installs the dll to the same folder.

OR

2) ILMerge the DLL directly into your exe - this means the exe contains the entire DLL and will always be able to find it. There are NuGet packages that can do this for you autonatically. Try adding "MSBuild.ILMerge.Task" via NuGet, and then build your project again.

(There are other solutions but they're generally terrible, like PATH, so I'm not going to explain how they work).

Personally, I'd usually recommend the former - just include the DLL. Look inside folders where you have software on your PC (e.g. most folders in Program Files) - you'll see that's how it's usually done, with DLLs installed as separate files. ILMerge can get messy if you don't know what you're doing and you start doing weird things with your DLLs.

Alex Hardwicke
  • 529
  • 6
  • 16