Question Creating ini/config files

stulish

Well-known member
Joined
Jun 6, 2013
Messages
61
Programming Experience
3-5
Hi guys i have created a program for setting up settings in another program, it then creates an INI file, the code i used to create the ini file is below:

VB.NET:
   Private Function SaveConfig(filename As String, data As Object) As Boolean
        Try
            Dim BF As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
            Dim fstream As New System.IO.FileStream(filename, IO.FileMode.OpenOrCreate)
            BF.Serialize(fstream, data)
            'My.Computer.FileSystem.WriteAllBytes(filename, MS.GetBuffer(), False)
            Return True
        Catch ex As Exception
            Return False
        End Try

    End Function

i sent the filename and structure where the data is held and it saves it to a file, the load ini code is below:

VB.NET:
    Private Function LoadConfig(filename As String, ByRef data As Object) As Boolean
        Try
            Dim BF As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
            Dim fstream As New System.IO.FileStream(filename, IO.FileMode.OpenOrCreate)
            data = BF.Deserialize(fstream)

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

This all works great from the set up program and i can load and save settings, but when i run a second program that is only able to read the ini files there is no data in the returned, after looking at the fstream data it seems that because it cant find the set up program and thus wont load the data, below is a shot of the error:

serialization error.png

Is there a way to save the data with one program and load with another without it caring which program is actually loading the data???

opening up the files in a text editor i see the start of the file is:

???? OSet Up, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null (WindowsApplication1.Form1+

any help is appreciated.

regards

Stu
 
Back
Top