Search code examples
c#wcf

App_Code AppInitialize does not compile when dependencies within a sub directory of bin


I have the following structure of an IIS application:

IIS Application\
  App_Code\
    AppInitializer.cs
  bin\
    CommonLibrary //junction folder
  ...
  foo.svc
  web.config

The AppInitializer.cs contains the following:

using CommonLibrary; //Dependency located inside the junction folder
namespace TD.Registry
{
  public class Hostbootstrapper
  {
    public static void AppInitialize()
    {
       //Some code here using CommonLibrary
    }
  }
}

When I browse the IIS application in the web browser it results in a Compilation Error with the following message

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'CommonLibrary' could not be found (are you missing a using directive or an assembly reference?)


Solution

  • I resolved the compilation error by adding the needed assemblies in the web.config like so:

    <system.web>
      <compilation debug="true" targetFramework="4.6.1">
        <assemblies>
          <add assembly="CommonLibrary"/>
        </assemblies>
      </compilation>
      
      ...
      
    </system.web>