Search code examples
.netasp.netdataprovider

Is it possible to place the ASP.NET DataProvider assemblies in a sub directory


I'm currently implementing some DataProviders according to the ASP.NET Provider Model. Everything works fine, though the application directory is a mess due to all the assemblies containing the data providers and their dependencies.

Is it possible to put the assemblies containing the DataProviders in a subfolder? If yes, what do I have to change (in the app.config?) so that the assemblies will be found by the application?

This is my current entry in the app.config:

<CustomerProvider>
  <providers>
   <add name="SqlDataProvider" type="SqlDataProvider.SqlCustomerDataProvider, SqlDataProvider"/>
  </providers>
</CustomerProvider>

Best regards, Michael


Solution

  • I just found the solution in the book .NET Framework-Programming in C# by Jeffrey Richter. You just have to add following section to your app.config:

    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <probing privatePath="Providers"/>
        </assemblyBinding>
      </runtime>    
      ...
    </configuration>
    

    This causes the CLR to look into the sub directory Providers in your application root directory (e.g. C:\MyApplication\Providers) when it can't find an referenced assembly.

    Now I can put all the 100+ assemblies in a separate directory and keep my application directory clean.