我可以确定是什么触发了程序集加载吗?

发布于 2024-08-07 00:51:42 字数 541 浏览 3 评论 0原文

当 Windows 服务安装程序因“错误 1001。无法在 MyService.exe 程序集中获取安装程序类型”而崩溃时。所以它无法加载MyServiceInstaller。 Fusion 日志记录显示,尝试查找 Data.dll 程序集时失败。

问题是,它不需要加载 Data.dll 来创建我的服务安装程序对象。我认为直到调用包含这些类型的方法之前才会触发类型加载。某些 MyServiceInstaller 方法引用 Data.dll 中的类型,但不引用任何构造函数。

这就好像加载 MyService.exe 或探测 MyServiceInstaller 的行为会调用 Data.dll 的加载。

据我了解,融合记录不会告诉我我需要知道的事情。那时已经太晚了。我需要知道加载 MyServer.exe 或对 MyServiceInstaller 的探测首先触发了 Data.dll 的加载。

有一个业务需求,Data.dll 不能放在 MyService.exe 旁边。事实上,这确实解决了这个问题。我有一个自定义的 AssemblyResolve 事件,它在正常运行时加载 Data.dll。

When windows service installer is bombing out with a "Error 1001. Unable to get installer types in the MyService.exe assembly." So it can't load MyServiceInstaller. Fusion logging is showing me that it is failing when trying to find my Data.dll assembly.

The thing is, it should not need to load Data.dll to create my service installer object. I thought that type loading was not triggered until just before a method containing those types was called. Some MyServiceInstaller methods reference types from Data.dll, but not any ctor.

It's as if the act of loading MyService.exe, or probing for MyServiceInstaller, invokes the load of Data.dll.

As I understand it, fusion logging will not tell me what I need to know. It's too late at that point. I need to know what it is about loading MyServer.exe or the probing for MyServiceInstaller that triggered the loading of Data.dll in the first place.

There is a business requirement that Data.dll cannot be placed next to MyService.exe. And indeed, that does solve this problem. I have a custom AssemblyResolve event which loads Data.dll at normal runtime.

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

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

发布评论

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

评论(2

江湖正好 2024-08-14 00:51:43

也许有一个Data.dll中定义的类型的实例变量(字段);加载 MyServiceInstaller 时,所有字段的类型都需要可用,即使未使用它们,因为如果创建实例,则正在编译该类。

Perhaps there is an instance variable (field) of a type defined in Data.dll; when MyServiceInstaller is loaded, the types for all fields need to be available, even if they're not used, because the class is being compiled if an instance is created.

余生共白头 2024-08-14 00:51:42

尝试将调试器附加到安装程序,并使其在引发异常时中断(您可以在 Visual Studio 中的“调试/异常”中进行设置)。通常应该抛出 FileNotFoundException 或类似的异常当程序集加载失败时,在安装程序内部,这可能会在其他地方捕获,但如果您在异常被抛出时使调试器中断(并且在未处理异常时)您可以介入并获取堆栈跟踪,这应该可以帮助您发现到底是什么导致了问题。

您应该在堆栈跟踪中看到类似的内容:

  • [Uninteresting native and/or external code]
  • SomeClassInYourInstaller.SomeMethod() <-- this is the Responsible method
  • SomeOtherStuff.SomeMethod()
  • ...等等...

Try to attach a debugger to the installer and make it break when the exception is thrown (you can set that up in Visual Studio in Debug/Exceptions). Normally there should be a FileNotFoundException or something similar thrown internally in the installer when the assembly load fails which is probably catched somewhere else but if you make the debugger to break when the exception is being thrown (and not when it's unhandled) you can step in and get a stack trace which should help you at discovering what exactly caused the problem.

You should see something like that in the stack trace:

  • [Uninteresting native and / or external code]
  • SomeClassInYourInstaller.SomeMethod() <-- this is the responsible method
  • SomeOtherStuff.SomeMethod()
  • ...etc...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文