LINQ query works in console app but not web app. Why?

Last post 07-18-2008 12:28 PM by Jeev. 3 replies.

Sort Posts:

  • LINQ query works in console app but not web app. Why?

    07-18-2008, 10:51 AM
    • Member
      10 point Member
    • SeanW122
    • Member since 05-10-2006, 3:59 PM
    • Posts 7

    I have the following code that works in a console app. I copied exactly and pasted into my web app as a function inside a class object.  Inside the web app it gives two errors.  One is saying that System.XML.Linq.XElement is not queryable.   The other is saying that "item1" is not declared.   Both apps have the System.XML and System.XML.Linq references set.   What am I missing?  Thanks.

     Public Function GetSetting() As String

    Dim _xml As XDocument = XDocument.Load("C:\appsettings.xml")

    Dim foo = From item In _xml.<appSettings>.<add> _

    Where item.@Key = "OrderNotice" _

    Select item.@Key, item.@Value

    Dim bar As String = String.EmptyFor Each item1 In foo

    bar = item1.Value

    Console.WriteLine(bar)

    Next

    Return bar

    End Function

    Filed under:
  • Re: LINQ query works in console app but not web app. Why?

    07-18-2008, 11:30 AM
    • All-Star
      20,998 point All-Star
    • Jeev
    • Member since 11-24-2005, 7:49 AM
    • Posts 3,163
    System.core should also be added to the list of references. Also I see a potential problem with security and also console.Write doesn't work in the web environment
    Jeev
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If you get the answer to your question, please mark it as the answer.
  • Re: LINQ query works in console app but not web app. Why?

    07-18-2008, 11:37 AM
    • Member
      10 point Member
    • SeanW122
    • Member since 05-10-2006, 3:59 PM
    • Posts 7

    True that the Console call doesn't need to be there;

     I added System.Core to my references and it did not help.  I tried adding Imports System.Core but it doesn't see it.

    I added Imports System.LINQ and the first error went away.  What is the difference between System.XML.LINQ and System.LINQ?  Shouldn't I stick with System.XML.LINQ?

     

     

    Thanks,

  • Re: LINQ query works in console app but not web app. Why?

    07-18-2008, 12:28 PM
    • All-Star
      20,998 point All-Star
    • Jeev
    • Member since 11-24-2005, 7:49 AM
    • Posts 3,163

    SeanW122:
    What is the difference between System.XML.LINQ and System.LINQ?  Shouldn't I stick with System.XML.LINQ?
     

    system.linq has the bulk of the linq to object implementation where as System.xml.linq has the LINQ to XML implementation

    Jeev
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If you get the answer to your question, please mark it as the answer.
Page 1 of 1 (4 items)