views:

227

answers:

2

When the spring.net framework starts up for an asp.net application does the component that registers all objects in the IoC container recurse all sub-directories referenced in the web.config?

eg.

<spring>
  <context>
    <resource uri="~/bin/ClientService/ClientService.config"/>
    <resource uri="~/MCFModule.config"/>
  </context>
</spring>

I believe the answer to be yes looking at the debug info (trace listener) output.

The problem I'm seeing is that when it attempts to create an instance in the '\bin\clientservice' directory it fails with the error message even though the dll exists in the sub-directory;

'Could not load file or assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. The system cannot find the file specified. '

Any one got any ideas?

Cheers

Ollie

A: 

When Spring.NET is trying to resolve a reference in its configuration file it will use the same rules as the .NET assembly loader. So maybe you could try adding the correct reference of log4net assembly in your bin folder.


EDIT: If you want Spring.NET to locate assemblies in non-standard locations you could use the <assemblyBinding> element to indicate the location:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
    </sectionGroup>
  </configSections>

  <spring>
    <context>
      <resource uri="config://spring/objects"/>
    </context>
    <objects xmlns="http://www.springframework.net"&gt;
      <object id="someObject" type="log4net.Util.AppenderAttachedImpl, log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" />
    </objects>
  </spring>

  <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:/some_special_location/log4net.dll" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>

And then you could ask the container to instantiate the object:

var someObject = ContextRegistry.GetContext().GetObject("someObject");
Darin Dimitrov
this is my understanding as well, the log4net is in the 'bin\clientservice' directory and it can't resolve it from the that sub directory...
AWC
+2  A: 

You also have the option to programmatically handle assembly load failures, using the AppDomain.AssemblyResolve event on the AppDomain class.

You could, for example, scan all subdirectories looking for the assembly you care about.

Nader Shirazie