Silverlight文件找不到System.Runtime.Serialization从Newtonsoft的反序列化 [英] Silverlight File Not Found System.Runtime.Serialization on Deserialization from Newtonsoft

查看:206
本文介绍了Silverlight文件找不到System.Runtime.Serialization从Newtonsoft的反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试反序列化JSON时,我遇到异常。我的理解是,该文件是由用户本地文件系统上的Silverlight Runtime提供的,不需要包含在XAP文件中。

  T result = default(T); 

result = JsonConvert.DeserializeObject< T>(data);任何想法,为什么我得到这个错误?



$ b $ / code $ $ b


 遇到异常:System.IO.FileNotFoundException:无法加载文件或程序集System.Runtime.Serialization,Version = 4.0 .0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089或其依赖关系之一。该系统找不到指定的文件。 

文件名:System.Runtime.Serialization,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'

在System.ModuleHandle.ResolveType(RuntimeModule模块, int32 typeToken,IntPtr * typeInstArgs,Int32 typeInstCount,IntPtr * methodInstArgs,Int32 methodInstCount,ObjectHandleOnStack类型)

在System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule模块,Int32 typeToken,RuntimeTypeHandle [] typeInstantiationContext,RuntimeTypeHandle [] methodInstantiationContext )

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

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

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

在系统.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType类型,RuntimeType caType,Boolean inherit)

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

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

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

在Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute [T](类型类型)

在Newtonsoft.Json.Serialization.JsonTypeReflector.GetAttribute [T](ICustomAttributeProvider attributeProvider)$ b Newtonsoft.Json.Utilities.ThreadSafeStore`2.AddValue(TKey key)
$ b在Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(TKey key)



在Newtonsoft.Json.Serialization.CachedAttributeGetter`1.GetAttribute(ICustomAttributeProvider类型)

在Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(类型objectType)

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

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

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

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

在Newtonsoft.Json.Serialization.JsonSerializerInternalRead呃。c__DisplayClass1。< CreateAndPopulateList> b__0(IList l,Boolean isTemporaryListReference)

在Newtonsoft.Json.Utilities.CollectionUtils.CreateAndPopulateList(Type listType,Action`2 populateList)$ b $在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader reader,String reference,JsonArrayContract contract)中的
$ b在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader,Type objectType, JsonContract合同,JsonProperty成员,Object existingValue,String引用)

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

在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader,Type objectType,JsonContract合同)

在Newtonsoft.Json.Serialization.Jso nSerializerInternalReader.Deserialize(JsonReader reader,Type objectType)

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

在Newtonsoft.Json.JsonConvert.DeserializeObject( Newtonsoft.Json.JsonConvert.DeserializeObject [T](String value,JsonSerializerSettings设置)

在Newtonsoft.Json.JsonConvert中。 DeserializeObject [T](String value)

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

编辑:



以下是使用系统的T

 的示例。 
使用System.Runtime.Serialization;

命名空间MyNs
{
[DataContract]
public class ClientQuery
{
[DataMember]
public int ClientId {get ;组; }

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


解决方案

问题是我们为Silverlight 4构建了一个Newtonsoft.Json.dll。它是4.0.5.14411版本,它不是针对Silverlight 5构建的。当Visual Studio构建解决方案时,它会将项目正确映射到正确的System.Runtime。序列化dll排队使用MSBUILD的TFS中的版本不会。



我升级到最新版本,并解决了这个问题。


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; }
    }
}

解决方案

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.

这篇关于Silverlight文件找不到System.Runtime.Serialization从Newtonsoft的反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆