Thursday, February 3, 2011

Import Namespace System.Query

I am trying to load Linq on my .Net 3.5 enabled web server by adding the following to my .aspx page:

<%@ Import Namespace="System.Query" %>

However, this fails and tells me it cannot find the namespace.

The type or namespace name 'Query' does not exist in the namespace 'System'

I have also tried with no luck:

  • System.Data.Linq
  • System.Linq
  • System.Xml.Linq

I believe that .Net 3.5 is working because var hello = "Hello World" seems to work.

Can anyone help please?

Cheers, Stephen

PS: I just want to clarify that I don't use Visual Studio, I simple have a Text Editor and write my code directly into .aspx files.

  • The var hello stuff is compiler magic and will work without Linq.

    Try adding a reference to System.Core


    Sorry, I wasn't clear. I meant add System.Core to the web project's references, not to the page.

    The Import on the page are basically just using statements, allowing you to skip the namespace on the page.

    From Keith
  • Hi Keith, adding:

    <%@ Import Namespace="System.Core" %>
    

    failed to work and showed the same error message :(

    Any other idea's?

    From GateKiller
  • Make sure your project is set to target 3.5, and not 2.0.

    As others have said, your 'var' test is a test of C#3 (i.e. VS2008), not the 3.5 framework.

    If you set the project framework target settings properly, you should not expect to need to manually add dll references at this point.

    From Will Dean
  • Hi Will,

    I'm not using VS. Is there any other way I can confirm if 3.5 is installed correctly?

    From GateKiller
  • Updated original question.

    From GateKiller
  • What version of the framework have you selected on the ASP.NET tab in IIS?

    From Will Dean
  • <%@ Import Namespace="System.Core" %>

    failed to work and showed the same error message :(

    Keith was talking about adding a DLL reference, rather than another import. To be honest, I would suggest you start with Visual Studio (one of the free versions), as it will finesse this sort of stuff for you until you're a bit more up-to-speed with .NET development.

    From Will Dean
  • What version of the framework have you selected on the ASP.NET tab in IIS?

    I have version 2 selected in IIS and I have the following in my web.config:

    <system.codedom>
     <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
       type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
       <providerOption name="CompilerVersion" value="v3.5"/>
       <providerOption name="WarnAsError" value="false"/>
      </compiler>
     </compilers>
    </system.codedom>
    

    Help :(

    From GateKiller
  • I have version 2 selected in IIS and I

    Well, surely that's your problem? Select 3.5.

    Actually, here's the real info:

    http://www.hanselman.com/blog/HowToSetAnIISApplicationOrAppPoolToUseASPNET35RatherThan20.aspx

    From Will Dean
  • @Will, Yup, I have gone through those step. Like I said, I believe 3.5 is working because the syntax

    var string = "hello";
    

    works because this is a new feature of .Net 3.5.

    I'm completely at a loss now.

    PS: Thanks for your help though :)

    From GateKiller
  • var string = "hello";

    works because this is a new feature of .Net 3.5.

    As at least two people have already tried to tell you in here, this is NOT A FEATURE OF .NET 3.5

    It's a feature of C#3, which is the version of the language supported by the compiler that comes with VS2008.

    I find it hard to believe you've read and comprehended that Hanselman article, which seems to cover exactly what you're trying to do.

    From Will Dean
  • What does the part of your web.config file look like?

    Here's what it looks like for a brand new ASP.NET 3.5 project made with Visual Studio 2008:

    <assemblies>
      <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    </assemblies>
    
  • I found the answer :) I needed to add the following to my web.config:

    <assemblies>  
        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
        <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    </assemblies>
    

    Then I could add the following to my code:

    <%@ Import Namespace="System.Linq" %>
    

    @Will,

    Thanks for your help. I have accepted one of your answers :)

    From GateKiller
  • The csproj file might be missing the System.Core reference. Look for a line in the csproj file like this:

    <Reference Include="System" />
    

    And add a line below it like this:

    <Reference Include="System.Core" />
    
    From aboy021

0 comments:

Post a Comment