Remoting, the StreamingContext and BinaryFormatter Sinks
Well,
These next few posts, I'm playing catch up, seeing that I just reinstalled the blog! So bare with me, some of this may be older stuff.
It looks like .NET Remoting has a little problem. If you're trying to do some complex things with serialization (like me) and are using the StreamingContextStates as part of the contract of your ISerializable objects, then you'll notice theres a little problem when you try to apply this to remoting using the BinaryFormatterClientSink or BinaryFormatterServerSink.
Inside the sink, it seems that someone forgot to set the StreamingContextStates to StreamingContextStates.Remoting. By doing this, it effectively makes checking StreamingContext.State in an ISerializable implementation useless.
The solution? Well, if you're like me, and still want to use StreamingContextStates, you'll download the Mono code for this part of remoting and change the value. Works great (that is until they release a patch). You can download the patched code from me at the bottom of this post.
Once you have the Mono code (see my attachments if you want to get the code already patched), add this to your app.config:
<
system.runtime.remoting>
<
application>
<
channels>
<
channel ref="http" name="SecureChannel">
<
clientProviders>
<
formatter ref="patchedBinary" />
</
clientProviders>
<
serverProviders>
<
formatter ref="patchedBinary" />
</
serverProviders>
</
channel>
</
channels>
</
application>
<
channelSinkProviders>
<
clientProviders>
<
provider id="patchedBinary" type="Decav.Remoting.BinaryClientFormatterSinkProvider, MyAssembly"/>
</
clientProviders>
<
serverProviders>
<
provider id="patchedBinary" type="Decav.Remoting.BinaryServerFormatterSinkProvider, MyAssembly"/>
</
serverProviders>
</
channelSinkProviders>
</
system.runtime.remoting>
That should do the trick! Use the patched sink and you'll get the correct StreamingContextStates for serialization.