C# .NET - Windows Service Can't Find Referenced Assembly when running as Local System

Asked By Victor D.C. on 22-Apr-09 11:37 AM

Hello fellows,

I'm scracthing my head trying to figure out a pesky issue regarding Windows Services. I have a .NET .3.5 Windows Service that references a C++ "Wrapper" DLL (that is, this dll allows me to access unmanaged code by using managed wrapper methods). The wrapper dll and all the other dlls / libs it depends on reside in the same folder, which is also where the Windows Service executable resides.

For some strange reason, the windows service throws an HRESULT: 0x8007007E (specified module could not be found) exception when it runs as LocalSystem (the default). If I force the service to run as my personal admin account, everything works fine (except that I run into other issues that are out of the scope of this posting). So I would like to ask you if there is anything special I need to do to allow my service to find and use the wrapper assembly while running as LocalSystem.

I have tried moving all the wrapper dll (and its dependent dlls/libs) to c:\windows\system32 and also set the current directory (Directory.SetCurrentDirectory() method) to that of the local process, all to no avail. I even tried setting both the System and Local User PATH environments to point to the folder containing all the required DLLs, also without luck. At any rate, I don't *think* the problem is the PATH, because all the required DLLs reside in the same folder as the service executable.

My environment is Windows Vista.

Any suggestions? I'm out of ideas at this point :-(

Thank you very much in advance!

Windows Service

Ravenet Rasaiyah replied to Victor D.C. on 22-Apr-09 12:03 PM
hi

According your words, i  understood windows service work very when you are running in Administrator account as Local System.But when you are in normal account it not finding the DLL. from that i think Security issue to access the DLL when you are run in normal account. Mostlly in Windows Vista need security confirmation to every operation  :)

So Please lets try on this way.

Install  you service in XP or windows server 2003 with normal account then confirm what is the issues(i mean is it a security issues)

that's way we could find your exact issues place.

thank you

Clarification

Victor D.C. replied to Ravenet Rasaiyah on 22-Apr-09 12:14 PM

Hey Raveen,

First of all, thanks for the quick response!

I will try what you suggested, but first let me clarify something. I think I am having the opposite problem to what you are describing. The service runs without a problem when I tell it to run under my personal account (which happens to have admin privileges). The problems arise when I let the service run under its default "Local System" account.

I was under the impression that Local System had extensive privileges on the computer, as suggested by this article (http://msdn.microsoft.com/en-us/library/ms684190.aspx), which is the reason why I'm puzzled.

Does that make sense?

Thanks again,

Victor

Ohh ic

Ravenet Rasaiyah replied to Victor D.C. on 22-Apr-09 12:20 PM
Hi

ohh ic, so when you are run in Local System there should be issues on in OS, because of Microsoft, and i visit your link they given all the disabled and enable.

So finally when you are in Local System you have get all privileges like Network services.

thank you
Problem solved
Victor D.C. replied to Ravenet Rasaiyah on 22-Apr-09 01:56 PM
Thanks for the help, Raveen. I figured out the problem: I was missing some third-party assemblies :-)
Travis replied to Victor D.C. on 13-Oct-10 01:08 PM
Sorry to bring up an old issue, but can you explain a little more how you resolved this?  I am having the same problem.  How is it that the service works in your user account if you're missing 3rd party assemblies?  There are special assemblies required for the system account that aren't required for your user account?