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

  • Thread starter Thread starter ron19ie
  • Start date Start date
R

ron19ie

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!!
 
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,

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,





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
 
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
 
Hi (e-mail address removed),

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!!
 
Ron said:
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
 
Ron said:
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.
 
- 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!
 
On Jun 27, 9:42 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top