Silverlight serializers require that serialization callbacks are accessible to them, ergo they need to be public. However, since the object model generated by the Service Object Model Producer is the same whether the smart client is a standard .NET application or a Silverlight application, by default, those callbacks aren't which will cause a compilation error.
Two solutions are available:
- Set the publicSerializationCallbacks attribute, in the Service Object Model Producer namespace, to true on the project element of your model,
- Expose internal members of the SLOM to the used serialization assembly.
Both solutions are perfectly valid and only one of the two needs to be implemented, so use the one that suits you best depending on your needs.
Method One: Setting the publicSerializationCallbacks attribute
| Generating Public Serialization Callbacks | Copy Code |
|---|---|
<cf:project xmlns:cf="http://www.softfluent.com/codefluent/2005/1" xmlns:cfsm="http://www.softfluent.com/codefluent/producers.servicemodel/2007/1" defaultNamespace="Sample" cfsm:publicSerializationCallbacks="true"> (...) </cf:project> |
|
This will indicate the Service Object Model Producer to generate all serialization callbacks as public, such as:
| Public Serialization Callback Example | Copy Code |
|---|---|
[System.Runtime.Serialization.OnDeserializedAttribute()]
public void OnEntityDeserialized(System.Runtime.Serialization.StreamingContext context)
{
this.IsDeserializing = false;
}
|
|
Method Two: Exposing internal members
| Assembly.cs | Copy Code |
|---|---|
[assembly: InternalsVisibleTo("System.Runtime.Serialization")]
|
|
![]() |
Note: If using another serializer such as the JSON serializer, replace the assembly between quotes by the assembly containing the used serializer. |
