Question

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?

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

Was it helpful?

Solution

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

OTHER TIPS

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 :)

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.

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.

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" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top