Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8202597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:14:28+00:00 2026-06-07T07:14:28+00:00

When I try to add an extension method using the .NET 2.0 or 3.0

  • 0

When I try to add an extension method using the .NET 2.0 or 3.0 runtime, I get the error:

Cannot define a new extension method because the compiler required
type ‘System.Runtime.CompilerServices.ExtensionAttribute’ cannot be
found. Are you missing a reference to System.Core.dll?

But I can’t find System.Core in the list of available references when I try to add it to the project. What do I need to do to be able to use extension methods and in turn LINQ on in my projects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:14:29+00:00Added an answer on June 7, 2026 at 7:14 am

    Extension methods were not added to .NET until 3.5. However, it was not a change to the CLR, but a change to the compiler that added them, so you can still use them in your 2.0 and 3.0 projects! The only requirement is you must have a compiler that can create 3.5 projects to be able to do this workaround (Visual Studio 2008 and above).

    The error you get when you attempt to use an extension method is misleading as you do not truly need System.Core.dll to use extension methods. When you use a extension method, behind the scenes, the compiler is adding the [Extension] attribute to the function. If you have a compiler that understands what to do with the [Extension] attribute you can use it in your 2.0 and 3.0 projects if you create the attribute yourself.

    Just add the following class to your project and you can then start using extension methods:

    namespace System.Runtime.CompilerServices
    {
        [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
        public class ExtensionAttribute : Attribute
        {
        }
    }
    

    The above code block is sitting inside System.Core.Dll, so that is why the error says you need to include the DLL file to use them.


    Now if you want LINQ functionality that will take a little extra work. You will need to re-implement the extension methods yourself. To mimic the full LINQ to SQL functionality the code can get quite complicated. However, if you are just using LINQ to Objects most LINQ methods are not complicated to implement. Here are a few LINQ to Objects replacement functions from a project I wrote out to get you started.

    public static class LinqReplacement
    {
        public delegate TResult Func<T, TResult>(T arg);
        public delegate TResult Func<T1, T2, TResult>(T1 arg1, T2 arg2);
    
        public static TSource First<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
        {
            if (source == null)
                throw new ArgumentNullException("source");
            if (predicate == null)
                throw new ArgumentNullException("predicate");
    
            foreach (TSource item in source)
            {
                if (predicate(item) == true)
                    return item;
            }
    
            throw new InvalidOperationException("No item satisfied the predicate or the source collection was empty.");
        }
    
        public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source)
        {
            if (source == null)
                throw new ArgumentNullException("source");
    
            foreach (TSource item in source)
            {
                return item;
            }
    
            return default(TSource);
        }
    
        public static IEnumerable<TResult> Cast<TResult>(this IEnumerable source)
        {
            foreach (object item in source)
            {
                yield return (TResult)item;
            }
        }
    
        public static IEnumerable<TResult> SelectMany<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector)
        {
            if (source == null)
                throw new ArgumentNullException("source");
            if (selector == null)
                throw new ArgumentNullException("selector");
    
            foreach (TSource item in source)
            {
                foreach (TResult subItem in selector(item))
                {
                    yield return subItem;
                }
            }
        }
    
        public static int Count<TSource>(this IEnumerable<TSource> source)
        {
            var asCollection = source as ICollection;
            if(asCollection != null)
            {
                return asCollection.Count;
            }
    
            int count = 0;
            foreach (TSource item in source)
            {
                checked //If we are counting a larger than int.MaxValue enumerable this will cause a OverflowException to happen when the counter wraps around.
                {
                    count++;
                }
            }
            return count;
        }
    }
    

    A library with the full re-implemenation of LINQ to Objects with the ExtensionAttribute already added in can be found in the LinqBridge project (Thanks Allon Guralnek).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to add a class to a td-element using javascript with the internet
When I try to add struct in two-dimensional array cin>>array[1][items.stoka_ime]; in error list write
Getting this error when try to add an item to my repositories/context: Collection has
I try to add a record to SQLServer db table using LINQ to SQL
When I try to use any extension method to my class in ascx-control: <%@
i try to add facebook like button on my root domain that will like
I try to add the android coverflow in my own android projet when myt
I try to add dots between the page title and the page number in
I try to add Message.framework to my project frameworks directory. After that I compile
I try to add a class to a link with jquery <a rel=/Career/ href=/Career/></a>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.