/moduleassemblyname (Specify Friend Assembly for Module)
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

/moduleassemblyname (Specify Friend Assembly for Module) (C# Compiler Option) 

Specifies an assembly whose non-public types a .netmodule can access.



The name of the assembly whose non-public types the .netmodule can access.

/moduleassemblyname should be used when building a .netmodule, and where the following conditions are true:

  • The .netmodule needs access to non-public types in an existing assembly.

  • You know the name of the assembly into which the .netmodule will be built.

  • The existing assembly has granted friend assembly access to the assembly into which the .netmodule will be built.

For more information on building a .netmodule, see /target:module (Create Module to Add to Assembly) (C# Compiler Options).

For more information on friend assemblies, see Friend Assemblies (C# Programming Guide).

This option is not available from within the development environment; it is only available when compiling from the command line.

This compiler option is unavailable in Visual Studio and cannot be changed programmatically.

This sample builds an assembly with a private type, and that gives friend assembly access to an assembly called csman_an_assembly.

// moduleassemblyname_1.cs
// compile with: /target:library
using System;
using System.Runtime.CompilerServices;

[assembly:InternalsVisibleTo ("csman_an_assembly")]

class An_Internal_Class 
    public void Test() 
        Console.WriteLine("An_Internal_Class.Test called"); 

This sample builds a .netmodule that accesses a non-public type in the assembly moduleassemblyname_1.dll. By knowing that this .netmodule will be built into an assembly called csman_an_assembly, we can specify /moduleassemblyname, allowing the .netmodule to access non-public types in an assembly that has granted friend assembly access to csman_an_assembly.

// moduleassemblyname_2.cs
// compile with: /moduleassemblyname:csman_an_assembly /target:module /reference:moduleassemblyname_1.dll
class B {
    public void Test() {
        An_Internal_Class x = new An_Internal_Class();

This code sample builds the assembly csman_an_assembly, referencing the previously-built assembly and .netmodule.

// csman_an_assembly.cs
// compile with: /addmodule:moduleassemblyname_2.netmodule /reference:moduleassemblyname_1.dll
class A {
    public static void Main() {
        B bb = new B();


An_Internal_Class.Test called
© 2016 Microsoft