Thursday, February 8, 2007

System.IO.FileNotFoundException occurring with XmlSerializer

Recently I discovered that when loading the a C# app in the debugger and have exception trapping enabled, you will receive an exception "System.IO.FileNotFoundException" with a message similar to: "Could not load file or assembly 'mscorlib.XmlSerializers,..."

Looking around on the Microsoft bug database I found this explination: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=93647

"XmlSerializer attempts to load pre-generated serializers to avoid compilation of the serialization code on the fly. There is no easy way to check for "will assembly be found by the Assembly.Load() call", it would be duplicating Fusion path search and loader logic in XmlSerializer."

Basically, this is not really an error since the exception is caught and the assembly is then generated in order to run the XmlSerializer correctly. There is no way to avoid this exception and it will always be caught by the Exception manager in the debugger when you have CLR Exceptions set to be thrown. It is perfectly safe to just ignore this exception.


No comments: