Visual C# Developer Center > Visual C# Forums > Visual C# General > App.Config, codeBase href, and Windows Services
Ask a questionAsk a question
 

AnswerApp.Config, codeBase href, and Windows Services

  • Friday, November 06, 2009 10:23 PMtimclaason Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Friday, November 06, 2009 11:31 PMTaylorMichaelLMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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

All Replies

  • Friday, November 06, 2009 11:31 PMTaylorMichaelLMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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