O
Obinna
'
--------------------------------------------------------------------------
This is a follow-up to a question I asked "What's with the Assembly
Stuff?"
All the people that gave me a responce asked me to produce the code and
the error message
and here it is:
' VB.NET code to save the ArrayList object to file
' it could have been in any other dot NET language.
'
--------------------------------------------------------------------------
Private xlist As New ArrayList()
<Serializable()> Structure Human
Dim firstname As String
Dim lastname As String
End Structure
For i = 0 to <any Number>
Dim p As Human
p.firstname = "Obinna"
p.lastname = "Chikwendu"
xlist.Add(p)
Next
Dim fName As String = "C:\test.bin"
Dim fs As FileStream
Dim bf As New BinaryFormatter()
fs = File.Create(fName)
fs.Seek(0, SeekOrigin.End)
bf.Serialize(fs, xlist)
fs.Close()
/****************************************************************
C# code to retrieve the value stored in the file
Note: it works if both are compiled in the same assembly
but I intend to load the ArrayList from a different assembly
****************************************************************/
String fName = "C:\test.bin";
FileStream fs;
BinaryFormatter bf = new BinaryFormatter();
try{
fs = File.OpenRead(fName);
xlist = CType(bf.Deserialize(fs), ArrayList);
// retrieving the data from file ...
Human p;
for (i = 0; i < xlist.Count - 1; i++){
p = xlist.Item(i);
str = p.firstname & " " & p.lastname;
}
}
catch (Exception exp){
MessageBox.Show(exp.Message);
}
finally{
fs.Close();
}
/*******************************
When run the message box displays:
"File or assembly name <Project name>, or one of its dependencies,
was not found."
What's with the Assembly Stuff?
***********************************/
--------------------------------------------------------------------------
This is a follow-up to a question I asked "What's with the Assembly
Stuff?"
All the people that gave me a responce asked me to produce the code and
the error message
and here it is:
' VB.NET code to save the ArrayList object to file
' it could have been in any other dot NET language.
'
--------------------------------------------------------------------------
Private xlist As New ArrayList()
<Serializable()> Structure Human
Dim firstname As String
Dim lastname As String
End Structure
For i = 0 to <any Number>
Dim p As Human
p.firstname = "Obinna"
p.lastname = "Chikwendu"
xlist.Add(p)
Next
Dim fName As String = "C:\test.bin"
Dim fs As FileStream
Dim bf As New BinaryFormatter()
fs = File.Create(fName)
fs.Seek(0, SeekOrigin.End)
bf.Serialize(fs, xlist)
fs.Close()
/****************************************************************
C# code to retrieve the value stored in the file
Note: it works if both are compiled in the same assembly
but I intend to load the ArrayList from a different assembly
****************************************************************/
String fName = "C:\test.bin";
FileStream fs;
BinaryFormatter bf = new BinaryFormatter();
try{
fs = File.OpenRead(fName);
xlist = CType(bf.Deserialize(fs), ArrayList);
// retrieving the data from file ...
Human p;
for (i = 0; i < xlist.Count - 1; i++){
p = xlist.Item(i);
str = p.firstname & " " & p.lastname;
}
}
catch (Exception exp){
MessageBox.Show(exp.Message);
}
finally{
fs.Close();
}
/*******************************
When run the message box displays:
"File or assembly name <Project name>, or one of its dependencies,
was not found."
What's with the Assembly Stuff?
***********************************/