473,382 Members | 1,332 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,382 software developers and data experts.

Using XmlAttributeOverrides to override Type in a different assemb

Hi,
I have the following class.

Assembly: A.dll
public class Customers {
public Customer[] customer;
}

public class Customer {
public string name;
public string country;
public object obj;
}

The basic need is to serialize this. But the constraint is.. Customer.Obj
can contain a Type of either "Order" or "Product" at runtime. This actual
type is not known at design time. For this I use XmlAttributeOverrides to
override the Type and Serialize it. However it seems to require that the
definitions for "Order" or "Product" Types be present within the assembly
A.dll itself where the code to serialize is present. But in my case it would
be present in another assembly (say) B.dll.

To make it more clear - A.dll contains the "Customers" type to be serialzed.
The types that Customer.Obj can take at runtime are defined in B.dll. The
code to serialize the "Customers" type by using XmlAttributeOverrides is also
present in A.dll. Now, this does not work as the definitions for the types
that Customer.Obj can take are in B.dll. However if I move definitions for
the types that Customer.Obj
can take inline into A.dll, it works fine.

So, How can I override attributes present in a different dll using
XmlAttributeOverrides.

Thanks and Regards,
Kishore
Nov 16 '05 #1
3 2264
Kishore,

It's not that it requires the definition to be in the same dll, but
rather, when you deserialize it, the assembly containing the types have to
be loaded. Because of this, you will want make sure that the assembly B.dll
is loaded (either through a reference, or a call to the static Load method
on the Assembly class).

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

"Kishore Gopalan" <Ki************@discussions.microsoft.com> wrote in
message news:F9**********************************@microsof t.com...
Hi,
I have the following class.

Assembly: A.dll
public class Customers {
public Customer[] customer;
}

public class Customer {
public string name;
public string country;
public object obj;
}

The basic need is to serialize this. But the constraint is.. Customer.Obj
can contain a Type of either "Order" or "Product" at runtime. This actual
type is not known at design time. For this I use XmlAttributeOverrides to
override the Type and Serialize it. However it seems to require that the
definitions for "Order" or "Product" Types be present within the assembly
A.dll itself where the code to serialize is present. But in my case it
would
be present in another assembly (say) B.dll.

To make it more clear - A.dll contains the "Customers" type to be
serialzed.
The types that Customer.Obj can take at runtime are defined in B.dll. The
code to serialize the "Customers" type by using XmlAttributeOverrides is
also
present in A.dll. Now, this does not work as the definitions for the types
that Customer.Obj can take are in B.dll. However if I move definitions
for
the types that Customer.Obj
can take inline into A.dll, it works fine.

So, How can I override attributes present in a different dll using
XmlAttributeOverrides.

Thanks and Regards,
Kishore

Nov 16 '05 #2
Hello Kishore,

Since you decided not to use OO principles in designing your class
heirarchy, the serializer is stumped. It doesn't know what object to look
for.
If both Order or Product can be stored in that object, then either (a)
create an interface that both Order and Product can inherit from or (b)
create a little heirarchy in the b.dll to do encapsulate this.

option (a) is far better. However, I will demonstrate (b) because I don't
know what else is in your order or product classes.

public interface EmbeddedType
{
}

public class OrderContainer : EmbeddedType, Order
{
}

public class ProductContainer: EmbeddedType, Product
{
}

public class Customer {
public string name;
public string country;
public EnbeddedType obj;
}
Now, the serializer should have very little difficulty figuring out what is
included in what.

--- Nick

"Kishore Gopalan" <Ki************@discussions.microsoft.com> wrote in
message news:F9**********************************@microsof t.com...
Hi,
I have the following class.

Assembly: A.dll
public class Customers {
public Customer[] customer;
}

public class Customer {
public string name;
public string country;
public object obj;
}

The basic need is to serialize this. But the constraint is.. Customer.Obj
can contain a Type of either "Order" or "Product" at runtime. This actual
type is not known at design time. For this I use XmlAttributeOverrides to
override the Type and Serialize it. However it seems to require that the
definitions for "Order" or "Product" Types be present within the assembly
A.dll itself where the code to serialize is present. But in my case it would be present in another assembly (say) B.dll.

To make it more clear - A.dll contains the "Customers" type to be serialzed. The types that Customer.Obj can take at runtime are defined in B.dll. The
code to serialize the "Customers" type by using XmlAttributeOverrides is also present in A.dll. Now, this does not work as the definitions for the types
that Customer.Obj can take are in B.dll. However if I move definitions for the types that Customer.Obj
can take inline into A.dll, it works fine.

So, How can I override attributes present in a different dll using
XmlAttributeOverrides.

Thanks and Regards,
Kishore

Nov 16 '05 #3
I tried loading the assembly using Assembly.LoadFrom just before the
serialization happens. Still, the same issue persists. I also tried aadding a
reference. Still, the same thing. What could I be doing wrong.

Kishore

"Nicholas Paldino [.NET/C# MVP]" wrote:
Kishore,

It's not that it requires the definition to be in the same dll, but
rather, when you deserialize it, the assembly containing the types have to
be loaded. Because of this, you will want make sure that the assembly B.dll
is loaded (either through a reference, or a call to the static Load method
on the Assembly class).

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

"Kishore Gopalan" <Ki************@discussions.microsoft.com> wrote in
message news:F9**********************************@microsof t.com...
Hi,
I have the following class.

Assembly: A.dll
public class Customers {
public Customer[] customer;
}

public class Customer {
public string name;
public string country;
public object obj;
}

The basic need is to serialize this. But the constraint is.. Customer.Obj
can contain a Type of either "Order" or "Product" at runtime. This actual
type is not known at design time. For this I use XmlAttributeOverrides to
override the Type and Serialize it. However it seems to require that the
definitions for "Order" or "Product" Types be present within the assembly
A.dll itself where the code to serialize is present. But in my case it
would
be present in another assembly (say) B.dll.

To make it more clear - A.dll contains the "Customers" type to be
serialzed.
The types that Customer.Obj can take at runtime are defined in B.dll. The
code to serialize the "Customers" type by using XmlAttributeOverrides is
also
present in A.dll. Now, this does not work as the definitions for the types
that Customer.Obj can take are in B.dll. However if I move definitions
for
the types that Customer.Obj
can take inline into A.dll, it works fine.

So, How can I override attributes present in a different dll using
XmlAttributeOverrides.

Thanks and Regards,
Kishore


Nov 16 '05 #4

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

Similar topics

9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
5
by: Darius | last post by:
I'm writing here in hopes that someone can explain the difference between the new and virtual/override keywords in C#. Specifically, what is the difference between this: public class Window {...
0
by: Horia Tudosie | last post by:
Using Visual Studio 2003 This is to report a series of bugs regarding the FlagsAttribute and (independently) the usage of interfaces in Web applications. Let’s declare xColors type like: ...
0
by: Kishore Gopalan | last post by:
Hi, I have the following class. Assembly: A.dll public class Customers { public Customer customer; } public class Customer { public string name;
5
by: Stoyan | last post by:
Hi All, I don't understand very well this part of MSDN: "Derived classes that override GetHashCode must also override Equals to guarantee that two objects considered equal have the same hash code;...
15
by: Cliff_Harker | last post by:
Why can't I do this in C# public class A { public A virtual whatever( A a ) { } } public class B : A
4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
0
by: Simon Gregory | last post by:
I'm trying to override the default elementnames in the (seemingly) simple case of serializing an array of GUIDs into XML. Here's the basic code I started with: Dim arrGuids(3) as Guid ...
3
by: Andrus | last post by:
Two assemblies both referenced by application contain same class (created by script): namespace Script { public class Class1 { } } Compiling application
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.