Visual C# Developer Center >
Visual C# Forums
>
Visual C# General
>
App.Config, codeBase href, and Windows Services
App.Config, codeBase href, and Windows Services
- I have a Windows service that references an assembly (log4net.dll). When I have the log4net.dll in the same directory as the service .exe, (with no special app.config settings), the service runs fine.
When I try to have the .dll in a separate directory, and manipulate app.config to point to the other directory, the service fails to start.
Can anyone provide insight into what the heck I'm doing wrong? Thanks.
By the way, the directory, version, and publicKeyTokens are all correct. I've also tried the href with back-slashes with the same result.
Below is the app.config lines I put in:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" culture="neutral"/>
<codeBase version="1.2.10.0" href="file:///C:/Project/log4net/log4net.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Answers
- Unless the assembly is strongly named then the codebase must be relative to the app base path as described here: http://msdn.microsoft.com/en-us/library/efs781xb(VS.71).aspx
If assemblies will be located in subdirectories of your app then you should consider using <probe> instead. For shared assemblies then the GAC is the better location. Using a hard-coded path as you are trying to do is generally not a good idea for several reasons including deployment.
Michael Taylor - 11/6/09
http://p3net.mvps.org- Marked As Answer byChao KuoMSFT, ModeratorThursday, November 12, 2009 8:02 AM
- Proposed As Answer byChao KuoMSFT, ModeratorMonday, November 09, 2009 12:02 PM
All Replies
- Unless the assembly is strongly named then the codebase must be relative to the app base path as described here: http://msdn.microsoft.com/en-us/library/efs781xb(VS.71).aspx
If assemblies will be located in subdirectories of your app then you should consider using <probe> instead. For shared assemblies then the GAC is the better location. Using a hard-coded path as you are trying to do is generally not a good idea for several reasons including deployment.
Michael Taylor - 11/6/09
http://p3net.mvps.org- Marked As Answer byChao KuoMSFT, ModeratorThursday, November 12, 2009 8:02 AM
- Proposed As Answer byChao KuoMSFT, ModeratorMonday, November 09, 2009 12:02 PM


