Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Newtonsoft反序列化时找不到Silverlight文件System.Runtime.Serialization_C#_Silverlight_Exception_Filenotfoundexception_Json.net - Fatal编程技术网

C# 从Newtonsoft反序列化时找不到Silverlight文件System.Runtime.Serialization

C# 从Newtonsoft反序列化时找不到Silverlight文件System.Runtime.Serialization,c#,silverlight,exception,filenotfoundexception,json.net,C#,Silverlight,Exception,Filenotfoundexception,Json.net,我在尝试反序列化JSON时遇到异常。据我所知,该文件由用户本地文件系统上的Silverlight运行时提供,不需要包含在XAP文件中 T result = default(T); result = JsonConvert.DeserializeObject<T>(data); 问题是我们为Silverlight 4构建了一个Newtonsoft.Json.dll。它是版本4.0.5.14411,不是为Silverlight 5构建的。Visual Studio生成解决方案时,会将

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

T result = default(T);

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

问题是我们为Silverlight 4构建了一个Newtonsoft.Json.dll。它是版本4.0.5.14411,不是为Silverlight 5构建的。Visual Studio生成解决方案时,会将项目正确映射到正确的System.Runtime.Serialization dll。对利用MSBUILD的TFS中的生成进行排队时不会发生错误


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

检查数据中是否有空值。布尔变量中的Null值将引发奇怪的错误。不感兴趣的是对System.Runtime.Serialization的程序集引用,标记为Copy local=true?我尝试了Copy local=false和Copy local=true,但两次都失败了。我将运行一个测试以确保该值不为null。我可以保证这个值永远不会为null,但是它将是{}来表示一个空数组。
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   
---------------------------
using System;
using System.Runtime.Serialization;

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

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