views:

729

answers:

10

EDITED WITH ANSWER

I have been able to prove that you can in fact get LINQ to work running on a 2.0 sp1 server. It will not work at all without at least 2.0 SP1. But all you need is to include the following assemblies in your project.

System.Core.dll System.Data.DataExtensions.dll System.Data.Linq.dll System.Web.Extensions.dll System.Xml.Linq.dll

+1  A: 

You're not going to be able to run code targetted to 3.5 on the server unless you get 3.5 installed on it.

The problem isn't your code, rather that the required libraries will be missing.

Mark Pattison
+7  A: 

You are right in that 3.5 runs on the 2.0 CLR, but 3.5 contains libraries and if you have used any of those, you're out of luck unless you install 3.5 on that server.

There are plenty of options for a 3.5 program to not run correctly on only 2.0, so I'd consider downgrading the program, or upgrading the server.


Note regarding copy local. Even if you copy all the 3.5 libraries that your app uses, there is no guarantee it'll work and most likely it won't. Even so, distributing the libraries with your app is expressively prohibited by the .NET license.

Since you have stated you use LINQ, the only legal way to get your app running is to install the 3.5 license.

Or, you can rewrite your app using only 2.0.

Lasse V. Karlsen
Thanks for noting that "distributing the libraries with your app is expressively prohibited by the .NET license".
Lucas
A: 

This is not possible. Although the CLR has not changed (like it did between v1.1 and v2.0) The libraries have. You cannot run a 3.5 app that doesn't have the 3.5 fraework installed. All of the Linq features are made possible by the 3.5 framework.

Micah
+2  A: 

I'm pretty sure that LINQ is one of the things that makes 3.5 a requirement. A lot of the other things, like lambda expressions etc. are just compiler trickery.

Because System.Linq is a 3.5 feature, the framework is required to be that version.

A good way to determine would be to change the target framework to 2.0 and see if it builds.

Carl
A: 

One error is in Web.Config. The published Web.Config is setup to allow compilation from .NET 3.5, which is the reason it includes build provider information.

Beyond that, your code won't run. By using LINQ, you're referencing assemblies that don't exist in .NET 2.0.

Joseph Daigle
A: 

This is why I always keep away from new Microsoft technologies until they become very ubiquitous. LINQ sounds nice but it's too cutting edge and will probably be replaced by something else in the near future.

Vincent
So when do you give up on waiting? When LINQ gets replaced, will you start using it?
Robert S.
A: 

You can just copy over the 3.5 dlls onto the server. You can absolutely run 3.5 code on a 2.0 server.

Mike Fielden
As lassevk mentioned, this is expressly prohibited by the .NET license. Also you might need at least 2.0 SP1.
Lucas
A: 

You can may use of some C# 3 features whilst targeting .NET 2.0. Its the language features which by the time its compilied to IL will run on the 2.0 CLR regardless of whether that CLR is part of a 2.0 or higher framework install.

Hence you can use anonymous types, extension methods and Lambda expressions but as soon as you do things like LINQ you then need external libraries that are part of 3.5

If you are only doing LINQ to Object you could add the LINQBridge to your distribution.

Another problem you can run into is if you are shipping a web application that includes the source code, such as code behind files, in line code and .cs in the App_Code folder.

You can end up shipping C# source code which compiles on the developement machine with C# 3 compilier present but fails to compile on a server only equiped with C# 2. In this case you can't use any new language features either.

What's worse is that specifing the .NET 2.0 framework as the target in the Visual Studio doesn't stop you using C# 3 language features. You get no warnings that such syntax will not compile on a 2.0 machine.

Hence if you are shipping such a web app, you'll need to compile pretty much everything first.

AnthonyWJones
A: 

I was just going to leave a comment by my rep is not quite there. I agree with the crowd so far and believe that lassevk's answer is the best so please give him the rep for that. One this I wanted you to know about though is that once you install 3.5 on your IIS server (6 or better). When you go to the IIS Manager and right click on your website to access the ASP.Net tab. You will see AFTER the install of the 3.5 Framework that there is no 3.5 option available. It will still show it as 2.0.50727. Don't worry about that, it will still work just fine. Because of this inconsistence (thanks Microsoft) some confusion has been caused. Actually I think this is why you may have thought that 2.0 would run your 3.5 code just fine. Hope this helps and anyone please edit this so it makes more sense.

Matt
+2  A: 

Code compiled against 3.0 or 3.5 may run on the 2.0 framework, but only if you do not use any libraries that are specific to the 3.0+ framework. One good way to find what's causing your code to fail is to switch your target to 2.0 and change things so that it compiles. Since one of your target installations is .NET 2.0, you are going to have to write .NET 2.0 code; this is not unique to .NET. In the past, writing an application that executed in both Win95 and WinNT involved extra work for the developer to carefully make sure the appropriate API was used.

Technically, 3.5-targetted code can run on 2.0 with no problems, but there's some gotchas you have to watch for. If anything accesses something that is unavailable in .NET 2.0, that will fail. This doesn't happen when the application starts, it happens when the application tries to make the call. I tested this by making a console application that does a little bit of output, then tries to display a WPF window. The output is made, but the application throws an exception when it tries to display the window on a machine with nothing but .NET 2.0.

Another gotcha is that VS 2008 actually comes with the .NET Framework 2.0 SP1, and there are a few types and methods in SP1 that are not in the normal 2.0 Framework. Visual Studio will not flag these methods as unsafe.

Finally, if this is a web application, the default web.config file for 3.5-targeted projects is very different than the web.config file for 2.0-targeted projects. Make sure you're distributing a compatible web.config. This is likely the problem you are encountering. A cheap workaround might be to change your target to .NET 2.0, copy that web.config, and use it in this case. Keep in mind that if you are using any 3.0+-specific language features or types your code will still fail, but this should get you past the web.config.

OwenP