Attribute::GetCustomAttribute Method (Module, Type, Boolean)

Retrieves a custom attribute applied to a module. Parameters specify the module, the type of the custom attribute to search for, and an ignored search option.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

static Attribute^ GetCustomAttribute(
	Module^ element, 
	Type^ attributeType, 
	bool inherit


Type: System.Reflection::Module

An object derived from the Module class that describes a portable executable file.

Type: System::Type

The type, or a base type, of the custom attribute to search for.

Type: System::Boolean

This parameter is ignored, and does not affect the operation of this method.

Return Value

Type: System::Attribute
A reference to the single custom attribute of type attributeType that is applied to element, or nullptr if there is no such attribute.


element or attributeType is nullptr.


attributeType is not derived from Attribute.


More than one of the requested attributes was found.

The following code example illustrates the use of the GetCustomAttribute method taking a Module as a parameter.

using namespace System;
using namespace System::Diagnostics;

// Add the Debuggable attribute to the module.
namespace IsDef2CS
   ref class DemoClass
      static void Main()

         // Get the class type to access its metadata.
         Type^ clsType = DemoClass::typeid;

         // See if the Debuggable attribute is defined for this module. 
         bool isDef = Attribute::IsDefined( clsType->Module, DebuggableAttribute::typeid );

         // Display the result.
         Console::WriteLine( "The Debuggable attribute {0} " 
         "defined for Module {1}.", isDef ? (String^)"is" : "is not", clsType->Module->Name );

         // If the attribute is defined, display the JIT settings. 
         if ( isDef )

            // Retrieve the attribute itself.
            DebuggableAttribute^ dbgAttr = dynamic_cast<DebuggableAttribute^>(Attribute::GetCustomAttribute( clsType->Module, DebuggableAttribute::typeid ));
            if ( dbgAttr != nullptr )
               Console::WriteLine( "JITTrackingEnabled is {0}.", dbgAttr->IsJITTrackingEnabled );
               Console::WriteLine( "JITOptimizerDisabled is {0}.", dbgAttr->IsJITOptimizerDisabled );
                        Console::WriteLine( "The Debuggable attribute " 
            "could not be retrieved." );



 * Output:
 * The Debuggable attribute is defined for Module IsDef2CS.exe.
 * JITTrackingEnabled is True.
 * JITOptimizerDisabled is False.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft