16

I am getting the name of an assembly as follows:

String fullName = Assembly.GetAssembly(typeof(CP.Proj.ILogger)).FullName;

And I get the following:

CP.Proj, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Is there a way to get only the assembly name "CP.Proj", without the version and other infos?

giammin
  • 18,620
  • 8
  • 71
  • 89
Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
  • 1
    Did you look at the return type of [`Assembly.GetAssembly()`](http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getassembly(v=vs.110).aspx) and the [available properties and methods of that type](http://msdn.microsoft.com/en-us/library/system.reflection.assembly(v=vs.110).aspx)? – CodeCaster Nov 06 '13 at 11:20
  • `typeof(CP.Proj.ILogger).ToString();` – Shahin Dohan Apr 19 '19 at 13:01

2 Answers2

42

You need to get the AssemblyName object of that assembly through the Assembly.GetName() method

Assembly.GetAssembly(typeof(CP.Proj.ILogger)).GetName().Name

If the assembly is the one which is calling that method you can use:

string name = Assembly.GetCallingAssembly().GetName().Name;

or even create an utility method

public static string GetAssemblyShortName()
{
    return Assembly.GetCallingAssembly().GetName().Name;
}
giammin
  • 18,620
  • 8
  • 71
  • 89
5

Try this ,

**1**
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name


**2**
typeof(Program).Assembly.GetName().Name;
zey
  • 5,939
  • 14
  • 56
  • 110