Get executing assembly name using reflection

前端 未结 5 1067
清酒与你
清酒与你 2020-12-19 09:00

I am trying to pull the project name using the reflection, but during the substring method it give me \"index out of bound error\".

string s = System.Reflec         


        
5条回答
  •  误落风尘
    2020-12-19 09:35

    I would try accessing the AssemblyTitle Attribute in your AssemblyInfo file. Location of any assembly may not be the same as the project name. Try this:

    Assembly a = Assembly.GetEntryAssembly();
    AssemblyTitleAttribute titleAttr = (AssemblyTitleAttribute)  a.GetCustomAttributes(typeof(AssemblyTitlenAttribute), false)[0];
    Console.WriteLine("Title: " + titleAttr.Title);
    

    hth

提交回复
热议问题