我有一個SMS類,它使用Newtonsoft.Json方法來解析json。 該類由一個方法(RunSmsService)調用,該方法每30秒執行一次並基於到期的緩存系統。 RunSmsService方法首先由Application_Start(Global.asax.cs)啓動Newtonsoft.Json.JsonReaderException,無法找到程序集'Newtonsoft.Json ...'
幾乎每次調用SMS類時,下面的異常都會拋出,並在應用程序池崩潰後一段時間。
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()
和
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)
我擡頭一看,搜索相關的帖子 「無法找到程序集「Newtonsoft.Json,...」 錯誤,但沒有幫助!
任何人都知道這個解決方案?
將Newtonsoft.Json.dll與SMS類一起復制到輸出目錄(或部署到服務器)? – Paolo
@Paolo是的,它已被複制到bin文件夾並在web.config和package.config中引用 – Mahyar
檢查版本。當您使用的另一個庫也引用dll和不同版本的副本時,可能會發生這種情況。如果發生這種情況,您需要使用運行時>程序集綁定> dependantAssembly元素將其修復到web.config中。有關示例,請參閱http://stackoverflow.com/questions/17776090/newtonsoft-json-assembly-conflict。 –