PC Review


Reply
Thread Tools Rate Thread

XmlSerializer FileNotFoundException

 
 
Dan
Guest
Posts: n/a
 
      16th Jan 2009
I frequently serialize class instances with XmlSerializer. It works BUT...

Whenever I'm debugging and (via the Debug->Exceptions dialog) and enable
breaking whenever Common Language Runtime Exceptions are 'Thrown', I ALWAYS
get a FileNotFoundException instantiating a serializer:

XmlSerializer serializer = new XmlSerializer ( myClass.GetType () );

If I go back into the Exceptions dialog, Reset All and step over that line
of code it works, I re-enable Thrown exceptions and can continue. So, it's
not a show-stopper, but it's a pain to always have to be toggling this off
and on.

Is there anything I can do about this?

--
Dan
 
Reply With Quote
 
 
 
 
Jeroen Mostert
Guest
Posts: n/a
 
      16th Jan 2009
Dan wrote:
> I frequently serialize class instances with XmlSerializer. It works BUT...
>
> Whenever I'm debugging and (via the Debug->Exceptions dialog) and enable
> breaking whenever Common Language Runtime Exceptions are 'Thrown', I ALWAYS
> get a FileNotFoundException instantiating a serializer:
>
> XmlSerializer serializer = new XmlSerializer ( myClass.GetType () );
>
> If I go back into the Exceptions dialog, Reset All and step over that line
> of code it works, I re-enable Thrown exceptions and can continue. So, it's
> not a show-stopper, but it's a pain to always have to be toggling this off
> and on.
>
> Is there anything I can do about this?
>

In general, no -- try this with ASP.NET some time, you'll probably get
multiple framework exceptions (handled, of course, but that's not the
point). It's fairly painful. Thankfully, there are developers at Microsoft
who think this is painful too, so they do put some effort into making sure
the framework throws no exceptions in unexceptional cases. It's not perfect
yet, though.

However, in this very particular case, there probably *is* something you can
do. XmlSerializer generates temporary files and assemblies as it's producing
serializers. There are various things that can go wrong as it's doing so,
even if it manages to recover. You can avoid most problems with them if you
generate serializers up front (with sgen.exe or by checking the appropriate
project option) rather than have them produced at runtime. Not usable in all
scenarios, but when it is it's a good idea (not having to compile things at
runtime also gives a performance boost).

There's also this neat article:
http://msdn.microsoft.com/en-us/library/aa302290.aspx

It's old, but most of it still applies.

--
J.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileNotFoundException Luigi Microsoft ASP .NET 1 20th Sep 2006 05:17 PM
BUG: ASP.NET 2.0 FileNotFoundException Alan Samet Microsoft ASP .NET 2 25th Feb 2006 05:18 PM
FileNotFoundException' Peter Kirk Microsoft C# .NET 8 20th Jun 2005 10:08 PM
XmlSerializer, System.IO.FileNotFoundException Chris Aitchison Microsoft Dot NET 0 3rd Sep 2003 02:57 PM
XmlSerializer, System.IO.FileNotFoundException Chris Aitchison Microsoft Dot NET Framework 0 3rd Sep 2003 02:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:39 PM.