api.net-coreasp.net-apicontrollercore-api

Assembly name was changed after deployment in core web api application


I am using VS 2019 to develop core.net web Api. I am trying to read the all methods and Parameters inside my controller. I am using Repository pattern to develop API.

Below is the code from my repository.

var method = MethodBase.GetCurrentMethod();
_log4net.Info("Assembly Name : " + Assembly.GetCallingAssembly().FullName); _log4net.Info("Method Name : " + method.Name); _log4net.Info("Repository Name :" + method.ReflectedType.FullName);

var result = ((System.Reflection.TypeInfo)Assembly.GetCallingAssembly().GetTypes().Where(type => type.FullName.Contains("AsmeController")).FirstOrDefault()).DeclaredMethods; _log4net.Info(result);

Log's:

In Debug Mode: enter image description here

After deployment in IIS

enter image description here

This code is working as expected and returns the list of Method Info in Debug mode and not working and return Null in Release mode even after deployed in IIS.

As i observed using logs, Assembly name was changing Demo.dll to “ Assembly Name : Anonymously Hosted DynamicMethods Assembly “ after deployment.

Please give me suggestions to solve this problem.


Solution

  • For the work around i am directly reading the application dll, Instead of reading current assembly. So that i can able to access the all info from there.

    string assemblyFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location + "\\Demo.dll");
     
    Assembly testAssembly = Assembly.LoadFile(assemblyFile); 
    
    var result = ((TypeInfo)testAssembly.GetTypes().Where(type => type.FullName.Contains("AsmeController")).FirstOrDefault()).DeclaredMethods;