0

I am using Newtonsoft.Json in my Windows Service project.

My Newtonsoft.Json version is 6.0.0.0 and I have it referenced in my Project's References.

Installation and compilation go through just fine. But when I start my service from Services it throws an exception:

Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

I also searched the web and added the following in my app.config file:

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

But still getting the same error.

What am I doing wrong?

FireFalcon
  • 831
  • 11
  • 23

2 Answers2

2

If you are planning to convert array into Json, no need to use outsourced dll's. VS 2010 has JavaScriptSerializer to approach this task.

The example is as follows:

using System.Web.Script.Serialization;

JavaScriptSerializer js = new JavaScriptSerializer();
var json = js.Serialize(strYourArrayString);
firefalcon
  • 500
  • 2
  • 8
  • 21
0

Probably the problem is related to startup directory (is 'Newtonsoft.Json' in GAC?). You can try to work on services to set the directory but I gave up.

Actually I set always copy local for non Microsoft referenced assemblies and I use a source code similar to this How to add folder to assembly search path at runtime in .NET?

Community
  • 1
  • 1
bubi
  • 6,414
  • 3
  • 28
  • 45