NonSerialized

Posts   
 
    
MattE avatar
MattE
User
Posts: 77
Joined: 11-Sep-2007
# Posted on: 22-Nov-2010 11:46:32   

How do I configure a field to be ignored for binary serialization?

i.e. Add [NonSerialized] to the field?

thanks,

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 22-Nov-2010 16:16:32   

All fields are always serialized, this isn't configurable. Fast serialization does an excellent job to minimize data size/speed.

MattE avatar
MattE
User
Posts: 77
Joined: 11-Sep-2007
# Posted on: 23-Nov-2010 13:55:00   

Hi thanks,

Unfortunately I have the following error happening on serialization:

EventDetailSystem.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Runtime.Serialization.SerializationException: Type 'Microsoft.SqlServer.Types.GeoData' in Assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' is not marked as serializable. at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, 

when attempting to serialize an entity with a SqlGeography field.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 23-Nov-2010 21:07:23   

Hmm, dont remember seeing anyone trying to serialise the Geo fields before. We'll investigate...

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 24-Nov-2010 09:49:44   

Very strange, considering that the types have the [Serializable] attribute, both the GeoData type (referenced by SqlGeo* types) as well as the SqlGeo* types. If you are using Fast Serialization, you should try the TypeSurrogates feature of the fast serializer. The SerializationWriter and SerializationReader class have both a static property called 'TypeSurrogates'. This property returns a list of IFastSerializationTypeSurrogate instances. You should implement that interface on a class and implement the serialize/deserialize methods plus the SupportsType method which should return true for the SqlGeo* type you're using and then add an instance of this class to the TypeSurrogates property of both SerializationWriter and SerializationReader at application startup.

In the implementation of that interface, use the string serialization capabilities of the SqlGeo* types to serialize/deserialize the types. as binary serialization fails for some reason (as it otherwise wouldn't throw this exception).

If you're not using fast serialization, please switch on fast serialization, if you're using adapter. If you're using selfservicing, there's little we can do, I'm afraid, other than that you implement a surrogate for the type yourself for the binary formatter (see MSDN, but documentation is scarce), which isn't as easy as for fastserialization built into the framework.

Frans Bouma | Lead developer LLBLGen Pro
MattE avatar
MattE
User
Posts: 77
Joined: 11-Sep-2007
# Posted on: 24-Nov-2010 09:55:34   

Thanks.

For obvious reasons, I am trying to steer clear of implementing my own serialization, but will go the surrogate method if necessary.

What is stranger is that It happens on some machines, not on others.

THe only common factor is that it fails on machines which don't have SQL Server 2008 R2 installed (e.g. our live web servers)

I wonder If there are different versions of Microsoft.SQLServer.Types.dll floating around ..

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 24-Nov-2010 10:01:55   

I think it's more about service packs I think. The dll I checked is from the sqlserver 2008 dev version, not R2, and it had the Serializable attribute on the types, but I didn't try it in practice, so it might fail elsewhere.

If you check the dlls on systems which fail with reflector, do they have the Serializable attribute?

Frans Bouma | Lead developer LLBLGen Pro
MattE avatar
MattE
User
Posts: 77
Joined: 11-Sep-2007
# Posted on: 24-Nov-2010 10:14:05   

That was it! A rogue binary..

Thanks Frans.