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

    Question

  • Hi Folks,

    I want to deserialize a xml into a object in in mainpage.xaml.cs in a silverlight project. I have included System.Xml.Serialization namespace. The dll refered in silverlight project is "C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v3.0\System.Xml.dll". But when i compile the following code it throws an error " The type or namespace name 'XmlSerializer' could not be found (are you missing a using directive or an assembly reference?) ".

     

    XmlSerializer serializer = new XmlSerializer(typeof(node));
    HttpWebRequest wrservlet = WebRequest.Create(appURL) as HttpWebRequest;
    HttpWebResponse hwrWebResponse = (HttpWebResponse)wrservlet.GetResponse();
    TextReader outStream = new StreamReader(hwrWebResponse.GetResponseStream());
    node po = (node)serializer.Deserialize(outStream);
    outStream.Close();
     

    Please let me know what is going on here.

    Thanks,

    Ramneek

    Wednesday, July 22, 2009 4:34 AM

Answers

  • xmlserializer is not there in silverlight. neither is xmldocument or xmlnode. instead what you have is xdocument and xnode.

    what you can do is following

    Dim TxtRdr As TextReader = New StringReader(data)

    Dim xDoc As XDocument = XDocument.Load(TxtRdr)

    and then use linq to parse your data to required object.

    Thanks

    Jac

    Wednesday, July 22, 2009 5:03 AM

All replies

  • xmlserializer is not there in silverlight. neither is xmldocument or xmlnode. instead what you have is xdocument and xnode.

    what you can do is following

    Dim TxtRdr As TextReader = New StringReader(data)

    Dim xDoc As XDocument = XDocument.Load(TxtRdr)

    and then use linq to parse your data to required object.

    Thanks

    Jac

    Wednesday, July 22, 2009 5:03 AM
  • xmlserializer is not there in silverlight. neither is xmldocument or xmlnode. instead what you have is xdocument and xnode.

    what you can do is following

    Dim TxtRdr As TextReader = New StringReader(data)

    Dim xDoc As XDocument = XDocument.Load(TxtRdr)

    and then use linq to parse your data to required object.

    Thanks

    Jac

     

    Jac,

    But msdn documentation says XmlSerializer is there for silverlight:-

    "http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer(VS.95).aspx"

    Wednesday, July 22, 2009 5:08 AM
  • User linq to xml to solve the problem of serialization. For the web request you have to do an asynchronous callback in order to get a url. Keep in mind that the domain you make the request should have the cross domain file.
    Wednesday, July 22, 2009 9:58 AM
  • I was also under the same impression that it is supported.

    There are similar things which MSDN says SL supports but behaves otherwise. (indexed property binding for eg)

    Linq to xml is a fool proof way of doing it. You can add all your custom attributes and have the full power while deserializing the same.

    Thanks

    Jac

    Wednesday, July 22, 2009 10:27 AM
  • This is a bug in Silverlight.  Sometimes XmlSerializer shows up in IntelliSense, and sometimes not.

     I don't know how to work around it.  I have two projects right now where these lines are recognized by one but not by the other:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Xml;
    using System.Xml.Serialization;
    using System.IO.IsolatedStorage;
    using System.Diagnostics;
     
     //  private XmlSerializer serializer; //not recognized by one but is by the other!

     

    UPDATE:  I found the workaround.  You must add this assembly dll to your assembly:  System.Xml.Serialization

     You find this using the procedure here: http://www.programmersheaven.com/2/FAQ-VISUALSTUDIO-Add-Assembly-Reference  (How do I add a reference to a .NET assembly in my project?   To add a reference to a .NET assembly, right click the ‘Reference’ option under the project inside the solution explorer and select the ‘Add Reference…’ option. It will show you a user interface screen where you browse for the target assembly. When you have selected the assembly, press the ‘Select’ button and then press OK. This will add a new reference node in the Reference sub tree of the project. By selecting the added reference node, you can edit its properties from the properties window.)

     

    Wednesday, August 26, 2009 6:50 PM
  • Hi,

    Just follow MarlServin Update...Worked for me.   

    Wednesday, January 13, 2010 1:58 AM