Charles M
Charles M

Reputation: 11

Publishing a C# app with NewtonSoft.Json

I've been working on a console app that has some new features, using primarily the NewtonSoft.Json nuget package. For distribution, I've been going into the bin folder -> release and then copy/pasting the executable to distribute to my co-workers. However, since I've used the NewtonSoft.Json package, my coworkers will get the following error on their machine.

System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Jso n, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified. File name: 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30 ad4fe6b2a6aeed'

How do I get past this? How do I get my coworkers to be able to support NewtonSoft.Json on their own machines?

Upvotes: 0

Views: 1377

Answers (2)

Joshua Duxbury
Joshua Duxbury

Reputation: 5260

My issue was some of the configs was missing, this can happen if not checked in during commits in source control.

I use Nuget for packages and therefore a reinstall of the package worked for me. I did upgrade to different versions but this didn't work - it has to be a reinstall.

Update-Package -Id Newtonsoft.Json -reinstall

Upvotes: 0

Like ragerory said in your question comments, these errors will occur with any missing references to external dependencies deployed with the executable.

You can do the following to avoid dependencies loading issues:

  1. Distribute your executable with all the dependencies needed for the execution
  2. Use third party software to "merge" your dependencies with the executable

If you are familiar with NuGet, you could also use Costura.Fody which is a tool I use to embed references as resources at build time. It avoid using an external tool such as ILMerge, I chose it because of the easy integration in projects that already make use of NuGet packages.

Upvotes: 0

Related Questions