Click here to Skip to main content
12,942,930 members (48,873 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


9 bookmarked
Posted 25 Mar 2012

Get all Assembly Information

, 27 Mar 2012 CDDL
Rate this:
Please Sign up or sign in to vote.
This tip shows how to get quickly all Information of an Assembly


With assembly attributes it is possible to specify assembly meta information such as product title or version, either automatically by Visual Studio (see here for more information) or manually by editing the file "AssemblyInfo.cs" in the project folder "Properties".

With the class provided with this tip these attributes can be easily read from any assembly.

To obtain information of an assembly the constructor of AssemblyInfo can be used by passing the specific assembly.

If the corresponding assembly attribute to a property is not found, <code>null will be returned.


This example will write all assembly information of the entry assembly to the console.

AssemblyInfo entryAssemblyInfo = new AssemblyInfo(Assembly.GetEntryAssembly());
Console.WriteLine("Company: " + entryAssemblyInfo.Company);
Console.WriteLine("Copyright: " + entryAssemblyInfo.Copyright);
Console.WriteLine("Description: " + entryAssemblyInfo.Description);
Console.WriteLine("Product: " + entryAssemblyInfo.Product);
Console.WriteLine("ProductTitle: " + entryAssemblyInfo.ProductTitle);
Console.WriteLine("Version: " + entryAssemblyInfo.Version);

The Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace HdSystemLibrary.Reflection
    public class AssemblyInfo
        public AssemblyInfo(Assembly assembly)
            if (assembly == null)
                throw new ArgumentNullException("assembly");
            this.assembly = assembly;

        private readonly Assembly assembly;

        /// <summary>
        /// Gets the title property
        /// </summary>
        public string ProductTitle
                return GetAttributeValue<AssemblyTitleAttribute>(a => a.Title, 

        /// <summary>
        /// Gets the application's version
        /// </summary>
        public string Version
                string result = string.Empty;
                Version version = assembly.GetName().Version;
                if (version != null)
                    return version.ToString();
                    return "";

        /// <summary>
        /// Gets the description about the application.
        /// </summary>
        public string Description
            get { return GetAttributeValue<AssemblyDescriptionAttribute>(a => a.Description); }

        /// <summary>
        ///  Gets the product's full name.
        /// </summary>
        public string Product
            get { return GetAttributeValue<AssemblyProductAttribute>(a => a.Product); }

        /// <summary>
        /// Gets the copyright information for the product.
        /// </summary>
        public string Copyright
            get { return GetAttributeValue<AssemblyCopyrightAttribute>(a => a.Copyright); }

        /// <summary>
        /// Gets the company information for the product.
        /// </summary>
        public string Company
            get { return GetAttributeValue<AssemblyCompanyAttribute>(a => a.Company); }

        protected string GetAttributeValue<TAttr>(Func<TAttr, 
          string> resolveFunc, string defaultResult = null) where TAttr : Attribute
            object[] attributes = assembly.GetCustomAttributes(typeof(TAttr), false);
            if (attributes.Length > 0)
                return resolveFunc((TAttr)attributes[0]);
                return defaultResult;


This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


About the Author

Henning Dieterichs
Germany Germany
Presently I am a student of computer science at the Karlsruhe Institute of Technology in Germany.

You may also be interested in...


Comments and Discussions

QuestionRegarding full workspace Pin
Member 114944793-Mar-15 2:01
memberMember 114944793-Mar-15 2:01 
Suggestionnamespace screwed up, remove the static members... Pin
Andreas Gieriet25-Mar-12 17:17
memberAndreas Gieriet25-Mar-12 17:17 
I find it in general interesting, but in my opinion, you screwed up some parts:
- never introduce any custom class into a system namespece (as you do with System.Reflection)
--> change to something like namespace MyCompany.MyPackage.MyFunction;
- don't provide static functions when it is not really needed
--> these function have certainly no performance impact, i.e. are not used where speed matters
--> don't cache the entry assembly nor the calling assembly
--> discard the static methods/properties and always use an instance of the class to get the items
The maintainer of the code will thank you!

GeneralRe: namespace screwed up, remove the static members... Pin
Henning Dieterichs25-Mar-12 20:50
memberHenning Dieterichs25-Mar-12 20:50 
GeneralRe: namespace screwed up, remove the static members... Pin
Andreas Gieriet25-Mar-12 21:43
memberAndreas Gieriet25-Mar-12 21:43 
GeneralRe: namespace screwed up, remove the static members... Pin
Henning Dieterichs27-Mar-12 5:18
memberHenning Dieterichs27-Mar-12 5:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170518.1 | Last Updated 27 Mar 2012
Article Copyright 2012 by Henning Dieterichs
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid