By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,054 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,054 IT Pros & Developers. It's quick & easy.

Unable to cast object of type while deserializing to class

P: n/a
Hi,
I am running into this problem while deserializing the class, I do not
get this error the first time I try to deserialize but then I keep
getting this error - Unable to cast object of type ABCSettings to type
ABCSettings.

I tried closing the memory stream but no luck.Can you please help me
figure out this issue

byte[] b = Convert.FromBase64String(szSettingsSerialized);
MemoryStream oMs2 = new MemoryStream(b);
BinaryFormatter oBinaryFormatter = new BinaryFormatter();
if(this.zSettings == null)
this.xSettings = new ABCSettings()
try
{
this.xSettings =
(ABCPage.ABCSettings)oBinaryFormatter.Deserialize( oMs2);
}
catch(Exception ex)
{
this.aErrorMessages.Add("An error occurred.[" + ex.Message + "]");
}
finally
{
oMs2.Close();
}

Oct 2 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
The error is thrown at
this.xSettings =
(ABCPage.ABCSettings)oBinaryFormatter.Deserialize( oMs2);

please ignore the typo at if(this.zSettings == null)
we*****@gmail.com wrote:
Hi,
I am running into this problem while deserializing the class, I do not
get this error the first time I try to deserialize but then I keep
getting this error - Unable to cast object of type ABCSettings to type
ABCSettings.

I tried closing the memory stream but no luck.Can you please help me
figure out this issue

byte[] b = Convert.FromBase64String(szSettingsSerialized);
MemoryStream oMs2 = new MemoryStream(b);
BinaryFormatter oBinaryFormatter = new BinaryFormatter();
if(this.zSettings == null)
this.xSettings = new ABCSettings()
try
{
this.xSettings =
(ABCPage.ABCSettings)oBinaryFormatter.Deserialize( oMs2);
}
catch(Exception ex)
{
this.aErrorMessages.Add("An error occurred.[" + ex.Message + "]");
}
finally
{
oMs2.Close();
}
Oct 2 '06 #2

P: n/a
Do this. before you deserialise:

oMs2.Position = 0;

Let me know....

<we*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
The error is thrown at
this.xSettings =
(ABCPage.ABCSettings)oBinaryFormatter.Deserialize( oMs2);

please ignore the typo at if(this.zSettings == null)
we*****@gmail.com wrote:
>Hi,
I am running into this problem while deserializing the class, I do not
get this error the first time I try to deserialize but then I keep
getting this error - Unable to cast object of type ABCSettings to type
ABCSettings.

I tried closing the memory stream but no luck.Can you please help me
figure out this issue

byte[] b = Convert.FromBase64String(szSettingsSerialized);
MemoryStream oMs2 = new MemoryStream(b);
BinaryFormatter oBinaryFormatter = new BinaryFormatter();
if(this.zSettings == null)
this.xSettings = new ABCSettings()
try
{
this.xSettings =
(ABCPage.ABCSettings)oBinaryFormatter.Deserialize (oMs2);
}
catch(Exception ex)
{
this.aErrorMessages.Add("An error occurred.[" + ex.Message + "]");
}
finally
{
oMs2.Close();
}

Oct 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.