vb.net.net-3.5smart-device

Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable


My class gives me an error:

Error 4 Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.

I searched similar questions and found out it may be problem with imports/references. However, I think I imported everything I need and it still gives me the error.

The class and project references are below:

references

Imports System.Data.SqlClient
Imports System.Collections
Imports System.Data
Imports System
Imports System.Xml
Imports System.Xml.Linq


Public Class Form1

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Dim Result As Integer
    Dim mxldDataParams As System.Xml.Linq.XDocument = XDocument.Load("mypath\myxml.xml")


    Private Function GetProcedureName(ByVal Name As String) As String
        Dim Result As String = String.Empty
        'this line gives the error
        Dim Elems As System.Collections.Generic.IEnumerable(Of XElement) = From Elem As XElement In mxldDataParams.Root.Elements Where Elem.Name.LocalName = "data" And Elem.@name = Name
        For Each Elem As XElement In Elems
            Result = Elem...<target>...<remote>...<source>.@name
            Exit For
        Next
        Return Result
    End Function


End Class

Solution

  • You don't have an import for System.Linq, which means the compiler can't find LINQ to Objects, which is the LINQ implementation you're trying to use.

    Just add this to your imports:

    Imports System.Linq
    

    LINQ to XML isn't really a LINQ provider - it's just an XML API which also works well with LINQ to Objects.