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 8601859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:56:32+00:00 2026-06-12T01:56:32+00:00

I created the Class1.GetChild<T>() where T : DependencyObject extension method in lib1.dll assembly. After

  • 0

I created the Class1.GetChild<T>() where T : DependencyObject extension method in lib1.dll assembly. After that, all assemblies that depends on lib1.dll failed to compile with error:

The type ‘System.Windows.DependencyObject’ is defined in an assemebly
that is not referenced. You must add a reference to assembly
‘WindowsBase’ etc…

Why dependent assemblies requires WindowsBase even if they don’t use GetChild?

.

To reproduce (vs2010 .net4):

lib1.dll (references WindowsBase)

namespace lib1
{
    public static class Class1
    {
        public static T GetChild<T>(this DependencyObject src) where T : DependencyObject
        {
            return default(T);
        }
    }

    public static class Class2
    {
        public static int SomeExtMethod(this string src)
        {
            return 0;
        }
    }
}

lib2.dll (references lib1 but not WindowsBase)

using lib1;
class someClass
{
    void someFct()
    {
        "foo".SomeExtMethod(); // error: The type 'System.Windows.DependencyObject'
                // is defined in an assemebly that is not referenced. 
                // You must add a reference to assembly 'WindowsBase' etc..
    }
}

.

Update:

I think there’s definitly something when mixing generic methods and extension methods. I tried to demonstrate the issue in the following sample:

// lib0.dll
namespace lib0
{
    public class Class0 { }
}

// lib1.dll
using lib0;
namespace lib1
{
    public static class Class1
    {
        public static void methodA<T>() where T : Class0 { }    // A
        public static void methodB(Class0 e) { }                // B
        public static void methodC(this int src) { }            // C
    }

    public static class Class2
    {
        public static void methodD(this String s) { }
    }
}

// lib2.dll
using lib1;
class someClass
{
    void someFct()
    {
        Class2.methodD("");  // always compile successfully
        "".methodD();        // raise the 'must add reference to lib0' error depending on config. see details below.
    }
}

A, //B, //C -> compile ok

A, B, //C -> compile ok

//A, B, C -> compile ok

A, //B, C -> raise error

A, B, C -> raise error

//A means methodA is commented. As Damien pointed out, type inference might play some role. Still curious to know the ins and outs.

  • 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-12T01:56:33+00:00Added an answer on June 12, 2026 at 1:56 am

    Your situation has been answered by Microsoft here:
    https://connect.microsoft.com/VisualStudio/feedback/details/668498/problem-with-extension-method-in-c-compiler

    There are other use-cases as well independent of extension methods which produce this error wrongly.

    Consider this:

    1. Define a generic method in a type, say TP1, defined in library say LB1.
    2. Type constrain the generic method on some type defined in some other library LB2.
    3. Define another method in TP1.
    4. Now in your library reference only LB1 and try to call the second method of type TP1

    If you don’t use TP1 but some other type defined in LB1, you do not get the error.
    Also, even if one of the method of type TP1 expects a parameter of the type defined in LB2 (and you do not call this method) it does not produce this error

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

Sidebar

Related Questions

Out of curiosity, I've created 2 assemblies which both have a class ( Class1
I have an application that uses (has referenced) a class library (myLib.dll private assembly).
I have created a simple Google chrome extension that overrides CSS classes using the
I have created a class called Class1, and in another module, I want to
I've created class that takes Exception type in constructor private readonly Exception _exception; public
I created a class that extends DefaultMutableTreeNode. It has a variable, resource of the
I created a class that's something like this: public class MovieTheaterList { public DateTime
I created a class CMyClass whose CTor takes a UCHAR as argument. That argument
I created a class that handles serial port asynchronously. I use it to communicate
i created a method in a new library this is my code namespace ClassLibrary1

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.