[Mono-dev] Custom surrogates and serialization

Lluis Sanchez lluis at ximian.com
Wed Sep 21 06:40:30 EDT 2005


El dv 02 de 09 del 2005 a les 11:49 -0400, en/na Chris Micacchi va
escriure:

> I'm now working on some problems with Xml serialization, and this is 
> where the bulk of the problems I'm getting have been.  The first is that 
> our software uses a custom serializer surrogate for 
> System.Net.IPAddress, in order to handle differences between .Net 1.0 
> and 1.1.  On Mono, our custom serializer doesn't work; it gets the error 
> "The attempted operation is not supported for the type of object 
> referenced" instead.  My surrogate code is:
>      public object SetObjectData(
>          System.Object obj,
>          System.Runtime.Serialization.SerializationInfo info,
>          System.Runtime.Serialization.StreamingContext context,
>          System.Runtime.Serialization.ISurrogateSelector selector)
>          {
>              System.String ipStr = info.GetString( "address" );
>              System.Net.IPAddress newIP
>                  = System.Net.IPAddress.Parse( ipStr );
>              System.Net.IPAddress ipAddress = (System.Net.IPAddress)obj;
> 
>              // This line throws the exception
>              ipAddress.Address = newIP.Address;
>              return obj;
>          }
> 
> The problem seems to be that when the deserializer creates the new 
> IPAddress object the AddressFamily field ends up uninitialized, and the 
> Address property set fails.
> 
> Unfortunately the deserializer also mimics the .Net 1.0 behaviour where 
> the return value of SetObjectData is ignored, so I can't just create a 
> new IPAddress and return it instead (in .Net 1.1, this bug is supposedly 
> fixed).

Can you please file a bug report for this issue, including a
self-contained test application I can use to reproduce it? thanks.

Lluis.




More information about the Mono-devel-list mailing list