I have a SilverLight lib (dll) that implements classes I need to use in a .net project. I follewed the steps described in this answer, but I don't see how to use the proxy library to expose the classes I need. I added a references to the proxy in the .net project. The dll is for silverlight 5 and I'm using .net 4.0.
If I just add the dll as a reference, I can use the SL objects, but I can't serialize them.
Here's the problematic code:
static string SerializeWithDCS(object obj) { if (obj == null) throw new ArgumentNullException("obj"); DataContractSerializer dcs = new DataContractSerializer(obj.GetType()); MemoryStream ms = new MemoryStream(); dcs.WriteObject(ms, obj); return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Position); }
Serialization fails with:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.Serialization, Versio n=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system ca nnot find the file specified. File name: 'System.Runtime.Serialization, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea 7798e' at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int 32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeType Handle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Ty pe[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, Me tadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decora tedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList deriv edAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolea n& isVarArg) at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable) at System.Reflection.CustomAttribute.IsDefined(RuntimeType type, RuntimeType caType, Boolean inheri t) at System.RuntimeType.IsDefined(Type attributeType, Boolean inherit) at System.Runtime.Serialization.CollectionDataContract.IsCollectionOrTryCreate(Type type, Boolean t ryCreate, DataContract& dataContract, Type& itemType, Boolean constructorRequired) at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id , RuntimeTypeHandle typeHandle, Type type) at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidati on(Int32 id, RuntimeTypeHandle typeHandle, Type type)
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog