0

i have a serializable class

<Serializable()> Public Class SACCVar

Private _ConsigneCompression As Integer

Public Event VariableChanged(ByVal Val As Object, ByVal Old_Val As Object, desc As String)

Public Property ConsigneCompression As Integer

    Get
        Return _ConsigneCompression
    End Get
    Set(value As Integer)
        Tmp_Val = _ConsigneCompression
        _ConsigneCompression = value
        RaiseEvent VariableChanged(_ConsigneCompression, Tmp_Val, "ConsigneCompression")
    End Set
End Property End Class

In a module i declare my variable as class and implement my raise function

     Public WithEvents MesuresVal As New MesuresVar
Public Sub SaccVarChanged(ByVal Val, ByVal Old_Value, DictKeyDesc) Handles SaccData.VariableChanged
        For Each item As CtrlItem In SaccData.DicOfControl(DictKeyDesc)

        Dim pinstance As PropertyInfo = item.Ctrl.GetType.GetProperty(item.prop)
        pinstance.SetValue(item.Ctrl, Val)
    Next End Sub

In the code when i do

SaccData.ConsigneCompression = 1234

it call SaccVarChanged

but when i call my subroutines that Deserialize my class it pass on the RaiseEvent VariableChanged part of the code in my "public property". But it didn't raise the SaccVarChanged sub.

Is there anything i can do for that? Thank you

EDIT : here is my serialize /deserialize code :

  Dim fichier As String
    fichier = Fichier_SACC
    ' Déclaration
    Dim XSSACC As New XmlSerializer(SaccData.GetType)
    Dim streamSACC As FileStream
    If Not File.Exists(fichier) Then
        'Exit Sub
        'TODO gestion erreur
    Else
        streamSACC = New FileStream(fichier, FileMode.Open)
        Try
            SaccData = CType(XSSACC.Deserialize(streamSACC), SACCVar)


        Catch ex As Exception
            ' Propagrer l'exception
            Throw ex
        Finally
            ' En cas d'erreur, n'oublier pas de fermer le flux en lecture si ce dernier est toujours ouvert
            streamSACC.Close()
        End Try
    End If




            Dim StreamSACC As New StreamWriter(Fichier_SACC)
    Dim serialiseSACC As New XmlSerializer(SaccData.GetType)
    Try
        serialiseSACC.Serialize(StreamSACC, SaccData)
    Catch ex As Exception
        Throw ex
    Finally
        StreamSACC.Close()
    End Try
got_fr
  • 39
  • 8
  • can you show your Serialize and Deserialize code. They are central but we dont know how/what you did. Also NET has a standardized way of implementing events when a property changes: `INotifyPropertyChanged` a handful of other NET things look for this to reflect any changes – Ňɏssa Pøngjǣrdenlarp Nov 27 '15 at 19:21
  • ok i have just tested the INotifyPropertyChanged i got the same result. If i update the data before deserialize function it works, after that it works but during the deserialization i pass on the change property sub but the event isn't raised! – got_fr Nov 30 '15 at 09:15

1 Answers1

0

Ok i finally get it working...

thanks to here : Events not working with after Deserialization

i found that Deserialization remove the handler of the event. It seems that deserialization create a new instance of my object. The solution give in the link is something like :

        <OnDeserialized()>
Private Sub OnDeserializedMethod(ByVal Context As StreamingContext)

        AddHandler Child.Changed AddressOf Me.Child_Changed 
    End Sub

But that didn't work for me as i am using xmlserialiser wich seems not implement with call back (a question of compatibility with framework 1.1 i read...)

Instead i am using a flag that i test in my "new" method. everything is working as i expect.

Thanks once again @plutonix..

Community
  • 1
  • 1
got_fr
  • 39
  • 8