none
How to solve Error CS1935 IEnumerable<XElement> RRS feed

  • Question

  • I try to load xml and get certain data

    Here is my config.xml content

    <CONFIG xmlns:xdi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" FrameWidth="400" FrameHeight="200">
     <Frames>
        <FRAME FrameName="Frame0">
          <Frame_Elements>
            <Frame_Element><!--Frame_Element[0]-->
              <Basic><!--Basic[0]-->
                <Id>0</Id>
                <Uid>0</Uid>
              </Basic>
              <Base><!--Base[0]-->
                <BaseFilePath>C:/Image</BaseFilePath>
                <BaseFileName>f.png</BaseFileName>
              </Base>
            </Frame_Element>
            <Frame_Element><!--Frame_Element[1]-->
              <Basic><!--Basic[1]-->
                <Id>1</Id>
                <Uid>0</Uid>
              </Basic>
              <Base><!--Base[1]-->
                <BaseFilePath>C:/Image</BaseFilePath>
                <BaseFileName>large.png</BaseFileName>
              </Base>
            </Frame_Element>
            <Frame_Element><!--Frame_Element[2]-->
              <Basic><!--Basic[2]-->
                <Id>2</Id>
                <Uid>0</Uid>
              </Basic>
              <Base><!--Base[2]-->
                <BaseFilePath>C:/Image</BaseFilePath>
                <BaseFileName>medium.png</BaseFileName>
              </Base>
            </Frame_Element>
            <Frame_Element><!--Frame_Element[0]-->
              <Basic><!--Basic[3]-->
                <Id>3</Id>
                <Uid>0</Uid>
              </Basic>
              <Base><!--Base[3]-->
                <BaseFilePath>C:/Image</BaseFilePath>
                <BaseFileName>small.png</BaseFileName>
              </Base>
            </Frame_Element>
          </Frame_Elements>
        </FRAME>
        <FRAME FrameName="Frame1">
          <Frame_Elements>
            <Frame_Element><!--Frame_Element[4]-->
              <Basic><!--Basic[4]-->
                <Id>4</Id>
                <Uid>0</Uid>
              </Basic>
              <Base><!--Base[4]-->
                <BaseFilePath>C:/Image</BaseFilePath>
                <BaseFileName>Main.png</BaseFileName>
              </Base>
            </Frame_Element>
            <Frame_Element><!--Frame_Element[5]-->
              <Basic><!--Basic[5]-->
                <Id>5</Id>
                <Uid>0</Uid>
              </Basic>
              <Base><!--Base[5]-->
                <BaseFilePath>C:/Image</BaseFilePath>
                <BaseFileName>icon.png</BaseFileName>
              </Base>
            </Frame_Element>
          </Frame_Elements>
        </FRAME>
    </CONFIG>    

    I try to get  Frame0  Frame1

    So use below code to get

    XElement config = XElement.Load(filePath);
                    IEnumerable<XElement> frame = from element in config.Elements("FRAME")
                                                  where element.Attribute("FrameName")
                                                  select element;

    I include

    using System.Xml.Linq;
    using System.Collections.Generic;


    But I get error 

    Severity Code Description Project File Line Suppression State
    Error CS1935 Could not find an implementation of the query pattern for source type 'IEnumerable<XElement>'.  'Where' not found.  Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'? C:\OpenXML.cs 19 Active

    How to solve this?

    Thanks


    • Edited by CY_Chen Friday, September 27, 2019 2:21 AM
    Friday, September 27, 2019 2:19 AM

Answers

  • Hi 

    Thanks for the feedback.

    You could try the following code to get Frame0 Frame1.

    XElement config = XElement.Load(@"D:\test.xml");
                var frame = from element in config.Descendants("FRAME")
                            where element.Attribute("FrameName").Value!=null
                            select element.Attribute("FrameName").Value;

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by CY_Chen Friday, September 27, 2019 3:32 AM
    Friday, September 27, 2019 3:24 AM
    Moderator

All replies

  • Hi CY_Chen,

    Thank you for posting here.

    You could add the following bold using code to solve the problem you got.

    using System.Collections.Generic;
    using System.Linq;
    using System.Xml.Linq;

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 27, 2019 3:05 AM
    Moderator
  • Hi Jack 

    Thanks for answering

    I try your method it solve element in config.Elements("FRAME")

    But it error move to element.Attribute("FrameName")

    Like below image

     How to solve those ?

    Thanks

    Friday, September 27, 2019 3:13 AM
  • Hi 

    Thanks for the feedback.

    You could try the following code to get Frame0 Frame1.

    XElement config = XElement.Load(@"D:\test.xml");
                var frame = from element in config.Descendants("FRAME")
                            where element.Attribute("FrameName").Value!=null
                            select element.Attribute("FrameName").Value;

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by CY_Chen Friday, September 27, 2019 3:32 AM
    Friday, September 27, 2019 3:24 AM
    Moderator