This project has moved and is read-only. For the latest updates, please go here.

how to access the StreamingContext in Serialization Callbacks

Jan 14, 2010 at 9:40 AM

There is a parameter StreamingContext context in Serialization Callbacks, 

how do I set it before serialization?

Jan 16, 2010 at 6:33 AM
Edited Jan 16, 2010 at 6:33 AM

You don't, Json.NET creates it and uses it to call the callback method. Why do you want to?

Jan 16, 2010 at 1:27 PM

NetDataContractSerializer has a Context property (

so I can use

Serializer.Context = new StreamingContext(StreamingContextStates.Other, myData);

then in the callback, I can do something like

        internal void OnSerializingMethod(StreamingContext context)
		var myData = context.Context as MyData;

		propertyA = myData.Filename;
		if (myData.IsXXX){
			propertyB = 1;
		} else {
			propertyB = 2;



        internal void OnSerializingMethod(StreamingContext context)