Csla.Validation.BrokenRule cannot be serialized because it does not have a parameterless constructor.

Csla.Validation.BrokenRule cannot be serialized because it does not have a parameterless constructor.

Old forum URL: forums.lhotka.net/forums/t/10165.aspx


kalpesh posted on Monday, March 14, 2011

I have written a Web service in .Net 2008, with following Web method -

    <WebMethod()> _

   Public Function GetCurrency(ByVal ID As Guid) As Currency

        Dim mCurrency As Currency = Currency.GetCurrency(ID)

        Return mCurrency

    End Function

WHERE 'Currency' is CSLA.net object. WHILE running web service its giving subjected error.

PLEASE guide me as I am new to this.

 

RockfordLhotka replied on Monday, March 14, 2011

This is a frequently asked question. Frequent enough that it is covered in the FAQ:

http://www.lhotka.net/cslanet/faq/XmlServicesFaq.ashx

It is also the subject of Chapter 21 in the Expert 2008 Business Objects book.

In short, you can't use the XmlSerializer, DataContractSerializer, JsonSerializer, or the other more limited serializers to directly convert a CSLA object into and out of a data format.

And you shouldn't want to do this anyway. It would be an architectural disaster to tightly couple your internal object design to an external interface. Especially a service interface, because they are really hard to version in any case.

kalpesh replied on Monday, March 14, 2011

Thanks.

Can you please explain how should I work arround in this situation.

RockfordLhotka replied on Tuesday, March 15, 2011

As I said, Chapter 21 explains in detail. In summary:

  1. Define your external service interface - this is often done using an XSD or DataContract class - in any case you'll end up with proxy types representing the service interface
  2. Implement your service to create instances of the proxy types, and to load them with data from your business objects - you can often use Csla.Data.DataMapper to simplify this code
  3. Return the proxy type as the result of your service - it will serialize fine because it is a service proxy type

There's also a lot of information (mostly architecture related) on my blog in the Service Oriented category:

http://www.lhotka.net/weblog/CategoryView,category,Service-Oriented.aspx

Copyright (c) Marimer LLC