Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 506
Ed Ayers Avatar asked Feb 05 '11 23:02

Ed Ayers


People also ask

What is XmlSerializer C#?

XML serialization is the process of converting an object's public properties and fields to a serial format (in this case, XML) for storage or transport. Deserialization re-creates the object in its original state from the XML output.

Can I make XmlSerializer ignore the namespace on Deserialization?

Yes, you can tell the XmlSerializer to ignore namespaces during de-serialization. Note this is the kind of thing I meant. You are not telling the XmlSerializer to ignore namespaces - you are giving it XML that has no namespaces.


1 Answers

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.

like image 170
Dan Abramov Avatar answered Nov 09 '22 05:11

Dan Abramov