c# - How to Retrieve Assembly information from within DLL -


i have asp.net asmx web site service, has assemblyinfo.cs inside properties folder. having trouble accessing information inside file.

my assumption should able call

assembly.getexecutingassembly(); 

and information file, other assembly. solve issue moved assembly attributes file global.asax.cs page. after doing calling above line returned me expected values.

1. have way or have on looked regarding assemblyinfo.cs file?

this website has dll trying use information same assemblyinfo.cs. cannot figure out how information need within dll.

assembly.getentryassembly() = null assembly.getcallingassembly() = mscorlib assembly.getexecutingassembly() = dll assembly 

2. how can assembly information of site?

using system.runtime.interopservices; using gatewayprotocol; using steno; [assembly: guid("3d5900ae-aaaa-bbbb-cccc-d9e4606ca793")] //if remove above line, below debug line **does not** return expected guid  namespace gws {  public class global : system.web.httpapplication {     protected void application_start(object sender, eventargs e)     {         logger.init();          var assembly = assembly.getexecutingassembly();         var attribute = (guidattribute)assembly.getcustomattributes(typeof(guidattribute), true)[0];         debug.writeline(attribute.value) //3d5900ae-aaaa-bbbb-cccc-d9e4606ca793     } } 

}

inside logger.init() starts thread loop reading queue

var guid = ((guidattribute)assembly.getexecutingassembly.getcustomattributes(typeof(guidattribute), true)[0]).value; 

this returns guid of dll, not want.

this works me:

assemblyinfo.cs in web application

[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; // 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 = assembly.getexecutingassembly();             var attribute = (guidattribute)a.getcustomattributes(typeof(guidattribute), true)[0];             var guidfromdll = logger.assemblyguid;             return "my guid: " + attribute.value + " guid dll: " + guidfromdll; // returns 'my guid: df21ba1d-f3a6-420c-8882-92f51cc31ae1 guid dll: df21ba1d-f3a6-420c-8882-92f51cc31ae1'          }      } } 

dll:

namespace classlibrary1 {     public class logger     {         public static string assemblyguid;          public static void init() {             assembly = assembly.getcallingassembly();             var attribute = (guidattribute)a.getcustomattributes(typeof(guidattribute), true)[0];             assemblyguid = attribute.value;         }     } } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -