0

i have a SMS class which uses Newtonsoft.Json methods to resolve json. this class is called by a method (RunSmsService) which is executing every 30 seconds and is based on expiring cache system. RunSmsService method is first initiated by Application_Start (Global.asax.cs)

almost each time the SMS class is called, the below exceptions throw and after a while the app pool crashes.

Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: Newtonsoft.Json.JsonReaderException
Stack:
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__5(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

and

An unhandled exception occurred and the process was terminated.

Application ID: DefaultDomain

Process ID: 9232

Exception: System.Runtime.Serialization.SerializationException

Message: Unable to find assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.

StackTrace:    at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.AppDomain.Deserialize(Byte[] blob)
   at System.AppDomain.UnmarshalObject(Byte[] blob)

i looked up and searched for posts related to "Unable to find assembly 'Newtonsoft.Json,... " error, but none helped!

anyone knows a solution for this?

Mahyar
  • 681
  • 6
  • 12
  • 2
    Has the Newtonsoft.Json.dll been copied to the output directory (or deployed to the server) alongside the SMS class? – Paolo Apr 08 '15 at 12:48
  • @Paolo yes, it has been copied to bin folder and is referenced in web.config and package.config – Mahyar Apr 08 '15 at 12:55
  • Check the version. This can happen when another library you use also references the dll and copies in a different version. If that has happened you'll need to fix it in your web.config with a runtime > assembly binding > dependantAssembly element. See http://stackoverflow.com/questions/17776090/newtonsoft-json-assembly-conflict for an example. – Andy Nichols Apr 08 '15 at 14:10
  • i think i found a solution :-) i will post an answer when i was sure that no same exception is thrown again Thanks – Mahyar Apr 08 '15 at 14:10

1 Answers1

0

I found what was wrong
in my SMS class, i'm reading a url using HttpClient which should return a json. in some cases it returns an empty string and because i'm parsing the string using JObject.Parse , exception will be thrown.

when an exception in JSON parsing (in Newtonsoft.Json) is thrown, almost it results in this error: Unable to find assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

it was my mistake not to surround that section of code in try/catch
thanks

Mahyar
  • 681
  • 6
  • 12
  • 2
    You're still just avoiding the problem. You need to be able to find that assembly. – mason Apr 08 '15 at 14:29
  • @mason no, the assembly is right there in the \bin folder of website i read somewhere else this error is a common exception for json parsing exceptions – Mahyar Apr 08 '15 at 14:31