c#3.5 Deserialization error - object reference not set

Posted by BBR on Stack Overflow See other posts from Stack Overflow or by BBR
Published on 2012-11-14T10:58:33Z Indexed on 2012/11/14 10:59 UTC
Read the original article Hit count: 246

Filed under:
|

I am trying to deserialize an xml string in c#3.5, the code below does work in c# 4.0. When I try to run in the code in c#3.5 I get an Object reference not set to an instance of an object exception when the code tries in initialize the XmlSerializer.

Any help would be appreciated.

string xml = "<boolean xmlns=\"http://schemas.microsoft.com/2003/10/serialization/\">false</boolean>";
var xSerializer = new XmlSerializer(typeof(bool), null, null,
             new XmlRootAttribute("boolean"),
             "http://schemas.microsoft.com/2003/10/serialization/");

             using (var sr = new StringReader(xml))
            using (var xr = XmlReader.Create(sr))
            {
                var y = xSerializer.Deserialize(xr);
            }

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="System.Xml"
  StackTrace:
       at System.Xml.Serialization.XmlSerializer..ctor(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, String defaultNamespace, String location, Evidence evidence)
       at System.Xml.Serialization.XmlSerializer..ctor(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, String defaultNamespace)
       ....
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

© Stack Overflow or respective owner

Related posts about c#

Related posts about deserialization