L
Lucas
Well, here's the situation.. It's pretty simple; just that I can't get
it to work.
I have 2 Executables..
The first one is called CSharp.exe which is a simple WinForm App. I
have a single button on the form which does the following OnClick.
// CSharp.cs
private void button1_Click(object sender, System.EventArgs e)
{
Hope y = new Hope();
BinaryFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("C:\\MyFile.bin", FileMode.Create,
FileAccess.Write, FileShare.None);
formatter.Serialize(stream, y);
stream.Close();
}
Within the same file I have the definition of the class "Hope" as
follows:
// Also in CSharp.cs
[Serializable]
public class Hope
{
private int i;
private string s;
public long l;
public double d;
public Hope()
{
i = 1;
s = "Lucas";
l = 123;
d = 3.1415;
}
}
The code above is pretty straightforward and simply serializes an
instance of the "Hope" object to a file C:\MyFile.bin.
The project compiles (to CSharp.exe) and runs fine.
The second executable is also a Winform App called Another.exe.
The Main form again has a single button which does the following:
// Another.cs
private void button1_Click(object sender, System.EventArgs e)
{
Assembly assm = Assembly.LoadFrom(@"\..\..\..\CSharp\Csharp.exe");
Current.Load(assm.GetName());
BinaryFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("C:\\MyFile.bin", FileMode.Open,
FileAccess.Read, FileShare.Read);
Object o = formatter.Deserialize(stream);
stream.Close();
}
Here I'm simply trying to deserialize that "Hope" Object that was
serialized to file. There is no reference to the CSharp.exe (I don't
think that it's even possible). So this program has no idea what the
"Hope" class is..
However, the 'Deserialize' method works fine when the CSharp.exe is in
the same directory as Another.exe. But not if it is elsewhere. (Gives
a "Cannot find the assembly CSharp..." error!)
I tried Loading CSharp.exe into the AppDomain, but it still complains
that it cannot load the "CSharp" assembly when the Deserialize method
is invoked.
I really don't want to have to copy that assembly into the same folder
as Another.exe.
I hope that all that makes some amount of sense...
Any help would be most appreciated..
Thanks,
Lucas.
it to work.
I have 2 Executables..
The first one is called CSharp.exe which is a simple WinForm App. I
have a single button on the form which does the following OnClick.
// CSharp.cs
private void button1_Click(object sender, System.EventArgs e)
{
Hope y = new Hope();
BinaryFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("C:\\MyFile.bin", FileMode.Create,
FileAccess.Write, FileShare.None);
formatter.Serialize(stream, y);
stream.Close();
}
Within the same file I have the definition of the class "Hope" as
follows:
// Also in CSharp.cs
[Serializable]
public class Hope
{
private int i;
private string s;
public long l;
public double d;
public Hope()
{
i = 1;
s = "Lucas";
l = 123;
d = 3.1415;
}
}
The code above is pretty straightforward and simply serializes an
instance of the "Hope" object to a file C:\MyFile.bin.
The project compiles (to CSharp.exe) and runs fine.
The second executable is also a Winform App called Another.exe.
The Main form again has a single button which does the following:
// Another.cs
private void button1_Click(object sender, System.EventArgs e)
{
Assembly assm = Assembly.LoadFrom(@"\..\..\..\CSharp\Csharp.exe");
Current.Load(assm.GetName());
BinaryFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("C:\\MyFile.bin", FileMode.Open,
FileAccess.Read, FileShare.Read);
Object o = formatter.Deserialize(stream);
stream.Close();
}
Here I'm simply trying to deserialize that "Hope" Object that was
serialized to file. There is no reference to the CSharp.exe (I don't
think that it's even possible). So this program has no idea what the
"Hope" class is..
However, the 'Deserialize' method works fine when the CSharp.exe is in
the same directory as Another.exe. But not if it is elsewhere. (Gives
a "Cannot find the assembly CSharp..." error!)
I tried Loading CSharp.exe into the AppDomain, but it still complains
that it cannot load the "CSharp" assembly when the Deserialize method
is invoked.
I really don't want to have to copy that assembly into the same folder
as Another.exe.
I hope that all that makes some amount of sense...
Any help would be most appreciated..
Thanks,
Lucas.