473,842 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.LoadFi le(@"C:\Sources \TestWizard\Wiz ardDemo\bin\Deb ug\WizardDemo.d l
l");
Wizard _wizard =
(Wizard)_assemb ly.CreateInstan ce("RTECH.Demo. WizardDemo");
_main.Wizard = _wizard;

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

f = new FileStream(@"c: \sources\testwi zard\test.bin",
System.IO.FileM ode.Open);
bf = new BinaryFormatter ();
Main _main2 = (Main)bf.Deseri alize(f); //Problem here
f.Close();
}

Nov 15 '05 #1
1 2665
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.co m

"Paul Bawin" <pa********@sky net.be> wrote in message
news:40******** *************@n ews.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.LoadFi le(@"C:\Sources \TestWizard\Wiz ardDemo\bin\Deb ug\WizardDemo.d l l");
Wizard _wizard =
(Wizard)_assemb ly.CreateInstan ce("RTECH.Demo. WizardDemo");
_main.Wizard = _wizard;

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

f = new FileStream(@"c: \sources\testwi zard\test.bin",
System.IO.FileM ode.Open);
bf = new BinaryFormatter ();
Main _main2 = (Main)bf.Deseri alize(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
1841
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 class to internal. But is there any way, dirty or not, I could use this class and its methods anyway?
2
2486
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 against schema, which location specify in config file ("external" schema). Other files must be validating against schema, which location specify in parsed xml file (via xsi:shemaLocation attribute, "internal" schema) How can I switch between these ...
2
1053
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 whatsoever. Is there a way to do this? I guess I have to raise a ButtonX_click event in the other app, but I don´t know how to do that, nor do I know how to even find the name of this ButtonX. Does anyone have a clue as how to do this?
4
3256
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: Solution will NOT compile. Error is simply: "External component has thrown an exception". NO other details.
0
9715
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10945
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9454
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7040
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5886
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4500
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4090
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.