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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:58:58+00:00 2026-05-10T22:58:58+00:00

I created a separate assembly to contain common extension methods, the extension methods uses

  • 0

I created a separate assembly to contain common extension methods, the extension methods uses classes from System.Web.dll (and others).

When I then create a new project (Console Application) that references the Utilities.dll assembly that contains the extension methods, I do not need to add a reference to System.Web.dll to the new project if it does not use the extension methods that extends any class in the System.Web.dll assembly (for example System.Web.UI.Control).

When one of the extension methods will be a generic method everything continues to work as expected. But as soon as I add a constraint to the generic method that constraines it to a class in the System.Web.dll assembly the compiler will complain that my new project (Console Application) needs a reference to System.Web.dll even though the new project is still not using anything in that assembly.

In other words as long as I dont have a constraint on my generic methods everything compiles but as soon as I add a constraint the compiler complains.

An example of my extension methods assemble (compiled as a library Utilities.dll):

public static class StringExtensions {     public static bool IsNullOrEmpty(this string value)     {         return string.IsNullOrEmpty(value);     } }  public static class ControlExtensions {     // If I remove the where clause it compiles     public static T FildChild<T>(this Control parent, string id)         where T : Control     {         throw new NotImplementedException();     } } 

And here is a new console application that won't compile (unless I also add a reference to System.Web.dll):

    static void Main(string[] args)     {         bool isEmpty = 'Hello World!'.IsNullOrEmpty();          Console.ReadLine();     } 

Update: As Marc pointed out (below) puting the offending method in a separate namespace fixes the problem.

But the question still remains why is the constraint a problem while the type Control was already used as a parameter to the method. and why is the namespace the solution when I already use the using directive at the top.

  • 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. 2026-05-10T22:58:59+00:00Added an answer on May 10, 2026 at 10:58 pm

    well, yes! In order to compile, it needs to be able to resolve everything in the public/protected API. Otherwise it can’t enforce the constraint. I imagine it needs to recognise the types to see if the extension method is a candidate for a method.

    You could try placing the extension methods in a child namespace that has ‘Web’ in it – at least then it won’t spill into regular code. I’ve checked, and this fixes the issue. It is good practice to separate the namespaces of extension methods to allow the caller to control when they should be in scope.

    In order to execute, it would also need to be able to resolve anything used internally but not exposed in the API. This is standard behavior.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer (This is a Vista-specific solution; it only works when desktop… May 11, 2026 at 9:49 am
  • added an answer You should always have some way of exiting cleanly. I'd… May 11, 2026 at 9:49 am
  • added an answer First add a reference to WUApiLib 'C:\windows\system32\Wuapi.dll' Then you can… May 11, 2026 at 9:49 am

Related Questions

I created a separate assembly to contain common extension methods, the extension methods uses
I am wondering how to use NUnit correctly. First, I created a separate test
SHould I create a separate class for each object in an aggregate or should
I'm trying to create a bookmarklet for posting del.icio.us bookmarks to a separate account.
I have a method running in a seperate thread. The thread is created and
I have written a Windows service that spawns a separate process. This process creates
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
I created a few mediawiki custom tags, using the guide found here http://www.mediawiki.org/wiki/Manual:Tag_extensions I
I created a single page (with code behind .vb) and created Public intFileID As
I created a simple .NET windows application in Visual Studio 2005 and on just

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.