473,405 Members | 2,404 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,405 software developers and data experts.

unable to cast object of type 'x' to type 'x'

Hi everyone,
I have generated (using xsd) the c# code version of the report
definition used for 2005 version of reports in reporting services. I
was using it locally and I was able to deserialize already created
reports. I then move the code (only) into my main project. I access
the rdlc files just fine, i can read them no problem, but the minute I
try the following I get the above error,

_reportDef = (Rdl.Report)ser.Deserialize(fileStream);

I have no idea why this might be the case....can anyone shed any light
on the matter?

Thanks a million!!

Jun 27 '07 #1
10 5494
On Jun 27, 4:29 pm, ron1...@gmail.com wrote:
I have generated (using xsd) the c# code version of the report
definition used for 2005 version of reports in reporting services. I
was using it locally and I was able to deserialize already created
reports. I then move the code (only) into my main project. I access
the rdlc files just fine, i can read them no problem, but the minute I
try the following I get the above error,

_reportDef = (Rdl.Report)ser.Deserialize(fileStream);

I have no idea why this might be the case....can anyone shed any light
on the matter?
The serialized data probably says which assembly the type belongs to,
and deserialization will honour that. You're then trying to cast it to
a different type - one which is within your main project.

Jon

Jun 27 '07 #2
Hi ro*****@gmail.com,

Checks that a deserialized object is equal to casted (full type info, using
debugger).

Kind Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
Hi everyone,
I have generated (using xsd) the c# code version of the report
definition used for 2005 version of reports in reporting services. I
was using it locally and I was able to deserialize already created
reports. I then move the code (only) into my main project. I access
the rdlc files just fine, i can read them no problem, but the minute I
try the following I get the above error,
_reportDef = (Rdl.Report)ser.Deserialize(fileStream);

I have no idea why this might be the case....can anyone shed any light
on the matter?

Thanks a million!!

Jun 27 '07 #3
Hi,

<ro*****@gmail.comwrote in message
news:11**********************@o11g2000prd.googlegr oups.com...
Hi everyone,
I have generated (using xsd) the c# code version of the report
definition used for 2005 version of reports in reporting services. I
was using it locally and I was able to deserialize already created
reports. I then move the code (only) into my main project. I access
the rdlc files just fine, i can read them no problem, but the minute I
try the following I get the above error,

_reportDef = (Rdl.Report)ser.Deserialize(fileStream);
Must probably you are trying to deserialize in another type.

Do this:

Console.WriteLine( _reportDef.GetType().FullName);
object o = ser.Deserialize(fileStream);
Console.WriteLine( _o.GetType().FullName);
And see if there is any difference.

Jun 27 '07 #4
Ron
On Jun 27, 9:42 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Hi,

<ron1...@gmail.comwrote in message

news:11**********************@o11g2000prd.googlegr oups.com...
Hi everyone,
I have generated (using xsd) the c# code version of the report
definition used for 2005 version of reports in reporting services. I
was using it locally and I was able to deserialize already created
reports. I then move the code (only) into my main project. I access
the rdlc files just fine, i can read them no problem, but the minute I
try the following I get the above error,
_reportDef = (Rdl.Report)ser.Deserialize(fileStream);

Must probably you are trying to deserialize in another type.

Do this:

Console.WriteLine( _reportDef.GetType().FullName);
object o = ser.Deserialize(fileStream);
Console.WriteLine( _o.GetType().FullName);

And see if there is any difference.
Hi Ignacio,

I have done as you suggested and I have gotten the result I expected
from the Console output;

Rdl.Report
Rdl.Report

Thanks for the suggestion though!
Much appreciated

Jun 27 '07 #5
Ron
On Jun 27, 9:32 am, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Jun 27, 4:29 pm, ron1...@gmail.com wrote:
I have generated (using xsd) the c# code version of the report
definition used for 2005 version of reports in reporting services. I
was using it locally and I was able to deserialize already created
reports. I then move the code (only) into my main project. I access
the rdlc files just fine, i can read them no problem, but the minute I
try the following I get the above error,
_reportDef = (Rdl.Report)ser.Deserialize(fileStream);
I have no idea why this might be the case....can anyone shed any light
on the matter?

The serialized data probably says which assembly the type belongs to,
and deserialization will honour that. You're then trying to cast it to
a different type - one which is within your main project.

Jon
Hi Jon,

the serialized file which I pass to the fileStream is a report that
was generated using VS2003. I then converted said file to the .rdlc
format and that was using VS2005. I was able to do this locally as I
said, but once moved it suddenly stopped. i was wondering if you had
any further ideas which may help?

Thanks a million!
Ron

Jun 27 '07 #6
Ron
On Jun 27, 9:41 am, Alex Meleta <amel...@gmail.comwrote:
Hi ron1...@gmail.com,

Checks that a deserialized object is equal to casted (full type info, using
debugger).

Kind Regards, Alex Meleta
[TechBlog]http://devkids.blogspot.com
Hi Alex,

I have done what was suggested below by Ignacio but to no avail, I got
the same types. I was wondering if you might have adda ny further
ideas?
Thanks a million for the help all the same
Much appreciated!!
Jun 27 '07 #7

"Ron" <ro*****@gmail.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
On Jun 27, 9:42 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
>Hi,

<ron1...@gmail.comwrote in message

news:11**********************@o11g2000prd.googleg roups.com...
Hi everyone,
I have generated (using xsd) the c# code version of the report
definition used for 2005 version of reports in reporting services. I
was using it locally and I was able to deserialize already created
reports. I then move the code (only) into my main project. I access
the rdlc files just fine, i can read them no problem, but the minute I
try the following I get the above error,
_reportDef = (Rdl.Report)ser.Deserialize(fileStream);

Must probably you are trying to deserialize in another type.

Do this:

Console.WriteLine( _reportDef.GetType().FullName);
object o = ser.Deserialize(fileStream);
Console.WriteLine( _o.GetType().FullName);

And see if there is any difference.

Hi Ignacio,

I have done as you suggested and I have gotten the result I expected
from the Console output;

Rdl.Report
Rdl.Report
Show

GetType().AssemblyQualifiedName

instead.
>
Thanks for the suggestion though!
Much appreciated

Jun 27 '07 #8
Ron <ro*****@gmail.comwrote:
the serialized file which I pass to the fileStream is a report that
was generated using VS2003. I then converted said file to the .rdlc
format and that was using VS2005. I was able to do this locally as I
said, but once moved it suddenly stopped. i was wondering if you had
any further ideas which may help?
It shouldn't matter which version of VS or .NET you were using - the
problem is that you're trying to use a different type to the one which
was serialized. I suggest you leave the types in the different
assembly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 27 '07 #9
Ron
On Jun 27, 11:50 am, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"Ron" <ron1...@gmail.comwrote in message

news:11**********************@z28g2000prd.googlegr oups.com...


On Jun 27, 9:42 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Hi,
<ron1...@gmail.comwrote in message
>news:11**********************@o11g2000prd.googleg roups.com...
Hi everyone,
I have generated (using xsd) the c# code version of the report
definition used for 2005 version of reports in reporting services. I
was using it locally and I was able to deserialize already created
reports. I then move the code (only) into my main project. I access
the rdlc files just fine, i can read them no problem, but the minute I
try the following I get the above error,
_reportDef = (Rdl.Report)ser.Deserialize(fileStream);
Must probably you are trying to deserialize in another type.
Do this:
Console.WriteLine( _reportDef.GetType().FullName);
object o = ser.Deserialize(fileStream);
Console.WriteLine( _o.GetType().FullName);
And see if there is any difference.
Hi Ignacio,
I have done as you suggested and I have gotten the result I expected
from the Console output;
Rdl.Report
Rdl.Report

Show

GetType().AssemblyQualifiedName

instead.


Thanks for the suggestion though!
Much appreciated- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
Hi Ben,

Thanks a million for the help!! Its much appreciated!
I have done as you suggested and to find again the same result as
before. Both the object I am casting into and the object I got after
deserialization returned the same result for the above mentioned
suggestion.
Thanks again though!

Jun 27 '07 #10
On Jun 27, 9:42 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.comwrote:
Hi,
><ron1...@gmail.comwrote in message
>>news:11**********************@o11g2000prd.google groups.com...
Hi everyone,
I have generated (using xsd) the c# code version of the report
definition used for 2005 version of reports in reporting services. I
was using it locally and I was able to deserialize already created
reports. I then move the code (only) into my main project. I access
the rdlc files just fine, i can read them no problem, but the minute
I
try the following I get the above error,
_reportDef = (Rdl.Report)ser.Deserialize(fileStream);
>Must probably you are trying to deserialize in another type.
>Do this:
>Console.WriteLine( _reportDef.GetType().FullName);
object o = ser.Deserialize(fileStream);
Console.WriteLine( _o.GetType().FullName);
>And see if there is any difference.
Hi Ignacio,
I have done as you suggested and I have gotten the result I expected
from the Console output;
Rdl.Report
Rdl.Report

Show

GetType().AssemblyQualifiedName

instead.


Thanks for the suggestion though!
Much appreciated- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Hi Ben,

Thanks a million for the help!! Its much appreciated!
I have done as you suggested and to find again the same result as
before. Both the object I am casting into and the object I got after
deserialization returned the same result for the above mentioned
suggestion.
Thanks again though!
AssemblyQualifiedName certainly shouldn't have given the same result as
FullName...

From the docs: "Gets the assembly-qualified name of the Type, which includes
the name of the assembly from which the Type was loaded. "

"Rdl.Report" doesn't include the name of the assembly.
Jun 28 '07 #11

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

Similar topics

0
by: Pankaj Jain | last post by:
Hi All, I have a class A which is derived from ServicesComponent to participate in automatic transaction with falg Transaction.Required. Class A is exposed to client through remoting on Http...
3
by: Imran Aziz | last post by:
Hello All, I am getting the following error on our production server, and I dont get the same error on the development box. Unable to cast object of type 'System.Byte' to type 'System.String'. ...
8
by: | last post by:
I have the following class : Public Class MyTreeNode Inherits TreeNode Dim mystring As String End Class Now, when I try to do this : ''''''''''''nodes is a TreeNodeCollection, s is string
0
by: sam | last post by:
Hi: I am not sure if this is the right place to post this question. Please let me know if it is not and I appreciate if someone could point me in the right direction. I am getting this error...
0
by: hlyall1189 | last post by:
Hi, I recently started upgrading some of my old vs 2003 apps to vs 2005 and used the conversion tool but now i get the following error after building the page. I have typecasted the lines as...
2
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) {...
3
by: keithb | last post by:
What could be causing this? this code: String Com = ""; if (Com != (String)rw.ItemArray) fails at runtime with the error message: Unable to cast object of type 'System.Int32' to type...
10
by: mypetrock | last post by:
Has anyone run into this error message? Unable to cast object of type 'Foo.Bar' to type 'Foo.Bar'. I'm trying to cast an object of type Foo.Bar that I got out of a hash table into a variable...
1
by: miller.brettm | last post by:
Hi, I'm working with an ActiveX serial component that fires an event when data is received. I need to continue to use this component because it contains the ability to do Xmodem1k an d XmodemCRC...
1
by: =?Utf-8?B?U2NvdHQ=?= | last post by:
Hello, Using VS2008 in a C# web service application, a class has been created that inherits from the ConfigurationSelection. This class file has been placed in the App_Code folder. The...
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: 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?
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:
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...
0
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,...
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...
0
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...

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.