Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing serialization of properties in VB.NET

I have a VB.NET class which I'm serializing via XML in an asmx file. I've added attributes to the datamember I want to ignore in serialization, but it's still returned. I also have the <DataContract()> attribute on my class and the DataMember attribute on all properties which should be serialized. My property declaration is:

    <ScriptIgnore()> _
    <IgnoreDataMember()> _
    Public Property Address() As SomeObject
like image 749
Echilon Avatar asked Jul 19 '11 11:07

Echilon


2 Answers

By adding an attribute to the backing field and converting it from an auto-property, I eventually got the proprty to stop serializing:

<NonSerialized()> _
Private _address As SomeObject = Nothing
<ScriptIgnore()> _
<IgnoreDataMember()> _
<Xmlignore()>
Public Property address() As SomeObject
    Get
        Return _address
    End Get
    Set(ByVal value As SomeObject)
        _address = value
    End Set
End Property
like image 80
Echilon Avatar answered Nov 01 '22 10:11

Echilon


Have you tried the NonSerialized attribute:

<NonSerialized()> _
Public Property Address() As SomeObject

http://msdn.microsoft.com/en-us/library/system.nonserializedattribute.aspx

like image 3
Jay Avatar answered Nov 01 '22 09:11

Jay