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

  • SEARCH
  • Home
  • 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 799033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:03:48+00:00 2026-05-14T23:03:48+00:00

I have: Main Program Class – uses Library A Library A – has partial

  • 0

I have:

  • Main Program Class – uses Library A
  • Library A – has partial classes which mix in methods from Library B
  • Library B – mix in methods & interfaces

Why would I need a using statement to LibaryB just to get their extension methods working in the main class? That is given that it’s Library B that defines the classes that will be extended.

EDIT – Except from code

    // *** PROGRAM ***
    using TopologyDAL;
    using Topology;  // *** THIS WAS NEEDED TO GET EXTN METHODS APPEARING ***
    class Program
    {
        static void Main(string[] args)
        {
            var context = new Model1Container();
            Node myNode;  // ** trying to get myNode mixin methods to appear seems to need using line to point to Library B ***
         }
     }


// ** LIBRARY A
namespace TopologyDAL
{
    public partial class Node
    {
        // Auto generated from EF
    }

    public partial class Node : INode<int>   // to add extension methods from Library B
    {
        public int Key
    }
}

// ** LIBRARY B
namespace ToplogyLibrary
{
    public static class NodeExtns
    {
        public static void FromNodeMixin<T>(this INode<T> node) {
           // XXXX
        }
    }
    public interface INode<T> 
    {
        // Properties
        T Key { get; }

        // Methods
    }

}

  • 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-05-14T23:03:48+00:00Added an answer on May 14, 2026 at 11:03 pm

    This is an unfortunate discoverability issue with extension methods. In order to make them available you need to add a using statement for the namespace containing the static class that has the extensions. Check out this blog about extension methods.

    Here is some background on extension methods:

    So how is the compiler to know which
    extension method to bind? The compiler
    looks for extension methods in the
    innermost namespace when the call is
    made for extension methods and then in
    all the namespaces imported by the
    “using” clause. This process is
    followed moving outward until we reach
    the topmost namespace.

    Since extension methods can be
    imported in to the current context by
    the “using” clause and bound to any
    object which is assignable(see
    convertibility section for details) to
    the instance parameter, all sorts of
    interesting possibilities open up for
    extending the methods implemented by a
    type. This can simply be done by
    importing a library of extension
    methods and using these methods as if
    they were declared on a type that you
    don’t own. This means that

    1. Depending on the library you import the code can be made to do different
      things.

    2. The client gets an interesting way to extend a type that he does not own.

    My understanding is that using extension methods is just like using any other type, except that you can’t qualify them (that is just syntactically impossible), hence the need for using statement. Since you can define multiple of them in different classes in different namespaces, the compiler needs a way to resolve ambiguity.

    I envisage that in future Visual Studio will add a feature to import the right namespace when you type in the method name, in a similar way it does so for class and interface names.

    Consider this scenario:

    namespace FruityNamespace {
      public static class FruityExtensions {
        public static string ToFunString(this int value) {return value + " bananas"; }
      }
    }
    
    namespace VegetablNamespace {
      public static class VegetablyExtensions {
        public static string ToFunString(this int value) {return value + " carrots"; }
      }
    }
    
    //In some other source file
    static void Main(/**/) {
      int things = 3;
      3.ToFunString(); //error CS1061: 'System.Int' does not contain a definition for 'ToFunString' and no extension method 'ToFunString' accepting a first argument of type 'System.Int' could be found (are you missing a using directive or an assembly reference?)
    }
    

    In order to use any of those extension methods you need to import the right namespace:

    using FruityNamespace;
    //OR
    using VegetablyNamespace;
    

    You might ask what happens when you import both namespaces. You get a compiler error just like this:

    error CS0121: The call is ambiguous between the following methods or properties: 'VegetablNamespace.VegetablyExtensions.ToFunString(int)' and 'FruityNamespace.FruityExtensions.ToFunString(int)'
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 388k
  • Answers 388k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Most user pleasing IMO would be instant feedback via the… May 15, 2026 at 12:21 am
  • Editorial Team
    Editorial Team added an answer Got it! FilteredTermEnum subclasses (FuzzyTermEnum, RegexTermEnum, WildcardTermEnum) do exactly what… May 15, 2026 at 12:21 am
  • Editorial Team
    Editorial Team added an answer Integrated mode means that the pipeline events of ASP.NET run… May 15, 2026 at 12:21 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.