title: C#, WinForms and Extension Methods
body: <p><strong>The Question</strong></p>
  
  <p>Aside from all the obvious answers, what would cause extension methods to generate compiler errors like this one:</p>
  
  <p><em>'DataType' does not contain a definition for 'YourExtensionMethodName'</em></p>
  
  <p>I've got a real stumper here, and it's spelled out for you in detail below. I've exhausted all the possible causes I can think of.</p>
  
  <p><strong>Scenario</strong></p>
  
  <ul>
  <li>I have a couple of extension methods defined in various static classes in a DLL that is consumed by a WinForms application.</li>
  <li>The extension method signatures do not conflict with the signatures of methods on the class I'm extending (<code>String</code>, in this case).</li>
  <li>Both the DLL and the WinForms application are written in C#. </li>
  <li>Both the DLL and the WinForms application are configured to target .NET 3.5.</li>
  <li>The consuming classes include a reference to the namespace that defines the extension method. Its spelling has been verified.</li>
  <li>If I reference the extension class directly, the extension methods appear. For example, if I type <code>StringExtensions.</code>, Intellisense appears as normal, with all of my extension methods listed.</li>
  <li><strong>EDIT</strong>: The errors are occurring in the WinForms application, but only for <em>some</em> of the extension methods, not all of them.</li>
  </ul>
  
  <p><strong>The Code (Or an Excerpt Thereof)</strong></p>
  
  <p>(Yep, this is the offending code)</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace Roswell.Framework
  {
      public static class StringBuilderExtensions
      {
          public static string ToSentenceCase(this string value)
          {
              return value.Substring(0, 1).ToUpper() + value.Substring(1).ToLower();
          }
  
          public static string ToTitleCase(this string value)
          {
              string[] parts = value.Split(new string[] {" "}, StringSplitOptions.None);
              System.Text.StringBuilder builder = new System.Text.StringBuilder();
              foreach (string part in parts)
              {
  
                  builder.Append(part.ToSentenceCase());
                  builder.Append(" ");
              }
              return builder.ToString();
          }
  
      }
  }
  </code></pre>
  
  <p>And this is the code that consumes it:</p>
  
  <pre><code>using Roswell.Framework;
  
  namespace Roswell.Windows.Command
  {
      /// &lt;summary&gt;
      /// Views the SQL for an object in the database window.
      /// &lt;/summary&gt;
      internal class ViewObjectDdlCommand
          : MainWindowCommand
      {
  
          public override void Execute()
          {
             // ...
  
             OpenCodeWindow(
                 string.Format("{0} - {1} - {2}", 
                               dsn.Name, 
                               objectName, 
                               info.ToTitleCase()),
                  schemaItemType,
                  objectName);
           }
      }
  }
  </code></pre>