Silverlight File Not Found System.Runtime.Serialization on Deserialization from Newtonsoft

谁都会走 提交于 2019-12-11 05:09:38

问题


I am getting an exception when trying to deserialize JSON. It is my understanding that this file is provided by the Silverlight Runtime on the users local file system and should not need to be included in the the XAP files.

T result = default(T);

result = JsonConvert.DeserializeObject<T>(data);

Any ideas as to why I am getting this error?


Exception encountered: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

File name: 'System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)

   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)

   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)

   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)

   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)

   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)

   at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)

   at Newtonsoft.Json.Utilities.ReflectionUtils.GetAttributes[T](ICustomAttributeProvider attributeProvider, Boolean inherit)

   at Newtonsoft.Json.Utilities.ReflectionUtils.GetAttribute[T](ICustomAttributeProvider attributeProvider, Boolean inherit)

   at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[T](Type type)

   at Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute[T](ICustomAttributeProvider attributeProvider)

   at Newtonsoft.Json.Utilities.ThreadSafeStore`2.AddValue(TKey key)

   at Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(TKey key)

   at Newtonsoft.Json.Serialization.CachedAttributeGetter`1.GetAttribute(ICustomAttributeProvider type)

   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)

   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, Type t, JsonConverter propertyConverter)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForTypeArrayHack(JsonReader reader, Type t)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IWrappedCollection wrappedList, JsonReader reader, String reference, JsonArrayContract contract)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.<>c__DisplayClass1.<CreateAndPopulateList>b__0(IList l, Boolean isTemporaryListReference)

   at Newtonsoft.Json.Utilities.CollectionUtils.CreateAndPopulateList(Type listType, Action`2 populateList)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader reader, String reference, JsonArrayContract contract)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String reference)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract)

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType)

   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)

   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)

   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)

   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)

   at Sungard.Helios.UI.Common.Infrastructure.ControllerUtility.<>c__DisplayClass1d`1.<GetResponse>b__16(IAsyncResult r)
---------------------------
OK   
---------------------------

EDIT:

Here's a sample of T

using System;
using System.Runtime.Serialization;

namespace MyNs
{
    [DataContract]
    public class ClientQuery
    {
        [DataMember]
        public int ClientId { get; set; }

        [DataMember]
        public string ClientName { get; set; }
    }
}

回答1:


The issue is we had a Newtonsoft.Json.dll built for Silverlight 4. It was version 4.0.5.14411 which wasn't built for Silverlight 5. When Visual Studio builds the solution, it correctly maps the project to the correct System.Runtime.Serialization dll. Queueing a build in TFS that utilizes MSBUILD does not.

I upgraded to the newest version and that fixed the issue.



来源:https://stackoverflow.com/questions/10238187/silverlight-file-not-found-system-runtime-serialization-on-deserialization-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!