4

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.

6 Answers 6

5

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

Sign up to request clarification or add additional context in comments.

Comments

2

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>

Comments

2

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

Comments

1

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.

3 Comments

Hi Will, I'm not using VS. Is there any other way I can confirm if 3.5 is installed correctly?
What version of the framework have you selected on the ASP.NET tab in IIS?
I have version 2 selected in IIS and my web.config shows Version=2.0.0.0. Help :(
0

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.

4 Comments

Hi Keith, adding: <%@ Import Namespace="System.Core" %> failed to work and showed the same error message :( Any other ideas?
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.
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 :)
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.
0

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" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.