在Core Web API应用程序中部署后更改了汇编名称

发布于 2025-02-10 18:33:16 字数 838 浏览 2 评论 0原文

我正在使用VS 2019来开发Core.NET Web API。我正在尝试阅读控制器内部的所有方法和参数。我正在使用存储库模式来开发API。

以下是我的存储库中的代码。

var method = methodbase.getCurrentMethod();
_log4net.info(“汇编名称:” + assembly.getCallingAssembly()。fullName); _log4net.info(“方法名称:” + method.name); _log4nnet.info(“存储库名称:” + method.reflectedType.fullname);

var结果= ((System.Reflection.Typeinfo)组件.getCallingAssembly().getTypes() => type.fullname.contains(“ asmecontroller”))。firstordEfault())。dectectMethods; _log4net.info(结果);

日志:

在调试模式下:

中部署后

在IIS

​。

正如我使用日志观察到的那样,汇编名称正在将Demo.dll更改为“汇编名称:匿名托管DynamicMethods Assembly”。

请给我建议解决这个问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逐鹿 2025-02-17 18:33:16

对于周围的工作,我直接读取应用程序DLL,而不是读取当前组件。这样我就能从那里访问所有信息。

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文