Cisco CloudCenter: Get the Hybrid IT Advantage

Friend Assembly

Definition - What does Friend Assembly mean?

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.

Techopedia explains Friend Assembly

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:

  • While using signed assemblies , the tool, ‘sn.exe’ can be used to get the public key that has to be passed to the attribute specifying friend assembly
  • While compiling a friend assembly that accesses internal members of another assembly, the compiler option (/out) has to be set with the name of the output file (.exe or .dll)
  • It is necessary to explicitly specify every assembly that needs to be friend for the assembly to which it needs access
  • It is suggested to use friend assemblies without breaking the rules of encapsulation
This definition was written in the context of C#
Share this:

Connect with us

Email Newsletter

Join thousands of others with our weekly newsletter

The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.