How can I retrieve an assembly’s qualified type name?

How can I generate a assembly qualified type name?

For an example, when configuring a membership provider, I would have to provide a assembly qualified type name for “SqlMembershipProvider” (in this example, i have copied the below configuration from somewhere) in “type” attribute.

How do you generate that assembly qualified type name?
Does it have to be typed manually everytime by examining an assembly type?

<membership>
  <providers>
    <clear />
    <add name="AspNetSqlMembershipProvider"
           type="System.Web.Security.SqlMembershipProvider,
           System.Web, Version=2.0.0.0,
           Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
           connectionStringName="LocalSqlServer"/>
  </providers>
</membership>

[UPDATE]: Simpler PowerShell version

PS>([System.String]).AssemblyQualifiedName
System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

This is a nice handy tool (shell extension with source code) for copying the fully qualified name to clipboard by right clicking on any assembly.

Update: After seeing the comment from dance2die, thought of putting together a sample powershell script to export the type name to a csv file.

> [System.Reflection.Assembly]::LoadWithPartialName("System.Web")

> [System.Web.Security.SqlMembershipProvider] | select {$_.UnderlyingSystemType.AssemblyQualifiedName } | export-csv c:typenames.csv

Using C#, if you want to generate the assembly qualified type name with all the references set, it is easy to build a test script using reflection..

using System;
using System.Reflection;
........

Type ty = typeof(System.Web.Security.SqlMembershipProvider);
string fullname = ty.AssemblyQualifiedName;
//"System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

Method 2

The easiest way to find that information is to use Reflector, load the assembly, and copy the Name out of the assembly’s manifest. The manifest information will be in the bottom pane of Reflector when your assembly is selected in the window above.

Method 3

ok just use it like Gulzar Nazim wrote

$ String typeName = typeof(AssemblyName.ClassName).AssemblyQualifiedName);

that give you the full name you can use it in type.getType();
That works with me and no null any more

Method 4

AFAIK the Fully qualified type name consists in the Class name and the assembly signature.
I don’t think that you can generate it…

The type is the namespace.

The version you can set it in the AssemblyInfo.cs (remove the * for keep it the same)

The public key token you set it in the Project properties.

That’s from what i remember

other way to obtain the assembly qualified name could be:

class Program
    {
        static void Main(string[] args)
        {
            string assemblyPath = args[0];
            Assembly loadedAssembly = Assembly.LoadFrom(assemblyPath);
            Module[] modules = loadedAssembly.GetModules();
            Console.WriteLine("Assembly: " + loadedAssembly.GetType().Name);
            foreach (Module module in modules)
            {
                Console.WriteLine("Module: {0}nFullyQualifiedName: {1}", module.Name, module.FullyQualifiedName);
                Type[] types = module.GetTypes();
                foreach (Type type in types)
                {
                Console.WriteLine("Type: {0}n FullName: {1}", type.Name, type.FullName);    
                }
            }
            Console.ReadLine();
        }
    }

Method 5

use add type in your command :

add-type -assemblyname "system.example"


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x