0

I cannot deserialize string I get from chartlyrics.com. I get the result from there by next line of code:

string xml = await HttpClient.GetStringAsync("http://api.chartlyrics.com/apiv1.asmx/SearchLyric?artist="+Artist+"&song="+Song);

So far so good... But when I try to deserialize it occurs problems. During process I get error

System.Runtime.InteropServices.WindowsRuntime.RuntimeClass is inaccessible due to its protection level. Only public types can be processed.

My classes are following:

    [Serializable]
    public class SearchLyricResultCollection
    {
        [XmlArray("ArrayOfSearchLyricResult")]
        [XmlArrayItem("SearchLyricResult")]
        public List<SearchLyricResult> ListOfTracks;
    }
    [Serializable]
    public class SearchLyricResult
    {
        [XmlElement(ElementName = "TrackId")]
        public string TrackId;
        [XmlElement(ElementName = "LyricChecksum")]
        public string LyricChecksum;
        [XmlElement(ElementName = "LyricId")]
        public string LyricId;
        [XmlElement(ElementName = "SongUrl")]
        public string SongUrl;
        [XmlElement(ElementName = "ArtistUrl")]
        public string ArtistUrl;
        [XmlElement(ElementName = "Artist")]
        public string Artist;
        [XmlElement(ElementName = "Song")]
        public string Song;
        [XmlElement(ElementName = "SongRank")]
        public string SongRank;
    }

and I try to serialize using next code:

        //Crash just here...
        XmlSerializer serializer = new XmlSerializer(typeof(SearchLyricResultCollection));
        //Cannot continue up here...
        using (TextReader reader = new StringReader(xml))
        {
            var result = (SearchLyricResultCollection)serializer.Deserialize(reader);
        }

So, how to fix this problem?

Selim Yildiz
  • 5,254
  • 6
  • 18
  • 28
Weissu
  • 409
  • 3
  • 15

1 Answers1

1

Your problem is that SearchLyricResultCollection is probably inside the other class which is not public. So if you update that as public it should solve your problem.

See: Public Class - "is inaccessible due to its protection level. Only public types can be processed."

Selim Yildiz
  • 5,254
  • 6
  • 18
  • 28