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

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(fileName);
blob = (CustomClass) serializer.Deserialize(reader); //error

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

object o = (object) serializer.Deserialize (reader);
blob = (CustomClass) serializer.Deserialize (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.CanDeserialize(reader)
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(ElementName="ABC")]
public Country[] ABC;
}

public class Country
{
[XmlAttribute]
public string CountryDescription;

[XmlAttribute]
public string Value;
}

and the .xml file is:

<?xml version="1.0" encoding="utf-8" ?>
<HyperionConfiguration Name="bnp">
<ABC CountryDescription="United Arab Emirates" Value="ae"/>
<ABC CountryDescription="Antilhas" Value="an"/>
<ABC CountryDescription="Argentina" Value="ar"/>
<ABC CountryDescription="Austria" Value="at"/>
<ABC CountryDescription="Australia" Value="au"/>
</HyperionConfiguration>

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

rgds

pb

Nov 12 '05 #1
2 1490
pb
Hi,

update:

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

<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="4" />
</switches>
</system.diagnostics>

to output the temporary XmlSerialization 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().Assembly.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.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="4" />
</switches>
</system.diagnostics>

to output the temporary XmlSerialization 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
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...
1
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"...
1
by: Gianmaria | last post by:
Hi, how do i deserialize a composite object my object have this structure... obj |_ leaf |_subObj |_leaf
2
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...
1
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...
3
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
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...
4
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...
1
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? ...
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: 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: 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...
0
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,...
0
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...
0
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...
0
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...

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.