Assembly Display Names


An assembly display name should include the assembly simple name, version, culture and public key token. The assembly simple name is usually the file name of the assembly without the extension (“.dll” or “.exe”).


For example, the assembly display name for the v1.0 system.dll assembly is:


System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089


All of those components are required to be specified in calls to Assembly.Load() if the assembly is to be found in the GAC (and I strongly recommend that you always specify them, even if the assembly is not in the GAC).


My plea: please don’t put together these names yourself. Allow Fusion to create them for you so that they will be canonicalized and work with upcoming (and past) versions of Fusion. If you need to get one programmatically, try Assembly.FullName, AssemblyName.FullName, or Type.AssemblyQualifiedName. If you just need to cut-and-paste one into your code, “gacutil /l” is a quick way to get the official string. If you just need the public key/token, try “sn -Tp”.

Comments (32)

  1. Linda Dai says:

    It is great to read your blogs. It is very informational! Thanks for your effort.

    Could you please say something more about canonicalizing process in Fusion?

    Thanks,
    –L.

  2. Suzanne says:

    Thanks! What exactly would you like to know about the canonicalizing process? Mscorlib.dll’s APIs that return an assembly display name should all give the official, canonicalized one. Basically, Fusion pastes together the different components in the official, ‘good’ way, filtering out inappropriate stuff.

  3. Dave says:

    Is there a method that will take as arguments the difrerent components of an assembly name and return the displayname? And is there one that will do the inverse operation? This will help in handling AssemblyResolve events where we want to change one or more components of the assembly display name to a different form of it (e.g. changing a version number or culture).

    Thanks. And keep blogging

    Dave

  4. Dave says:

    Is there a method that will take as arguments the difrerent components of an assembly name and return the displayname? And is there one that will do the inverse operation? This will help in handling AssemblyResolve events where we want to change one or more components of the assembly display name to a different form of it (e.g. changing a version number or culture).

    Thanks. And keep blogging

    Dave

  5. Suzanne says:

    Yes, set those properties on an AssemblyName object, and then get its FullName property. Going the other direction is supported starting in v2.0 – the AssemblyName(String) constructor takes an assembly display name, and then the resulting AssemblyName will have the parsed properties.

  6. Mark says:

    In .NET 1.0, in which scenarios will Assembly.FullName return a string that doesn’t contain version, culture, or publicKeyToken?

  7. Suzanne says:

    In v1.0, there was a race condition where the full string may not have been set, if multiple threads were asking for the same assembly’s display name at the same time, if it had not been requested before. (The first thread would get the full string, while threads losing the race may get a string missing one or more of the public key token, culture and version.) This has been fixed in v1.0 SP3, and v1.1 or later.

  8. anand mathew says:

    I am trying to use the function Assembly.gettype. But my system does not show any such function. Please let me know what is hapening.

  9. Suzanne says:

    It’s System.Reflection.Assembly.GetType() in mscorlib.dll, and these are the different overloads, below. See MSDN for more info.

    Type GetType(String name)

    Type GetType(String name, bool throwOnError)

    Type GetType(String name, bool throwOnError, bool ignoreCase)

    Type GetType()

  10. dirk says:

    Sorry Suzanne,

    I think the whole assembly concept of .NET sucks. I spend hours trying to load a stupid assembly after I have completed all the hard work in coding it. I just keep getting Exceptions concerning security access (after having given the ASP.NET User full access to the relevent directory). In the end I give up and write elaborate switch statements because I cannot run Type.GetType(classname) successfully.

    This just messes up the whole point of Reflection. Why make security so complex that programmers spend more time trying to evade it than dealing with it, because it is so confusing?

    Windows and .NET security derail the joy of coding with .NET. They are such a headache!

  11. Nicole says:

    hi i love u

  12. Daniel Moldovan says:

    I’m generating an assembly using CSharpCodeProvider compile method. I use in my code, in another project (not using reflection) Types from this generated assembly. In this second project I’m loading the generated assembly unsing Assembly.Load(byte[] bytes) method. But when the code want to load Types from this assembly .net tries to load again the generated assembly from the file system. Why? This assembly is already loaded by the previous call to Assembly.Load(). Can anybody help me?

    Thanks,

    Daniel

  13. An unmanaged dll can be wrapped in a managed assembly by adding it as a file of a multi-module assembly.

  14. Calling Load(AssemblyName) is not necessarily the same as calling Load(String). If the AssemblyName.CodeBase

  15. Pre-v2, when you load an assembly by path through Fusion (LoadFrom(), ExecuteAssembly(), etc.), it can

  16. By "Frameworks assemblies," I mean the assemblies that ship with the CLR. But, I’m not counting mscorlib.dll

  17. There are two types of assembly identity that the loader deals with: bind-time and after bind-time. The

  18. So, after checking out the binding context options , you’ve decided to switch your app to use the Load

  19. A partial bind is when only part of the assembly display name is given when loading an assembly. Assembly.LoadWithPartialName()

  20. If no assembly is specified, Type.GetType() will only look in the calling assembly and then mscorlib.dll

  21. Kevin Burton says:

    I have an assembly call it MyAssembly.dll. In it there is a type under the namespace MyCompany.Service.MyServices that is MyService. What is the full CLR type name for this type?

    Thank you.

    Kevin

  22. Ishtiaque Hussain says:

    Is there any way (SomeMethod) I can find an assembly’s fully qualified name from just it’s name given as a string?

    Let me explain my question with an example:

    string DisplayName = "Microsoft.Msagl";

    string FullyQualifiedName = SomeMethod (DisplayName);

    and FullyQualifiedName would hold:

    "Microsoft.Msagl,Version=1.2.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"

    Thanks in advance.

  23. Ishtiaque Hussain says:

    Hi everyone,

    Thanks for posting my feedback. I got a solution to my problem and sharing with you:

    The following code actually finds the fully qualified name, if the file location is provided:

    Assembly asm = Assembly.LoadFrom("C:\Program Files\Microsoft Pex\bin\Microsoft.Msagl.dll");

               Dataflow.BasicBlock("Microsoft.Msagl.Anchor," + asm.FullName.ToString());

    The Assembly "asm.FullName" gives the fully qualified name. (Ignore Dataflow.BasicBlock: this some library that I was working on)

    I got this helpful piece code from:

    http://www.hanselman.com/blog/OutputAnAssemblyVersionFullyQualifiedNameFromTheCommandLine.aspx

    Thanks.

    –Ishtiaque