TechyMedia

A .NET Technology blog | .NET,C# Progamming,C# tutorials,WPF WCF|Software Engineer

NAVIGATION - SEARCH

Friend Assembly In C#, InternalsVisibeTo attribute

If you need one assembly to access non public types defined in another assembly and even though physically separated as two assemblies for some logical reasons you can make the first assembly as the friend of the second assembly.Then the second assembly can access all the non public types of the first assembly.

If you need one assembly to access non public  types defined in another assembly and even though physically separated as two assemblies for some logical reasons you can make the first assembly as the friend of the second assembly.Then the second assembly can access all the non public types of the first assembly.

.Net namespace System.Runtime.CompilerService provides an attribute

assembly: InternalsVisibleTo  for making an assembly friend to other. 

The syntax of the attribute is

[assembly: InternalsVisibleTo("AssemblyName, PublicKeyToken= #############")]

 

Here AssemblyName is the name of the assembly to be marked as friend and public key token is that assembly's key token which is a guid.

 

#Pragma Warning Control

Pingbacks and trackbacks (1)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading