"The type or namespace name 'XmlSerializer' could not be found" error when System.Xml.dll is referenced

Ed Ayers picture Ed Ayers · Feb 6, 2011 · Viewed 11.9k times · Source

I've already wasted a few hours on this one:

XmlSerializer serializer;

YES, the using is there, the reference is there, I made the entire solution in VS2010 using .NET 4.0 so it's not any of those things. If I go in Object Explorer I can find the XmlSerializer class I want in the correct namespace but if I try typing the above line in to my code file and compiling I get the dreaded

The type or namespace name 'XmlSerializer' could not be found (are you missing a using directive or an assembly reference?)

warning of death. I don't get it on IntelliSense either. All other threads/websites I've looked on have come up blank or with one of the solutions I've already ruled out. What am I missing? Cheers

Answer

Dan Abramov picture Dan Abramov · Feb 6, 2011

Do you build a Silverlight app?
Silverlight has XmlSerializer defined inside System.Xml.Serialization.dll assembly which is not referenced by default.
This often leads to confusion because other framework versions have it defined in System.Xml.dll.

You need to add System.Xml.Serialization.dll to project references to wire it up.