Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
A friend assembly, in C#, refers to the .NET assembly that can access the members of another assembly. Members in an assembly that are accessed from friend assembly need to be marked as
Friend assemblies are used in scenarios where there is a need to access internal classes and members in one assembly from another specific assembly. It enables two specific assemblies to share members or functionality without making them public.
Friend assemblies are also used in unit testing where the assembly underlying the test code needs to access the members which are marked as internal in the assembly to be tested. It is useful in development of class libraries that require additions contained in separate assemblies which need to access members in existing assemblies.
By marking members of a class as internal, they are visible to other classes within the same assembly but are private for classes that reside outside the assembly. To access the internal members from a friend assembly, name of friend assembly should be specified with the attribute, InternalsVisibleToAttribute in the assembly where the internal members are defined. Friend assembly cannot access private types and private members.
For example, InternalsVisibleToAttribute in Assembly X can be used to specify Assembly Y as friend assembly, so that Assembly Y can access all types and members of Assembly X that are marked as internal.
Following are the guidelines related to development of friend assemblies: