3

has anyone been able to use Linqbridge on a .Net 2.0 Website? I have no problem using it in a normal .Net 2.0 console, but when I use the methods in the website, I get

Feature 'extension method' cannot be used because it is not part of the ISO-2 C# language specification
C_Rance
  • 661
  • 12
  • 25
  • *Where* in the website? code-behind? aspx? something else? – Mauricio Scheffer Mar 17 '11 at 04:40
  • @Mauricio, when you create a new project, there is an option to choose new website. Use that. Just a newly created website with no codes will do too. Add in LinqBridge as reference and do some calling with Linq, it will reproduce the same error as I get – C_Rance Mar 18 '11 at 01:02
  • @C_Rance: weird, I'd expect something like that to happen in an aspx... but not on compiled code. Is that a compile-time error or runtime error? – Mauricio Scheffer Mar 18 '11 at 02:05
  • @Mauricio: luckily its compile time, so after I compile the website, all the errors start showing. In terms of intellisense, it worked fine, problem shows when you build it or assign it to variables – C_Rance Mar 18 '11 at 02:57
  • what version of Visual Studio are you using? – Mauricio Scheffer Mar 18 '11 at 03:25
  • using VS 2010, so I believe this would actually be a better option. Correct me if im wrong – C_Rance Mar 18 '11 at 04:06

2 Answers2

2

I think the error message is pretty clear. Extension methods aren't supported in 2.0. If you want to use an extension method in 2.0, you'd need to modify it by removing the this and call it explicitly.

If you had:

public static class ExtensionMethods {
    public static bool IsOdd(this int x) {
        return x % 2 != 0;
    }
}

Then ExtensionMethods and code like number.IsOdd() won't compile.

You'd need to remove the this in the IsOdd method signature and call it as ExtensionMethods.IsOdd(number) to get it to work under 2.0.

If I recall correctly, that's the approach the authors of LinqBridge used.

Hope that helps.

neontapir
  • 4,698
  • 3
  • 37
  • 52
  • so u mean I have to use the code file and manually edit their method signature? – C_Rance Mar 17 '11 at 09:54
  • Yes. I suspect that the extension method exists in some copied code from somewhere else. It should not be in the LinqBridge code, since it's written for .NET 2.0. – neontapir Mar 17 '11 at 13:36
  • 1
    I edited the .cs file, and tried to remove all the this, but it give me some other compiler issue. Guess some of the methods they use will still require "this". Any idea how to remove the ISO standard instead? A normal console application is working fine, but not a website. Voted u up for trying to help – C_Rance Mar 18 '11 at 01:00
  • Thank you for the upvote. I'm not sure what ISO standard would apply to this situation. Would you happen to have a reference to the System.Core 3.5 DLL instead of the 2.0 one? – neontapir Mar 18 '11 at 03:07
  • U're welcome. I have not tried referencing a 3.5 DLL but I believe after referencing, I do not even require LinqBridge, as Linq is dependent on this reference if Im not wrong. The problem is that my user's standard requires .Net 2.0, I've more experience with LINQ so ended up wasted alot of time using 2.0 as Im not as familar – C_Rance Mar 18 '11 at 04:05
  • True, if you can reference System.Core 3.5, then you can just use LINQ. But if you reference the 3.5 DLL and compile as 2.0, you might see errors like this. You'll want to look at DLLs referenced in the web.config also, since it's only happening on the web site. – neontapir Mar 18 '11 at 04:37
0

Maybe you're confusing .NET and C# versions. LINQBridge supports .NET 2.0, but you still need C# 3.0 or later (i.e. VS2008 or later) to compile code with extension method or LINQ syntax sugar. Once compiled, the assembly runs without issue on .NET 2.0 runtimes. That's the benefit of LINQBridge.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • actually if that's the case, I will already have no problem. The 1st try that I did was to download the LinqBridge dll from their site and add reference to it. Like I mention, I have tested on a .Net 2.0 console application and it is working fine. But doing the same way on a website project fails me. So the dll download from linqbridge does include the extension method – C_Rance Mar 18 '11 at 04:01