Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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)    
share|improve this question
You are probably experiencing the same problem as in this question and answer. Woudl it be an option to create a .NET library and include the Silverlight source code? – Anders Gustafsson Aug 31 '12 at 14:08
Did you try to turn your Silverlight project into a Portable Class Library? visualstudiogallery.msdn.microsoft.com/… - Another alternative is the Project Linker: visualstudiogallery.msdn.microsoft.com/… – herzmeister Aug 31 '12 at 14:16
@AndersGustafsson: I don't have the source. – user1367401 Aug 31 '12 at 14:45
I have no idea if this will work, but what if you try to use a serializer that is not available in Silverlight? In particular I am thinking of NetDataContractSerializer which according to the documentation should be able to serialize types to which the DataContractAttribute has been applied. – Anders Gustafsson Aug 31 '12 at 15:01
Nah, silly idea! Tried it, and it didn't work either. – Anders Gustafsson Aug 31 '12 at 15:36

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.