473,698 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deserialize - Casting error

pb
Hi,

I'm having problems deploying a project to win2003.
It is currently on win2000 server and works fine - it also works fine
on my development machine - win2003.
Both my machine and the new machine are running .net 1.1 sp1.

I get an error when I try to descrialize a file (with code):

XmlTextReader reader = new XmlTextReader(f ileName);
blob = (CustomClass) serializer.Dese rialize(reader) ; //error

Error is of type: InvalidCastExce ption,
so I re-ran the code with:

object o = (object) serializer.Dese rialize (reader);
blob = (CustomClass) serializer.Dese rialize (reader); //error

and it deserializes ok, but get an error on the cast, still.

I then embedded the .xml file, and read from the assembly, just to make
sure it had nothing to do with filesystem permissions, etc., and still
won't work.

I also run:
serializer.CanD eserialize(read er)
each time (before deserializing) and it returns a true value.

The custom class is of the form:

public class CustomClass
{
public CustomClass() {}
/// <summary>
/// informative name of the configuration file
/// </summary>
[XmlAttribute]
public string Name;

[XmlElement(Elem entName="ABC")]
public Country[] ABC;
}

public class Country
{
[XmlAttribute]
public string CountryDescript ion;

[XmlAttribute]
public string Value;
}

and the .xml file is:

<?xml version="1.0" encoding="utf-8" ?>
<HyperionConfig uration Name="bnp">
<ABC CountryDescript ion="United Arab Emirates" Value="ae"/>
<ABC CountryDescript ion="Antilhas" Value="an"/>
<ABC CountryDescript ion="Argentina" Value="ar"/>
<ABC CountryDescript ion="Austria" Value="at"/>
<ABC CountryDescript ion="Australia" Value="au"/>
</HyperionConfigu ration>

Does anybody have any Ideas?
I'd really appreciate any clues!

rgds

pb

Nov 12 '05 #1
2 1512
pb
Hi,

update:

I ran the app with the following line in the Machine.Config:

<system.diagnos tics>
<switches>
<add name="XmlSerial ization.Compila tion" value="4" />
</switches>
</system.diagnost ics>

to output the temporary XmlSerializatio n files, and it runs fine!
When I delete that line - it throws the Cast error!

I have the application running under a User that is a member of the
Admin group on the machine.

Anyone have any ideas?

thanks

Padraic

Nov 12 '05 #2
pb
hi,

I fixed it!

When I ran the code without the flag set in the machine.config I saw
that:
o.GetType().Ass embly.Location - was different to when the flag was
turned on.

I had a copy of the .dll in another folder (without knowing it), and it
was reading the CustomClass type from that and hence it couldn't cast!
I deleted it and it worked fine!

Hope this helps someone out!

pb
pb wrote:
Hi,

update:

I ran the app with the following line in the Machine.Config:

<system.diagnos tics>
<switches>
<add name="XmlSerial ization.Compila tion" value="4" />
</switches>
</system.diagnost ics>

to output the temporary XmlSerializatio n files, and it runs fine!
When I delete that line - it throws the Cast error!

I have the application running under a User that is a member of the
Admin group on the machine.

Anyone have any ideas?

thanks

Padraic


Nov 12 '05 #3

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

Similar topics

1
570
by: Carl Mercier | last post by:
Hi! I have 2 different applications/assembly. The first one creates an object and serializes it to a textfile on disk. The second one has the the exact same class (copied/pasted). It reads the file that is on disk and attempts to deserialize it and create a new object. The process works fine if I serialize/deserialize in the first
1
4819
by: Alex | last post by:
I am creating an application that allows the user to link a plug-in "utility" class (Watcher) to a class at runtime. There are several Watcher utilities, each with a different style of "watching" something. The all inherit from BaseWatcher which implements an IWatcher interface. To configure the Watcher we have a configuration object per Watcher called <watcher_name>WatcherConfig inheriting from BaseWatcherConfig which implements...
1
2113
by: Gianmaria | last post by:
Hi, how do i deserialize a composite object my object have this structure... obj |_ leaf |_subObj |_leaf
2
6069
by: PCH | last post by:
I have 2 functions, one to serialize an object, and one to deserialize it. I can serialize just fine, the problem is when I try to deserialize it later... I get an error: {"Invalid BinaryFormatter stream. " } I looked at the serialized string vs whats passed into the deserialize
1
2129
by: Pavel Pavel | last post by:
I have 2 solution to deserialize ArrayList which contains objects I am using for this MemoryStream, but MemoryStream is not functional - I receive always error #End of Stream encountered before parsing was completed.# The second solution is functionall - I am using in this solution FileStream - everything works fine !! I want to use MemoryStream instead of FileStrem Can somebody tells me where I have problem ? I am using the same...
3
1402
by: Parag Mahajan | last post by:
Hello, I would like to know if one can overload System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader) method? Thanks, Parag.
2
11535
by: Thomas S | last post by:
Any suggestions on how to deserialize an object from one line of XML? I'm trying to deserialize multiple objects from one XML document, each object on one line of the file. The serialization is working, but when I try to read the line back into a MemoryStream, and then to deserialize from that, I get an error that the root node doesn't exist. Example XML lines: <?xml version="1.0"?><LogItem
4
4647
by: Anbu | last post by:
Hi All, I need to Deserialize the SoapService's SoapEnvelope response object. Here is the Body of the SoapEnvelope received as respone, <q1:serviceResponse xmlns:q1="urn:CallSetup"><serviceReturn xsi:type="q1:response" xmlnssi="http://www.w3.org/2001/XMLSchema-instance">ok</serviceReturn></q1:serviceResponse>
1
7853
by: Heron | last post by:
Hi, I'm having a problem deserializing my streams since they are utf8 encoded (they are being received over tcp/ip) so I was looking for a way to make the serializer use utf8, is there any? I'm getting the following error: There is an error in XML document (0, 0). innerexception: There is no Unicode byte order mark. Cannot switch to Unicode."
0
8678
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9030
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
8899
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,...
0
8871
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
5861
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
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.