I have several quesions about reading/writing structures from/to files.
In a scenario when I open a data file having its own header and variable data fields I create a structure that represents a header consisting of 9 bytes:

Code:
Public Structure HeaderInfo
     Public DataField1 As Integer
     Public DataField2 As Byte
     Public DateField3 As Integer
End Structure
I'm using this code for the time being:

vb.net Code:
  1. Public Function ReadHeader(ByVal FileName As String) As HeaderInfo
  2.     Dim ReturnInfo As HeaderInfo
  3.     Try
  4.         Using br As New IO.BinaryReader(New IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read))
  5.             With ReturnInfo
  6.                 .DataField1 = br.ReadInt32()
  7.                 .DataField2 = br.ReadByte()
  8.                 .DataField3 = br.ReadInt32()
  9.             End With
  10.             br.Close()
  11.         End Using
  12.         Return ReturnInfo
  13.     Catch ex As Exception
  14.         Return Nothing
  15.     End Try
  16. End Function

The first question is - can I fill the structure directly somehow? Some structures are very long and filling them this way will be tedious. For example, if I know the length of the structure I could read the needed number of bytes in a byte array and somehow marshal these bytes into the structure.

My second question:
I can use Marshal.PtrToStructure, but then I would need to get an IntPtr of my byte array. Is it the only option?

And the last question - I use <Serializable()> attribute for my structure. Am I doing it right? Should there be some other attributes?