5

Possible Duplicate:
XmlSerializer giving FileNotFoundException at constructor

I received the first chance exception when I used XMLSerializer,

XMLSerializer xml = new XMLSerializer(typeof(A))

A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

Additional information: Could not load file or assembly 'A.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

It is OK, but it is annoying when debugging. What is the reason?

Community
  • 1
  • 1
user496949
  • 83,087
  • 147
  • 309
  • 426

1 Answers1

7

First chance means the program hasn't been able to deal with it yet, the debugger comes first. When you let it through, the app will deal with it nicely, so you don't get errors.

In this particular case, the thing is that XMLSerializer can use assemblies with compiled schema information in them. So it tries to load the assembly just in case it exists. If not, it's not a problem, but if it does, it will use that and it will be faster. When you compile your project in release mode, you often get XMLSerializer assemblies.

You should set up Visual Studio to ignore thrown (1st chance) exceptions, and only break on unhandled ones.

fejesjoco
  • 11,763
  • 3
  • 35
  • 65
  • Seems strange to me that this throws an exception at all. Surely this is part of the expected flow: if the framework is only speculatively loading the assembly then it must know there's a chance of failure. – Tim Barrass Dec 23 '10 at 09:28
  • 2
    They could call File.Exists before they try to load it, but I guess they were lazy :) – fejesjoco Dec 23 '10 at 10:13
  • I've been chasing this wild goose half the day. It really ended up being one of those exceptions that doesn't matter – Curtis Feb 07 '14 at 01:01
  • Works for me: Tools / Opctions / Debugging / Enable Just My code – Sith2021 Feb 14 '15 at 13:34