Does LINQ work in Orcas?

S

subtle

I've installed Orcas beta1 March 2007 CTP. I get compiler errors on
any LINQ related code. For example:

List<string> cities = new List<string>();
cities.Add("London");
cities.Add("Paris");
cities.Add("Las Vegas");
var holdit = from city in cities
where city.Length > 4
select city.ToUpper();

That throws a bunch of "; expected" compiler errors. Intellisense in
there for the LINQ keywords but not for .ToUpper() or .Length. Has
anyone been able to use LINQ with the latest Orcas?
 
D

David R. Longnecker

Subtle-

That code works like a champ in Orcas B1. To start, is the project you're
working with set to .NET 3.5?

When you add a new project, in the upper right corner of the "Add New Project"
box, you can select your .NET version. Be sure you're set to 3.5 and not
3.0 or 2.0. Multi-targeting is a nice feature, but you've got to be sure
to choose the right one.

For an existing project, I'm not quite sure a GUI way to look, but if you
look in a project's config file, you'll see:

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

I've just assumed that the v3.5 was what registered those libraries for 3.5,
though verification would be nice from someone who actually knows. On a
class project or "non-web" project, you can go into the properties of the
project and use the "Target Framework" dropdown to choose.

The last question, the only other thing that comes to mind: Are you using
ReSharper? Unfortunately, ReSharper does not currently support LINQ or .NET
3.5 features and they will cause ReSharper to have a fit when you build.

HTH.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com

s> I've installed Orcas beta1 March 2007 CTP. I get compiler errors on
s> any LINQ related code. For example:
s>
s> List<string> cities = new List<string>();
s> cities.Add("London");
s> cities.Add("Paris");
s> cities.Add("Las Vegas");
s> var holdit = from city in cities
s> where city.Length > 4
s> select city.ToUpper();
s> That throws a bunch of "; expected" compiler errors. Intellisense in
s> there for the LINQ keywords but not for .ToUpper() or .Length. Has
s> anyone been able to use LINQ with the latest Orcas?
s>
 
N

Nicholas Paldino [.NET/C# MVP]

In addition to what other people said, you have to have the following
statement at the top of your code to work:

using System.Linq;

If you don't, the compiler will not know how to resolve the extension
methods that are added to IEnumerable<T> (which the query syntax is
dependent on).
 
S

subtle

I was targeting 3.0. I'll try 3.5. I seems though that LINQ doesn't
work for a website project. I opened a downloaded console project
Linq example and it works. The System.Linq namespace is there and
seen by intellisense.

Unfortunately, if I try to create any other type of project, I get
this error:

Requested registry access is not allowed.

I did try a repair but no difference. Here's a similar post:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1712083&SiteID=1

I don't think I'm using ReSharper by the way.

Thanks on the suggestions.
 
N

Nicholas Paldino [.NET/C# MVP]

You have to use 3.5 for LINQ code. The .NET framework 3.0 is for the
most part, has the same C# compiler that's in .NET 2.0, neither of which has
what is necessary to compile LINQ expressions.
 
B

Ben Voigt [C++ MVP]

Nicholas Paldino said:
You have to use 3.5 for LINQ code. The .NET framework 3.0 is for the
most part, has the same C# compiler that's in .NET 2.0, neither of which
has what is necessary to compile LINQ expressions.

I thought Orcas generated downlevel code by passing options to the new C#
compiler, not by invoking the old one. Or no?
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

subtle said:
I was targeting 3.0. I'll try 3.5. I seems though that LINQ doesn't
work for a website project. I opened a downloaded console project
Linq example and it works. The System.Linq namespace is there and
seen by intellisense.

Unfortunately, if I try to create any other type of project, I get
this error:

Requested registry access is not allowed.

I did try a repair but no difference. Here's a similar post:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1712083&SiteID=1

I don't think I'm using ReSharper by the way.

Thanks on the suggestions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top