Sorry, I forgot to include the exception:

System.Runtime.Serialization.SerializationException : Type
'Castle.Proxies.SimpleViewModelProxy' with data contract name
'SimpleViewModelProxy:http://schemas.datacontract.org/2004/07/
Castle.Proxies' is not expected. Consider using a DataContractResolver
or add any types not known statically to the list of known types - for
example, by using the KnownTypeAttribute attribute or by adding them
to the list of known types passed to DataContractSerializer.

On Aug 30, 1:46 pm, JakeS <[email protected]> wrote:
> I'm running into an issue using
> System.Runtime.Serialization.Json.DataContractJsonSerializer to
> serialize a List<T> of proxied objects.  It works fine with a single
> proxied object, but the List makes it blow up.  Something like this:
>
> [DataContract]
> public class SimpleViewModel
> {
>     [DataMember]
>     public virtual int ID { get; set; }
>
> }
>
> [Test]
> public void TestSerializeArray()
> {
>     // Generates a proxy of type SimpleViewModelProxy that inherits
> SimpleViewModel
>     var proxyModel = (new
> ProxyGenerator()).CreateClassProxy<SimpleViewModel>();
>     proxyModel.ID = 1;
>
>     //Put it into List<T> (it can handle a single item without issue!)
>     var list = new List<SimpleViewModel> { proxyModel };
>
>     var serializer = new
> System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(List<Si 
> mpleViewModel>));
>     using (var stringWriter = new MemoryStream())
>     {
>         serializer.WriteObject(stringWriter, list); //BOOM!
>     }
>
> }
>
> I'm able to serialize either a single "SimpleViewModelProxy" object,
> or a List<SimpleViewModel>, but not a List<SimpleViewModelProxy>.  Has
> anyone had any experience getting this to work?  Can they provide some
> pointers on what I'm doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to