Assembly containing a given type

When exploring Dynamics AX 2012, I sometimes meet situations when I would like to know more about some CLR type (particularly to decompile it in ILSpy) and I need to know in which assembly it is contained.

It can be solved by the following X++ method, for instance:

public static void showContainingAssembly(str _typeName)
    System.AppDomain appDomain = System.AppDomain::get_CurrentDomain();
    System.Reflection.Assembly[] assemblies = appDomain.GetAssemblies();
    System.Reflection.Assembly assembly;
    int numOfAssemblies = assemblies.get_Count();
    int i;
    for (i = 0; i < numOfAssemblies; i++)
        assembly = assemblies.get_Item(i);
        if (assembly.GetType(_typeName, false, true) != null)
            info(strFmt("Assembly full name: %1", clr2XppStr(assembly.get_FullName())));
            info(strFmt("Assembly location: %1", clr2XppStr(assembly.get_Location())));

The method simply read all assemblies in the current application domain and tries to find the given type in every assembly. If the search is successful, assembly’s full name and physical location are displayed.

If you call the method for type Microsoft.Dynamics.AX.Framework.Services.Client.MetadataCache, for example, you get the following information:

Assembly full name: Microsoft.Dynamics.Framework.Metadata.AX, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Assembly location: C:\Windows\assembly\GAC_MSIL\Microsoft.Dynamics.Framework.Metadata.AX\\Microsoft.Dynamics.Framework.Metadata.AX.dll