title: Friend Assemblies in C#
body: <p>I'm trying to create some 'friend assemblies' using the [InternalsVisibleTo()] attribute, but I can't seem to get it working. I've followed Microsoft's instructions for <a href="http://msdn.microsoft.com/en-us/library/bb385180.aspx" rel="noreferrer">creating signed friend assemblies</a> and I can't see where I'm going wrong. So I'll detail my steps here and hopefully someone can spot my deliberate mistake...?</p>
  
  <p>Create a strong name key and extract the public key, thus:</p>
  
  <blockquote>
    <p>sn -k StrongNameKey<br>
    sn -p public.pk<br>
    sn -tp public.pk  </p>
  </blockquote>
  
  <p>Add the strong name key to each project and enable signing.  </p>
  
  <p>Create a project called <strong>Internals</strong> and a class with an internal property:</p>
  
  <pre><code>namespace Internals
  {
      internal class ClassWithInternals
      {
          internal string Message { get; set; }
          public ClassWithInternals(string m)
          {
              Message = m;
          }
      }
  }
  </code></pre>
  
  <p>Create another project called TestInternalsVisibleTo:  </p>
  
  <pre><code>namespace TestInternalsVisibleTo
  {
      using Internals;
  
      static class Program
      {
          /// &lt;summary&gt;
          /// The main entry point for the application.
          /// &lt;/summary&gt;
          [STAThread]
          static void Main()
          {
              var c = new Internals.ClassWithInternals("Test");
              Console.WriteLine(c.Message);
          }
      }
  }
  </code></pre>
  
  <p>Edit the AssemblyInfo.cs file for the Internals project, and add teh necessary attribute:  </p>
  
  <pre><code>[assembly: AssemblyTitle("AssemblyWithInternals")]
  [assembly: AssemblyDescription("")]
  [assembly: AssemblyConfiguration("")]
  [assembly: AssemblyCompany("Microsoft")]
  [assembly: AssemblyProduct("Internals")]
  [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
  [assembly: AssemblyTrademark("")]
  [assembly: AssemblyCulture("")]
  [assembly: ComVisible(false)]
  [assembly: Guid("41c590dc-f555-48bc-8a94-10c0e7adfd9b")]
  
  [assembly: AssemblyVersion("1.0.0.0")]
  [assembly: AssemblyFileVersion("1.0.0.0")]
  
  [assembly: InternalsVisibleTo("TestInternalsVisibleTo PublicKey=002400000480000094000000060200000024000052534131000400000100010087953126637ab27cb375fa917c35b23502c2994bb860cc2582d39912b73740d6b56912c169e4a702bedb471a859a33acbc8b79e1f103667e5075ad17dffda58988ceaf764613bd56fc8f909f43a1b177172bc4143c96cf987274873626abb650550977dcad1bb9bfa255056bb8d0a2ec5d35d6f8cb0a6065ec0639550c2334b9")]
  </code></pre>
  
  <p>And finally... build!  </p>
  
  <p>I get the following errors:  </p>
  
  <blockquote>
    <p>error CS0122: 'Internals.ClassWithInternals' is inaccessible due to its protection level<br>
    error CS1729: 'Internals.ClassWithInternals' does not contain a constructor that takes 1   arguments
    error CS1061: 'Internals.ClassWithInternals' does not contain a definition for 'Message' and no extension method 'Message' accepting a first argument of type 'Internals.ClassWithInternals' could be found (are you missing a using directive or an assembly reference?)  </p>
  </blockquote>
  
  <p>Basically, it's as if I had not used the InternalsVisibleTo attrbute. Now, I'm not going to fall into the trap of blaming the tools, so what's up here? Anyone?</p>