简体   繁体   English

服务找不到引用的DLL

[英]Service cannot find referenced DLLs

I have a C# service app that references a dll ('A') that in turn reference other dlls ('B' and 'C', say). 我有一个C#服务应用程序,该应用程序引用一个dll('A'),而该dll又引用了其他dll(例如'B'和'C')。 The service project references all the necessary dlls. 服务项目引用所有必需的dll。

The entry code calls a method in 'A' that calls methods in 'B' or 'C'. 进入代码在“ A”中调用一个方法,在“ B”或“ C”中调用方法。 We are getting a custom error message from 'A' that says that 'B' and 'C' cannot be found, in spite of them being in the same folder as the service, and we know that this indicates that the process working folder is incorrect (ie the process thinks the working folder is elsewhere). 我们从'A'收到一条自定义错误消息,提示找不到'B'和'C',尽管它们与服务位于同一文件夹中,并且我们知道这表明进程的工作文件夹为错误的(即进程认为工作文件夹在其他地方)。

The question is: how can I explicitly tell the service what the working folder is? 问题是:如何明确告诉服务工作文件夹是什么?

TIA TIA

Services run in System32 . 服务在System32中运行

If you copy B.dll and C.dll into your System32 folder, it'll probably work. 如果将B.dll和C.dll复制到System32文件夹中,则可能会起作用。

To fix it, you should create an installer project in your solution. 要修复它,您应该在解决方案中创建一个安装程序项目。 The installer will handle installing all of the necessary .dlls in the right place. 安装程序将在正确的位置处理所有必需的.dll。

Here's a SO example 这是一个SO示例

Edit #1: 编辑#1:

This post has the last piece of the puzzle. 这篇文章是拼图的最后一部分。 Dlls have to be added to the setup project separately from the original project. Dll必须与原始项目分开添加到设置项目中。

关键在于,我必须欺骗服务以认为工作文件夹是服务可执行文件所在的位置,由于上面的某些链接,现在我可以轻松地用代码来完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM