引用的程序集不会在 IIS 7 上的新线程中加载
我有一个过程,其中用户将文件上传到网站,然后处理该文件并将其上传到数据库中。验证文件的过程可能需要几分钟的时间,因此文件上传后,我会创建一个新线程,并在第二个线程上进行处理。这在我的本地计算机上工作得很好,但在我的 IIS 7 测试服务器上根本不起作用。
经过一番调查后,我发现问题是该进程正在尝试加载对 Castle 的引用,但找不到 DLL。我的 bin 中有一份 Castle DLL 的副本,它可以在我的应用程序的其他地方工作。我运行 Fuslog 并发现它试图从错误的位置加载城堡。它正在尝试从 c:/windows/system32/inetsrv/ 加载。
看来在 IIS 7 下,第二个线程是在不同的上下文或其他环境中执行的。
那么问题是我该怎么做才能让它在应用程序的 BIN 文件夹中找到 Castle?
I have a process in which a user uploads a file to a web site where the file is then processed and uploaded into the database. The process of validating the file could take several minutes so as soon as the file is uploaded I create a new thread and I do my processing on this second thread. This works great on my local machine but doesn't work at all on my IIS 7 test server.
After some investigating I found the problem is that the process is trying to load a reference to Castle and it can't find the DLL. I have a copy of Castle DLLs in my bin and it works elsewhere in my app. I ran Fuslog and discovered that it is trying to load castle from the wrong location. It is trying to load from c:/windows/system32/inetsrv/.
It appears that under IIS 7 the second thread is executing in a different context or something.
So the question is what can I do to get it to find Castle in the application BIN folder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 IIS 不太熟悉,但我的猜测是由于某种原因工作目录已更改。
一种可能性是将工作目录更改回 bin 文件夹。
另一种可能性是订阅 AppDomain.AssemblyResolve 事件,该事件将在 CLR 无法加载程序集时调用 - 在事件处理程序中,您可以从 dll 加载程序集并将其返回。
I am not very familiar with IIS but my guess is that for some reason the working directory has changed.
One possibility is to change the working directory back to the bin folder.
Another possibility is to subscribe to the AppDomain.AssemblyResolve event which will be invoked any tine the CLR fails to load an assembly - inside the event handler you can load the assembly from the dll and return it.