ArrayList

  • Thread starter Thread starter Obinna
  • Start date Start date
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?
***********************************/
 
/*******************************
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?
***********************************/

The runtime must be able to find and load the assembly containing the
Human type when deserializing the data. The reason you get that error
message is because it doesn't find it.


Mattias
 
So must I include the Assembly in the new application, if so how do I?
please dont tell me to place the Assembly in the Global assembly cache,
cos the whole Idea is to use a different application without knowing
anything bout the previous application to read such information,
probably, even remotely...

Obinna.
 
So must I include the Assembly in the new application, if so how do I?
please dont tell me to place the Assembly in the Global assembly cache,
cos the whole Idea is to use a different application without knowing
anything bout the previous application to read such information,
probably, even remotely...

You can put it anywhere the CLR will try to find it. The GAC is just
one option, the application directory another. For details, see

How the Runtime Locates Assemblies
http://msdn2.microsoft.com/en-us/yx7xezcf.aspx


Mattias
 
Mattias, that article doesn't tell me how. It tell's me why. I'd rather
go straight to the steps involved in accomplishing that, and then
understand by expirience.
I'm very greatful for your assistance, and would be even more if you
could be of futher assistance.

I dont know if this will be far from this group's interest, but how do
I set windows restrictions (as in ... how can I restrict a user or set
of users from running a window's application?)

Obinna.
 
Back
Top