views:

109

answers:

1

In my ASP.NET website all calls into the data layer return entities as interfaces and the website does not need to know what the concrete type is. This works fine, but I have run into a problem when trying to store one of those types into the user Profile. My interface implements ISerializable, like the following:

public interface IInsured : IPerson, IEntity, ISerializable

and the concrete type in the datalayer does implement ISerializable. My Profile property in web.config is:

<add name="ActiveInsured" type="FacadeInterfaces.IInsured" serializeAs="Binary" defaultValue="[null]"/>

It compiles just fine, but I get a runtime error on Profile.Save() saying that the interface cannot be serialized. I have also tried it with serializeAs="Xml". I thought that if my interface implemented ISerializable it would work.

Anybody had this problem before or know of a workaround?

A: 

In the context of a profile property, you must specify the type to be serialized explicitly.

You cannot instantiate an interface, thus ASP.net cannot instantiate an interface and the exception you mention occurs.

Sky Sanders