C# 如何从DLL中检索程序集信息

C# 如何从DLL中检索程序集信息,c#,asp.net,.net,dll,C#,Asp.net,.net,Dll,我有一个ASP.Net asmx网站服务,在Properties文件夹中有一个AssemblyInfo.cs。我无法访问该文件中的信息 我的假设是我应该可以打电话 Assembly.GetExecutingAssembly(); 然后从该文件中获取信息,但是我得到了一些其他程序集。 为了解决这个问题,我将程序集属性从该文件移到了Global.asax.cs页面。完成此操作后,调用上面的行将返回预期值 一,。我必须这样做吗?还是我只是看了一些关于AssemblyInfo.cs文件的内容 此网站还

我有一个ASP.Net asmx网站服务,在Properties文件夹中有一个AssemblyInfo.cs。我无法访问该文件中的信息

我的假设是我应该可以打电话

Assembly.GetExecutingAssembly();
然后从该文件中获取信息,但是我得到了一些其他程序集。 为了解决这个问题,我将程序集属性从该文件移到了Global.asax.cs页面。完成此操作后,调用上面的行将返回预期值

一,。我必须这样做吗?还是我只是看了一些关于AssemblyInfo.cs文件的内容

此网站还有一个DLL,它试图使用来自同一AssemblyInfo.cs的信息。我不知道如何从DLL中获取所需的信息

Assembly.GetEntryAssembly() = null
Assembly.GetCallingAssembly() = mscorlib
Assembly.GetExecutingAssembly() = DLL Assembly
二,。如何获取站点的装配信息

}

在Logger.Init内部,它启动一个线程,其中一个循环读取队列

var guid = ((GuidAttribute)Assembly.GetExecutingAssembly.GetCustomAttributes(typeof(GuidAttribute), true)[0]).Value;
这将返回DLL的GUID,这不是我想要的。

这适用于我:

web应用程序中的AssemblyInfo.cs

[assembly: Guid("df21ba1d-f3a6-420c-8882-92f51cc31ae1")]
Global.asax.cs

public class Global : HttpApplication
{
    void Application_Start(object sender, EventArgs e)
    {
        Logger.Init();
        string assemblyName = Logger.AssemblyGuid; // to test under debug
    }
}
WebService1.asmx.cs

namespace WebApplicationSO2
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld() {
            Assembly a = Assembly.GetExecutingAssembly();
            var attribute = (GuidAttribute)a.GetCustomAttributes(typeof(GuidAttribute), true)[0];
            var guidFromDll = Logger.AssemblyGuid;
            return "My Guid: " + attribute.Value + " Guid from Dll: " + guidFromDll; // returns 'My Guid: df21ba1d-f3a6-420c-8882-92f51cc31ae1 Guid from Dll: df21ba1d-f3a6-420c-8882-92f51cc31ae1'

        }
     }
}
动态链接库:

namespace WebApplicationSO2
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld() {
            Assembly a = Assembly.GetExecutingAssembly();
            var attribute = (GuidAttribute)a.GetCustomAttributes(typeof(GuidAttribute), true)[0];
            var guidFromDll = Logger.AssemblyGuid;
            return "My Guid: " + attribute.Value + " Guid from Dll: " + guidFromDll; // returns 'My Guid: df21ba1d-f3a6-420c-8882-92f51cc31ae1 Guid from Dll: df21ba1d-f3a6-420c-8882-92f51cc31ae1'

        }
     }
}
namespace ClassLibrary1
{
    public class Logger
    {
        public static string AssemblyGuid;

        public static void Init() {
            Assembly a = Assembly.GetCallingAssembly();
            var attribute = (GuidAttribute)a.GetCustomAttributes(typeof(GuidAttribute), true)[0];
            AssemblyGuid = attribute.Value;
        }
    }
}