Daniel Gartmann
Daniel Gartmann

Reputation: 13078

Unable to find assembly file 'example.dll' while starting windows service

I have developed a WCF service which uses the net.tcp binding and read and write files to the file system. When I start the windows service (in a console) I get following error even if the sample.dll is in the folder:

Unable to find assembly file sample.dll

This specific WCF service is hosted in a windows service which runs on windows 7 64bit and I have following questions:

Which account should I use for my application:

User / NetworkService / LocalSystem / LocalService

And why can’t the OS load the dll even if it is there?

Thank you in advance for your help!

Upvotes: 2

Views: 3297

Answers (2)

Tojamismis
Tojamismis

Reputation: 59

For the dll you should add the following line of code right at the beginning of the OnStart method.

 System.Environment.CurrentDirectory = System.AppDomain.CurrentDomain.BaseDirectory

That should allow your service to load dlls from the actual directory.

Upvotes: 3

Whit Waldo
Whit Waldo

Reputation: 5217

According to the MSDN documentation on the ServiceAccount, the User member prompts for a username and password. I'd guess that if you're using the User account and it doesn't have read permissions for windows/system32, that would result in your assembly failing to be found.

Perhaps change the ServiceAccount up a step to a LocalService?

Upvotes: 0

Related Questions