xinghua
xinghua

Reputation: 149

c# assembly, friend assembly

The definition for C# internal access modifier is internal: Accessible only within containing assembly or friend assemblies. So my question is what is c# assembly? what does it mean to be within containing assembly or friend assemblies? Does it mean within same namespace or project?

Upvotes: 3

Views: 7652

Answers (4)

Orhan Cinar
Orhan Cinar

Reputation: 8428

The assembly contains the intermediate code, resources, and the metadata for itself. We can have a look inside the assembly using the ildasm (Intermediate Language Disassembler) tool that comes as part of Visual Studio. To access it you need to open the Visual Studio Command Prompt and type ildasm.exe. This will launch a Windows application that you can use to explore any .Net application.

A friend assembly is an assembly that can access another assembly's Friend (Visual Basic) or internal (C#) types and members. If you identify an assembly as a friend assembly, you no longer have to mark types and members as public in order for them to be accessed by other assemblies. This is especially convenient in the following scenarios:

  • During unit testing, when test code runs in a separate assembly but requires access to members in the assembly being tested that are marked as Friend (Visual Basic) or internal (C#).

  • When you are developing a class library and additions to the library are contained in separate assemblies but require access to members in existing assemblies that are marked as Friend (Visual Basic) or internal (C#).

Upvotes: 1

Tigran
Tigran

Reputation: 62248

The assembly is IL code with manifest information (in case of .NET), which can be DLL or EXE. In this way, using a manifest information, one assembly can be declared as a friend of another one, so access internal dataypes too.

By using attribute [assembly: InternalsVisibleTo..] you mark into the manifest of the assembly specified information,

Upvotes: 2

to StackOverflow
to StackOverflow

Reputation: 124696

You define it using the InteralsVisibleToAttribute.

Upvotes: 2

SLaks
SLaks

Reputation: 887225

An assembly is (in general) a single .dll or .exe file.
A C# project (in general) compiles to a single assembly.

You can mark a friend assembly using the [assembly: InternalsVisibleTo(...)] attribute.

Upvotes: 9

Related Questions