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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:57:04+00:00 2026-05-18T00:57:04+00:00

This is a question about Extension Method visibility in .Net (specifically C#), and why

  • 0

This is a question about Extension Method visibility in .Net (specifically C#), and why intellisense may work, but the compiler fail on the same piece of code.

Picture this…

I have .Net 3.5 class library consisting of a bunch of objects and a single Extension Methods class. Here is one of the methods:

namespace MyApp.Extensions
{
    public static class ExtensionMethods
    {
        public static string ToTitleCase(this string Origcase)
        {   string TitleCase = Origcase;
            ... implementation ...
            return TitleCase;
        }
    }

To use the extension methods within the class library itself, each class that requires one of the methods needs to specify:

using MyApp.Extensions;

Since that is a different namespace than the rest of the library. All of that works fine.

Now, a .Net 2.0 web site properly references this library, and a class file wishes to use the library. So it declares that it is:

using MyApp.Extensions

That SEEMS to work just fine, and when typing a string, Intellisense does see the extension method dangling off a string instance:

http://www.flipscript.com/test/ToTitleCase.jpg

I love it when a plan comes together!

However, that’s the end of the joy.

When attempting to Build the web site, the build fails with the following message:

http://www.flipscript.com/test/titlecaseerror.jpg

When attempting to directly copy the ExtensionMethods class into the web project, the build again fails. This time, because the word “this” was not expected.

Oddly enough, the extension method does work as a normal static method:

http://www.flipscript.com/test/titlecaseok.jpg

…and the Build works just fine (so the problem is NOT actually with the “this” keyword). In fact, the build works whether the ExtensionMethods class is in the class library or the web site.

In other words, this does solve the problem, and the build will succeed.

…but the solution sucks.

Question: Is there some sort of secret trick to get Extension Methods to work correctly in this scenario?

http://www.flipscript.com/test/ToTitleCase.jpg

I’ve tried the “namespace System.Runtime.CompilerServices” trick, but that didn’t seem to help.

What would cause Intellisense to see an extension method correctly, and the compiler to fail?

Note: The contrived example variable should have been called ‘name’ instead of ‘FirstName’, but you get the idea.

  • 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-18T00:57:04+00:00Added an answer on May 18, 2026 at 12:57 am

    In web.config, try adding to the system.web/pages/namespaces node

    <system.web>
        ....
        <pages ....>
            ....
            <namespaces>
                ....
                <add namespace="MyApp.Extensions" />
    

    You will also need to ensure that the ASP.NET compiler is in 3.5 mode:

    <system.codedom>
      <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
                  type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <providerOption name="CompilerVersion" value="v3.5"/>
          <providerOption name="WarnAsError" value="false"/>
        </compiler>
     </compilers>
    </system.codedom>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently asked this question: Compiler error referencing custom C# extension method Marc Gravell
I have a question about this question . I posted a reply there but
This question is about a Java JTree or a Window .Net Tree (Winforms) or
This question is a follow up to my previous question about getting the HTML
I was reading this question about how to parse URLs out of web pages
I just came across this question about initializing local variables. Many of the answers
As kind of a follow up to this question about prefixes , I agree
This question is about removing sequences from an array, not duplicates in the strict
This question is about organizing the actual CSS directives themselves within a .css file.
This question is about App domains and Sessions. Is it possible to have IIS

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.