Usage of .net class lib in a windows service

  • Thread starter Thread starter Michael Ulmann
  • Start date Start date
M

Michael Ulmann

Hi,

I'm developing a windows service with c#. Now I'm trying to use a .net class
library (dll) to include.
For this I added the dll to my references. But unfortunately if i run the
service i got always this error:

File or assembly name "myClassLibrary", or one of its dependencies, was not
found.

Does someone knows where i have to place my dll that it could be found by my
windows service.
I already tryied to place it in the System32 folder and also in the same
folder as the windows service is. But without any success. :(

Thank you for your help!

Best Regards,
Michael
 
Hi,

The simplest solution would be to put the assembly in the GAC.
Also, you can utilize Fusion Log Viewer (fuslogvw.exe) upon service start-up
to see which locations are probed for the class library assembly.
If your service is an .exe, you can also probably use the configuration file
to specify additional probing paths for the class library assembly.
 
Yes, I'd suggest Strong Naming the myClassLibrary.dll assembly and
installing it into the Global Assembly Cache (GAC). Here's how to do
it, in case you don't know how:

1.) Open up the Visual Studio .NET Command Prompt from the Start Menu
Program Item link
2.) Navigate to a directory where you'd like to store your
public/private key pair file (e.g. C:\MyKeys)
3.) Generate a public/private key pair using the following command:
sn -k myKeyPair.snk
4.) Add the following to your AssemblyInfo.cs file in your Project for
myClassLibrary:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyKeyFile(@"C:\MyKeys\myKey.snk")]
Change the version to whatever you'd like and the AssemblyKeyFile path
to the appropriate path to the location of your key pair file.
5.) Build your assembly
6.) Install your assembly in the GAC with the following command:
gacutil /i myClassLibrary.dll

Your Windows Service should now be able to find your assembly. Let me
know if it works for you.
 
[assembly: AssemblyKeyFile(@"C:\MyKeys\myKey.snk")] should read
[assembly: AssemblyKeyFile(@"C:\MyKeys\myKeyPair.snk")] above to be
consistent with step 3.
 
Back
Top