0

Meet a little problem here which i do not know where the wrong the code

    Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
    Dim str As New MemoryStream
    Dim Serializetemplate As New DPFP.Template
    Serializetemplate.Serialize(str)
    Dim serializedTemplate As Byte() = str.ToArray()

    'save to database
    opencon1()
    Dim cmd As MySql.Data.MySqlClient.MySqlCommand
    cmd = New MySql.Data.MySqlClient.MySqlCommand
    cmd.Parameters.AddWithValue("?imagedata", serializedTemplate)
    cmd.Parameters.AddWithValue("?userid", txtEmpid.Text)
    cmd.CommandText = "UPDATE master SET fp1=?imagedata WHERE userid=?userid"
    cmd.CommandType = CommandType.Text
    cmd.Connection = con1
    cmd.ExecuteNonQuery()
End Sub

I get an error at Serializetemplate.Serialize(str) with the error message Bad Serialization

Anyone ever meet this error and solve it?

Lance U. Matthews
  • 15,725
  • 6
  • 48
  • 68
Joseph Goh
  • 689
  • 5
  • 16
  • 38

1 Answers1

1

Joseph I'm not very good with VB but as far as I can see you're declaring a new DPFP.Template and then serializing it into your memory stream. Why are you doing this?

Given that you're enrolling or verifying the SDK'll give you the template on the event handler

private void Enrolled(object Control, int Finger, DPFP.Template Template, ref DPFP.Gui.EventHandlerStatus Status)
{
   if (Status == DPFP.Gui.EventHandlerStatus.Success)
   {
      // Here you can use the template as  Template.Bytes
   }
}

The template is already serialized as byte[].

I think that given that you just create the template (blank) then when you try to serialize it throws the exception.

Erre Efe
  • 15,387
  • 10
  • 45
  • 77
  • if i don't declaring a new DPFP.Template i will get an error "Object reference not set to an instance of an object." This is what i don't understand I am declaring this Private Template As DPFP.Template at the top of the code – Joseph Goh Apr 26 '12 at 02:02
  • Sure, but thats the error precisely @JosephGoh, the recently created template can't be serialized because it's empty. Why are you creating this new Template anyway? That template must come from the biometric sensor or must be loaded from repo once stored. I don't see why are you instantiating a new one. If you need an empty object just assign the byte[] where you store the template as null. – Erre Efe Apr 26 '12 at 02:15