1

I have a C# service app that references a dll ('A') that in turn reference other dlls ('B' and 'C', say). The service project references all the necessary dlls.

The entry code calls a method in 'A' that calls methods in 'B' or '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).

The question is: how can I explicitly tell the service what the working folder is?

TIA

haughtonomous
  • 4,602
  • 11
  • 34
  • 52

2 Answers2

3

Services run in System32.

If you copy B.dll and C.dll into your System32 folder, it'll probably work.

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.

Here's a SO example

Edit #1:

This post has the last piece of the puzzle. Dlls have to be added to the setup project separately from the original project.

Community
  • 1
  • 1
Shaz
  • 1,376
  • 8
  • 18
  • I should have mentioned - I have an installer and a setup and deployment project, used to install the service, and the dlls are actually in the service executable folder. But it still seems ot be confused about where to look for them. – haughtonomous Dec 18 '13 at 16:56
  • @NeilHaughton edited my post. I couldn't test it on my machine, but it looks like you have to add the .dlls to the setup project manually(it doesn't do it automatically). Let me know if that helps. – Shaz Dec 18 '13 at 17:01
  • 1
    Nope. I've done that and also checked that the dlls are actually present in the same folder as the installed service. It still reports that it can't find them. I don't really want to copy all these dlls into the System32 directory - they have no business there, being part of my app rather than 'shared' libraries. The key turns out to be that I have to fool the service to think the working folder is where the service executable is located, which I can easily do in code. – haughtonomous Dec 19 '13 at 10:03
1

The key turns out to be that I have to fool the service to think the working folder is where the service executable is located, which I can now easily do in code, thanks to some of the links above.

haughtonomous
  • 4,602
  • 11
  • 34
  • 52