Search code examples
c#assembliesinternal

Accessing a method defined as `internal` by a FriendAssembly



I have a method declared with internal static in one of my classes and i would like to expose this method to another class in a particular assembly can anybody help me with this please?


Solution

  • In your AssemblyInfo.cs file in the assembly that contains your internal method, use the following line:

    [assembly: InternalsVisibleTo("OtherAssemblyName")]
    

    If you receive the following error...

    Friend assembly reference 'OtherAssemblyName' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.

    Then see the modification here: How to declare a friend assembly?

    This, however, will give your other assembly visibility into all of your internals in your original assembly. You can't just expose one internal to a friend assembly.