473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

HOW TO : Serialization and "external" Assembly

Hi All,

How can I load an object A that host an object B that is defined in an other
Assembly ?

Thank you

See the exemple below :

I have a DLL with these classes

namespace RTECH
{
[Serializable()]
public class Main // A Class that host a wizard
{
public Main()
{
}
public Wizard Wizard
{
get { return _Wizard; }
set { _Wizard = value; }
}
}

[Serializable()]
public abstract class Wizard // A Abstract Class Wizard
{
protected static string _Name;

}
}

I have an other DLL with this class

using RTECH;
namespace RTECH.Demo
{
[Serializable()]
public class WizardDemo : Wizard
{
public WizardDemo() : base()
{
}
}
}
Now I have an EXE with this code
Using RTECH;
.....
{
Main _main = new Main();
//I load the plugin that contain the WizardDemo
Assembly _assembly =
Assembly.LoadFile(@"C:\Sources\TestWizard\WizardDe mo\bin\Debug\WizardDemo.dl
l");
Wizard _wizard =
(Wizard)_assembly.CreateInstance("RTECH.Demo.Wizar dDemo");
_main.Wizard = _wizard;

FileStream f = new FileStream(@"c:\sources\testwizard\test.bin",
System.IO.FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(f, _main);
f.Close();

f = new FileStream(@"c:\sources\testwizard\test.bin",
System.IO.FileMode.Open);
bf = new BinaryFormatter();
Main _main2 = (Main)bf.Deserialize(f); //Problem here
f.Close();
}

Nov 15 '05 #1
1 2631
Paul,

The way to get around this is to make sure that you have BOTH assemblies
loaded before you attempt to deserialize the stream.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul Bawin" <pa********@skynet.be> wrote in message
news:40*********************@news.skynet.be...
Hi All,

How can I load an object A that host an object B that is defined in an other Assembly ?

Thank you

See the exemple below :

I have a DLL with these classes

namespace RTECH
{
[Serializable()]
public class Main // A Class that host a wizard
{
public Main()
{
}
public Wizard Wizard
{
get { return _Wizard; }
set { _Wizard = value; }
}
}

[Serializable()]
public abstract class Wizard // A Abstract Class Wizard
{
protected static string _Name;

}
}

I have an other DLL with this class

using RTECH;
namespace RTECH.Demo
{
[Serializable()]
public class WizardDemo : Wizard
{
public WizardDemo() : base()
{
}
}
}
Now I have an EXE with this code
Using RTECH;
....
{
Main _main = new Main();
//I load the plugin that contain the WizardDemo
Assembly _assembly =
Assembly.LoadFile(@"C:\Sources\TestWizard\WizardDe mo\bin\Debug\WizardDemo.dl l");
Wizard _wizard =
(Wizard)_assembly.CreateInstance("RTECH.Demo.Wizar dDemo");
_main.Wizard = _wizard;

FileStream f = new FileStream(@"c:\sources\testwizard\test.bin",
System.IO.FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(f, _main);
f.Close();

f = new FileStream(@"c:\sources\testwizard\test.bin",
System.IO.FileMode.Open);
bf = new BinaryFormatter();
Main _main2 = (Main)bf.Deserialize(f); //Problem here
f.Close();
}

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John Nossluap | last post by:
I've got a third-party assembly dll containing an "internal" class with some public methods I would very much like to use. I understand the meaning and reason of setting the accessibility of the...
2
by: Gnus | last post by:
Hi all! I have a little(?) problem with external schema location... I'm using xerces/xalan (C++) for doing some actions with some set of xml-files. Some of these files must validating...
2
by: Thijs | last post by:
Hello, I´ve got a question regarding controlling an external app. I´m writing a vb.NET app that, at some point, needs to push a button in an external app. This external app has no API...
4
by: =?Utf-8?B?U0g=?= | last post by:
There seems to be an issue with .NET 3.5/Visual Studio 2008 (Team System). After convincing my company to create our latest project in .NET 3.5, this is kind of reflecting bad on me. Problem:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.