473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serialization problem with late binding

I'm having trouble serializing some of my classes when using late binding.
When I don't use late binding, it works fine. MyClass inherit from an
abstract class called
AbsMyClass.

If I do the following, it works fine:
#BEGIN
public static void Write( string fileName ){
MyClass myClass = null;
XmlSerializer xmlSerializer = null;
Stream stream = null;

myClass = new MyClass();

xmlSerializer = new XmlSerializer( myClass.GetType () );
stream = new FileStream(file Name, FileMode.Create ,
FileAccess.Writ e, FileShare.None) ;

xmlSerializer.S erialize(stream , gen);
stream.Close();
}
#END

If I do the following, I get a error msg

#BEGIN
public static void Write( string fileName ){
AbsMyClass myAbsClass = null;
XmlSerializer xmlSerializer = null;
Stream stream = null;

//This will get a pre-created myAbsClass using reflection
// The GetAbsClass is used in many other places in my code and it
// correctly return a pre-created class of the right type.
myAbsClass = GetAbsClass("My FullClassName") ;

xmlSerializer = new XmlSerializer(
myAbsClass.GetT ype() );
stream = new FileStream(file Name, FileMode.Create ,
FileAccess.Writ e, FileShare.None) ;

xmlSerializer.S erialize(stream , gen);
stream.Close();
}
#END

#ERROR

ex : There was an error generating the XML document.
stack trace :
at System.Xml.Seri alization.XmlSe rializer.Serial ize(XmlWriter xmlWriter,
Obje
ct o, XmlSerializerNa mespaces namespaces, String encodingStyle)
at System.Xml.Seri alization.XmlSe rializer.Serial ize(XmlWriter xmlWriter,
Obje
ct o, XmlSerializerNa mespaces namespaces)
at System.Xml.Seri alization.XmlSe rializer.Serial ize(Stream stream, Object
o,
XmlSerializerNa mespaces namespaces)
at System.Xml.Seri alization.XmlSe rializer.Serial ize(Stream stream, Object
o)
#END_ERROR
Tks in advance.
Nov 15 '05 #1
1 2186
Sacha,

Can you give the message that comes with the Exception?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Sacha" <sa***@severus. org> wrote in message
news:eq******** ******@TK2MSFTN GP09.phx.gbl...
I'm having trouble serializing some of my classes when using late binding.
When I don't use late binding, it works fine. MyClass inherit from an
abstract class called
AbsMyClass.

If I do the following, it works fine:
#BEGIN
public static void Write( string fileName ){
MyClass myClass = null;
XmlSerializer xmlSerializer = null;
Stream stream = null;

myClass = new MyClass();

xmlSerializer = new XmlSerializer( myClass.GetType () );
stream = new FileStream(file Name, FileMode.Create ,
FileAccess.Writ e, FileShare.None) ;

xmlSerializer.S erialize(stream , gen);
stream.Close();
}
#END

If I do the following, I get a error msg

#BEGIN
public static void Write( string fileName ){
AbsMyClass myAbsClass = null;
XmlSerializer xmlSerializer = null;
Stream stream = null;

//This will get a pre-created myAbsClass using reflection
// The GetAbsClass is used in many other places in my code and it
// correctly return a pre-created class of the right type.
myAbsClass = GetAbsClass("My FullClassName") ;

xmlSerializer = new XmlSerializer(
myAbsClass.GetT ype() );
stream = new FileStream(file Name, FileMode.Create ,
FileAccess.Writ e, FileShare.None) ;

xmlSerializer.S erialize(stream , gen);
stream.Close();
}
#END

#ERROR

ex : There was an error generating the XML document.
stack trace :
at System.Xml.Seri alization.XmlSe rializer.Serial ize(XmlWriter xmlWriter, Obje
ct o, XmlSerializerNa mespaces namespaces, String encodingStyle)
at System.Xml.Seri alization.XmlSe rializer.Serial ize(XmlWriter xmlWriter, Obje
ct o, XmlSerializerNa mespaces namespaces)
at System.Xml.Seri alization.XmlSe rializer.Serial ize(Stream stream, Object o,
XmlSerializerNa mespaces namespaces)
at System.Xml.Seri alization.XmlSe rializer.Serial ize(Stream stream, Object o)
#END_ERROR
Tks in advance.

Nov 15 '05 #2

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

Similar topics

0
1351
by: Andy Searls via .NET 247 | last post by:
Trying to get business objects to work as return values for webservices. The primary problem is that the business objects arelate bound, requiring interfaces for property types. I tryusing the XmlTypeAttribute to indicate the class to use in placeof the interface, but that doesn't seem to do any good. Here's the simplified objects in question: public interface IAddress { int AddressKey {get;set;} }
4
2294
by: David | last post by:
Hi, I want to work with Access 2002. I will need to be able to distribute my application to users that may still have access 2000 on their computers. I know access 2002 has a function that enables you to convert a database to a format of an earlier version of Access. I wanted to check for any unforeseen problems so here is what I did: I used Access 2002 to convert my Access 2000 application to the 2002
14
4299
by: Composer | last post by:
I've read many postings about the problem of Access.References.IsBroken and the consensus seems to be that late binding is the cure-all. I have a very complex Access application that needs hundreds of lines of code to format a Word document in a very specific way. Because my clients have various versions of Word, the problem of broken references comes up. I wish Microsoft had implemented a reasonable solution, so that VBA could do...
9
10413
by: Zlatko Matić | last post by:
I was reading about late binding, but I'm not completely sure what is to be done in order to adjust code to late binding... For example, I'm not sure if this is correct: early binding: Dim ws As DAO.Workspace Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim rs As DAO.Recordset
0
2491
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem serializing the object but there seems to be a problem serializing an array of objects. Any help will be appreciated "Cannot assign object of type System.Object to an object of type ElectronicWallet.C2PTest.PaymentItem." :...
30
2818
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as integer The integers in these arrays are actually pointers to different columns of data in a text file.
6
1888
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document that describes this. Here's the setup. We have a COM server, written in Python. For completeness, here is the script: ----- testserver.py ----- import pythoncom
2
8340
by: GS | last post by:
I have installed the ms PIA for ofc XP, and followed the article http://support.microsoft.com/kb/247412/ trying to paste into a worksheet However I got late binding not allowed errors .... webOCWraooer,Copy // get the desired data into clapboard
3
16057
ADezii
by: ADezii | last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile time (Early Binding) or run time (Late Binding). When you declare an Object Variable as a specific Data Type, you are using Early Binding so the verification can take place during compile time. When you declare a Variable of the generic Object Data...
0
8325
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
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
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
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
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.