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

Deserializing double.NaN generates exception in framwork source

P: n/a
Using the XmlSerializer to deserialize a double.NaN value generates an
exception in the framework which the framework then catches. This is super
undesirable in our application, because our developers have the IDE set to
break into the debugger on ALL Common Language Runtime Exceptions.

Can there be a change made to the framework source so that it does not throw
such routine exceptions? (Why does it throw such a routine exception?)

Example code to generate the exception follows:

/// <summary>
/// Use the XmlSerializer to write out a single "double.NaN" value.
/// All is well.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveFileEvent(object sender, System.EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.DefaultExt = "XML";

if (sfd.ShowDialog(this) != DialogResult.OK)
return;

XmlSerializer MySer = new XmlSerializer(typeof(double));
TextWriter MyTW = new StreamWriter(sfd.FileName);
MySer.Serialize(MyTW, double.NaN );
MyTW.Close();
}

/// <summary>
/// Open file previously saved with "SaveFileEvent".
/// Note exception is thrown (and caught) by the framework.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenFileEvent(object sender, System.EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.DefaultExt = "XML";

if (ofd.ShowDialog(this) != DialogResult.OK)
return;

XmlSerializer MySer = new XmlSerializer(typeof(double));

FileStream MyFS = new FileStream(ofd.FileName, FileMode.Open
);

double d = (double)MySer.Deserialize(MyFS);
}
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Nathan,

Do you have the option of migrating to .NET 2.0? In .NET 2.0, I do not
have this problem.

If not, it is possible that one of the events that fire during
deserialization could help you out.

As for changing the framework, considering that the change was made in
..NET 2.0, I doubt you will see a change in previous versions.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
Using the XmlSerializer to deserialize a double.NaN value generates an
exception in the framework which the framework then catches. This is
super
undesirable in our application, because our developers have the IDE set to
break into the debugger on ALL Common Language Runtime Exceptions.

Can there be a change made to the framework source so that it does not
throw
such routine exceptions? (Why does it throw such a routine exception?)

Example code to generate the exception follows:

/// <summary>
/// Use the XmlSerializer to write out a single "double.NaN" value.
/// All is well.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveFileEvent(object sender, System.EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.DefaultExt = "XML";

if (sfd.ShowDialog(this) != DialogResult.OK)
return;

XmlSerializer MySer = new XmlSerializer(typeof(double));
TextWriter MyTW = new StreamWriter(sfd.FileName);
MySer.Serialize(MyTW, double.NaN );
MyTW.Close();
}

/// <summary>
/// Open file previously saved with "SaveFileEvent".
/// Note exception is thrown (and caught) by the framework.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenFileEvent(object sender, System.EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.DefaultExt = "XML";

if (ofd.ShowDialog(this) != DialogResult.OK)
return;

XmlSerializer MySer = new XmlSerializer(typeof(double));

FileStream MyFS = new FileStream(ofd.FileName,
FileMode.Open
);

double d = (double)MySer.Deserialize(MyFS);
}

Nov 17 '05 #2

P: n/a
Hi Nicholas,

We are releasing shrink wrap (hopefully with software in it) in 5 weeks, so
we do not have the option of migrating to .NET 2.0 right now. Any advice you
have on overcoming this problem with .NET Framework 1.1 would be greatly
appreciated.

Thanks,
Nate

"Nicholas Paldino [.NET/C# MVP]" wrote:
Nathan,

Do you have the option of migrating to .NET 2.0? In .NET 2.0, I do not
have this problem.

If not, it is possible that one of the events that fire during
deserialization could help you out.

As for changing the framework, considering that the change was made in
..NET 2.0, I doubt you will see a change in previous versions.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
Using the XmlSerializer to deserialize a double.NaN value generates an
exception in the framework which the framework then catches. This is
super
undesirable in our application, because our developers have the IDE set to
break into the debugger on ALL Common Language Runtime Exceptions.

Can there be a change made to the framework source so that it does not
throw
such routine exceptions? (Why does it throw such a routine exception?)

Example code to generate the exception follows:

/// <summary>
/// Use the XmlSerializer to write out a single "double.NaN" value.
/// All is well.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveFileEvent(object sender, System.EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.DefaultExt = "XML";

if (sfd.ShowDialog(this) != DialogResult.OK)
return;

XmlSerializer MySer = new XmlSerializer(typeof(double));
TextWriter MyTW = new StreamWriter(sfd.FileName);
MySer.Serialize(MyTW, double.NaN );
MyTW.Close();
}

/// <summary>
/// Open file previously saved with "SaveFileEvent".
/// Note exception is thrown (and caught) by the framework.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenFileEvent(object sender, System.EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.DefaultExt = "XML";

if (ofd.ShowDialog(this) != DialogResult.OK)
return;

XmlSerializer MySer = new XmlSerializer(typeof(double));

FileStream MyFS = new FileStream(ofd.FileName,
FileMode.Open
);

double d = (double)MySer.Deserialize(MyFS);
}


Nov 17 '05 #3

P: n/a
Nathan,

The best solution I can see is to have your type implement
IXmlSerializable, this way, you can control the serialization of your type,
and prevent the runtime error.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
Hi Nicholas,

We are releasing shrink wrap (hopefully with software in it) in 5 weeks,
so
we do not have the option of migrating to .NET 2.0 right now. Any advice
you
have on overcoming this problem with .NET Framework 1.1 would be greatly
appreciated.

Thanks,
Nate

"Nicholas Paldino [.NET/C# MVP]" wrote:
Nathan,

Do you have the option of migrating to .NET 2.0? In .NET 2.0, I do
not
have this problem.

If not, it is possible that one of the events that fire during
deserialization could help you out.

As for changing the framework, considering that the change was made
in
..NET 2.0, I doubt you will see a change in previous versions.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in
message
news:EE**********************************@microsof t.com...
> Using the XmlSerializer to deserialize a double.NaN value generates an
> exception in the framework which the framework then catches. This is
> super
> undesirable in our application, because our developers have the IDE set
> to
> break into the debugger on ALL Common Language Runtime Exceptions.
>
> Can there be a change made to the framework source so that it does not
> throw
> such routine exceptions? (Why does it throw such a routine exception?)
>
> Example code to generate the exception follows:
>
> /// <summary>
> /// Use the XmlSerializer to write out a single "double.NaN"
> value.
> /// All is well.
> /// </summary>
> /// <param name="sender"></param>
> /// <param name="e"></param>
> private void SaveFileEvent(object sender, System.EventArgs e)
> {
> SaveFileDialog sfd = new SaveFileDialog();
> sfd.DefaultExt = "XML";
>
> if (sfd.ShowDialog(this) != DialogResult.OK)
> return;
>
> XmlSerializer MySer = new XmlSerializer(typeof(double));
> TextWriter MyTW = new StreamWriter(sfd.FileName);
> MySer.Serialize(MyTW, double.NaN );
> MyTW.Close();
> }
>
> /// <summary>
> /// Open file previously saved with "SaveFileEvent".
> /// Note exception is thrown (and caught) by the framework.
> /// </summary>
> /// <param name="sender"></param>
> /// <param name="e"></param>
> private void OpenFileEvent(object sender, System.EventArgs e)
> {
> OpenFileDialog ofd = new OpenFileDialog();
> ofd.DefaultExt = "XML";
>
> if (ofd.ShowDialog(this) != DialogResult.OK)
> return;
>
> XmlSerializer MySer = new XmlSerializer(typeof(double));
>
> FileStream MyFS = new FileStream(ofd.FileName,
> FileMode.Open
> );
>
> double d = (double)MySer.Deserialize(MyFS);
> }


Nov 17 '05 #4

P: n/a
Hi Nicholas,

Do you have any ETA for Visual Studio 2005 going release?

It is my understanding that Framework v2.0 will not work with Microsoft
Development Environment 2003. Is this correct?

I understand that implementing IXmlSerializable means manually spitting out
and reading in all the fields we wish to serialize. Is this correct?
Currently, a simple XML file that our app generates is over 7000 lines
(342KB), so manually forming this much XML could be a large task.

Aside:
I do believe the issue in this post is quite insignificant when looking at
all the other problems our development is facing right now. However, I do
feel abandoned by Microsoft for sticking with Developement Environment 2003.
It seems absurd that all Microsoft's effort is going into a beta product
while release product users suffer.

Thanks,
Nate

"Nicholas Paldino [.NET/C# MVP]" wrote:
Nathan,

The best solution I can see is to have your type implement
IXmlSerializable, this way, you can control the serialization of your type,
and prevent the runtime error.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in message
news:5F**********************************@microsof t.com...
Hi Nicholas,

We are releasing shrink wrap (hopefully with software in it) in 5 weeks,
so
we do not have the option of migrating to .NET 2.0 right now. Any advice
you
have on overcoming this problem with .NET Framework 1.1 would be greatly
appreciated.

Thanks,
Nate

"Nicholas Paldino [.NET/C# MVP]" wrote:
Nathan,

Do you have the option of migrating to .NET 2.0? In .NET 2.0, I do
not
have this problem.

If not, it is possible that one of the events that fire during
deserialization could help you out.

As for changing the framework, considering that the change was made
in
..NET 2.0, I doubt you will see a change in previous versions.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in
message
news:EE**********************************@microsof t.com...
> Using the XmlSerializer to deserialize a double.NaN value generates an
> exception in the framework which the framework then catches. This is
> super
> undesirable in our application, because our developers have the IDE set
> to
> break into the debugger on ALL Common Language Runtime Exceptions.
>
> Can there be a change made to the framework source so that it does not
> throw
> such routine exceptions? (Why does it throw such a routine exception?)
>
> Example code to generate the exception follows:
>
> /// <summary>
> /// Use the XmlSerializer to write out a single "double.NaN"
> value.
> /// All is well.
> /// </summary>
> /// <param name="sender"></param>
> /// <param name="e"></param>
> private void SaveFileEvent(object sender, System.EventArgs e)
> {
> SaveFileDialog sfd = new SaveFileDialog();
> sfd.DefaultExt = "XML";
>
> if (sfd.ShowDialog(this) != DialogResult.OK)
> return;
>
> XmlSerializer MySer = new XmlSerializer(typeof(double));
> TextWriter MyTW = new StreamWriter(sfd.FileName);
> MySer.Serialize(MyTW, double.NaN );
> MyTW.Close();
> }
>
> /// <summary>
> /// Open file previously saved with "SaveFileEvent".
> /// Note exception is thrown (and caught) by the framework.
> /// </summary>
> /// <param name="sender"></param>
> /// <param name="e"></param>
> private void OpenFileEvent(object sender, System.EventArgs e)
> {
> OpenFileDialog ofd = new OpenFileDialog();
> ofd.DefaultExt = "XML";
>
> if (ofd.ShowDialog(this) != DialogResult.OK)
> return;
>
> XmlSerializer MySer = new XmlSerializer(typeof(double));
>
> FileStream MyFS = new FileStream(ofd.FileName,
> FileMode.Open
> );
>
> double d = (double)MySer.Deserialize(MyFS);
> }


Nov 17 '05 #5

P: n/a
Nathan,

VS.NET 2005 is scheduled for release in early November (11/8 I believe,
but I'm not sure). You are right in that VS.NET 2005 will not develop for
..NET 1.1 or before.

As for implementing IXmlSerializable, you could easily write a method
using reflection to cycle through the public properties to do this (it
wouldn't be that bad really) and handle the float appropriately.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in message
news:66**********************************@microsof t.com...
Hi Nicholas,

Do you have any ETA for Visual Studio 2005 going release?

It is my understanding that Framework v2.0 will not work with Microsoft
Development Environment 2003. Is this correct?

I understand that implementing IXmlSerializable means manually spitting
out
and reading in all the fields we wish to serialize. Is this correct?
Currently, a simple XML file that our app generates is over 7000 lines
(342KB), so manually forming this much XML could be a large task.

Aside:
I do believe the issue in this post is quite insignificant when looking at
all the other problems our development is facing right now. However, I do
feel abandoned by Microsoft for sticking with Developement Environment
2003.
It seems absurd that all Microsoft's effort is going into a beta product
while release product users suffer.

Thanks,
Nate

"Nicholas Paldino [.NET/C# MVP]" wrote:
Nathan,

The best solution I can see is to have your type implement
IXmlSerializable, this way, you can control the serialization of your
type,
and prevent the runtime error.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in
message
news:5F**********************************@microsof t.com...
> Hi Nicholas,
>
> We are releasing shrink wrap (hopefully with software in it) in 5
> weeks,
> so
> we do not have the option of migrating to .NET 2.0 right now. Any
> advice
> you
> have on overcoming this problem with .NET Framework 1.1 would be
> greatly
> appreciated.
>
> Thanks,
> Nate
>
> "Nicholas Paldino [.NET/C# MVP]" wrote:
>
>> Nathan,
>>
>> Do you have the option of migrating to .NET 2.0? In .NET 2.0, I
>> do
>> not
>> have this problem.
>>
>> If not, it is possible that one of the events that fire during
>> deserialization could help you out.
>>
>> As for changing the framework, considering that the change was
>> made
>> in
>> ..NET 2.0, I doubt you will see a change in previous versions.
>>
>> Hope this helps.
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - mv*@spam.guard.caspershouse.com
>>
>> "Nathan Wiegman" <Na***********@discussions.microsoft.com> wrote in
>> message
>> news:EE**********************************@microsof t.com...
>> > Using the XmlSerializer to deserialize a double.NaN value generates
>> > an
>> > exception in the framework which the framework then catches. This
>> > is
>> > super
>> > undesirable in our application, because our developers have the IDE
>> > set
>> > to
>> > break into the debugger on ALL Common Language Runtime Exceptions.
>> >
>> > Can there be a change made to the framework source so that it does
>> > not
>> > throw
>> > such routine exceptions? (Why does it throw such a routine
>> > exception?)
>> >
>> > Example code to generate the exception follows:
>> >
>> > /// <summary>
>> > /// Use the XmlSerializer to write out a single "double.NaN"
>> > value.
>> > /// All is well.
>> > /// </summary>
>> > /// <param name="sender"></param>
>> > /// <param name="e"></param>
>> > private void SaveFileEvent(object sender, System.EventArgs e)
>> > {
>> > SaveFileDialog sfd = new SaveFileDialog();
>> > sfd.DefaultExt = "XML";
>> >
>> > if (sfd.ShowDialog(this) != DialogResult.OK)
>> > return;
>> >
>> > XmlSerializer MySer = new XmlSerializer(typeof(double));
>> > TextWriter MyTW = new StreamWriter(sfd.FileName);
>> > MySer.Serialize(MyTW, double.NaN );
>> > MyTW.Close();
>> > }
>> >
>> > /// <summary>
>> > /// Open file previously saved with "SaveFileEvent".
>> > /// Note exception is thrown (and caught) by the framework.
>> > /// </summary>
>> > /// <param name="sender"></param>
>> > /// <param name="e"></param>
>> > private void OpenFileEvent(object sender, System.EventArgs e)
>> > {
>> > OpenFileDialog ofd = new OpenFileDialog();
>> > ofd.DefaultExt = "XML";
>> >
>> > if (ofd.ShowDialog(this) != DialogResult.OK)
>> > return;
>> >
>> > XmlSerializer MySer = new XmlSerializer(typeof(double));
>> >
>> > FileStream MyFS = new FileStream(ofd.FileName,
>> > FileMode.Open
>> > );
>> >
>> > double d = (double)MySer.Deserialize(MyFS);
>> > }
>>
>>
>>


Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.