castleproject / Windsor

Castle Windsor is a best of breed, mature Inversion of Control container available for .NET
http://www.castleproject.org
Apache License 2.0
1.52k stars 456 forks source link

Can't use <install directory=""> from XML file to register a class. #637

Open OIIvIIO opened 2 years ago

OIIvIIO commented 2 years ago

Hi,

I want to load a DLL from different paths from executing directory and resolve from this DLL. But Castle.Windsor throw this exception

Castle.MicroKernel.SubSystems.Conversion.ConverterException: 'Could not convert string 'EngineA.AClass, EngineA' to a type. Assembly EngineA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null was matched, but it doesn't contain the type. Make sure that the type name was not mistyped.'
   at Castle.MicroKernel.SubSystems.Conversion.TypeNameConverter.GetType(String name) in C:\Users\name\Source\Repos\Windsor\src\Castle.Windsor\MicroKernel\SubSystems\Conversion\TypeNameConverter.cs:line 125
   at Castle.MicroKernel.SubSystems.Conversion.TypeNameConverter.PerformConversion(String value, Type targetType) in C:\Users\name\Source\Repos\Windsor\src\Castle.Windsor\MicroKernel\SubSystems\Conversion\TypeNameConverter.cs:line 72
   at Castle.MicroKernel.SubSystems.Conversion.DefaultConversionManager.PerformConversion(String value, Type targetType) in C:\Users\name\Source\Repos\Windsor\src\Castle.Windsor\MicroKernel\SubSystems\Conversion\DefaultConversionManager.cs:line 106
   at Castle.MicroKernel.SubSystems.Conversion.DefaultConversionManager.PerformConversion[TTarget](String value) in C:\Users\name\Source\Repos\Windsor\src\Castle.Windsor\MicroKernel\SubSystems\Conversion\DefaultConversionManager.cs:line 134
   at Castle.Windsor.Installer.DefaultComponentInstaller.GetType(IConversionManager converter, String typeName) in C:\Users\name\Source\Repos\Windsor\src\Castle.Windsor\Windsor\Installer\DefaultComponentInstaller.cs:line 228
   at Castle.Windsor.Installer.DefaultComponentInstaller.SetUpComponents(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) in C:\Users\name\Source\Repos\Windsor\src\Castle.Windsor\Windsor\Installer\DefaultComponentInstaller.cs:line 183
   at Castle.Windsor.Installer.DefaultComponentInstaller.SetUp(IWindsorContainer container, IConfigurationStore store) in C:\Users\name\Source\Repos\Windsor\src\Castle.Windsor\Windsor\Installer\DefaultComponentInstaller.cs:line 50
   at Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers, DefaultComponentInstaller scope) in C:\Users\name\Source\Repos\Windsor\src\Castle.Windsor\Windsor\WindsorContainer.cs:line 323
   at Castle.Windsor.WindsorContainer.Install(IWindsorInstaller[] installers) in C:\Users\name\Source\Repos\Windsor\src\Castle.Windsor\Windsor\WindsorContainer.cs:line 453
   at Reflection.Program.Main(String[] args) in C:\Users\name\Source\Repos\Reflection\Reflection\Program.cs:line 26

It is XML config file:

CastleInstallerConfig.xml
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
      <installers>
          <install directory="C:\Users\name\Source\Repos\Reflection\EngineA\bin\Release" maskMask="EngineA.dll"></install>
      </installers>
      <components>
              <component id="AClass" service="Reflection.IClass, Reflection" type="EngineA.AClass, EngineA" lifestyle="transient" ></component>
      </components>
</configuration>

It's main method

public static void Main(string[] args)
{
            IWindsorContainer container = new WindsorContainer();
            //container.Install(FromAssembly.InDirectory(new AssemblyFilter("C:\\Users\\name\\Source\\Repos\\Reflection\\EngineA\\bin\\Release"))); // dll in this directory
            container.Install(Configuration.FromXmlFile("C:\\Users\\name\\Source\\Repos\\Reflection\\Reflection\\CastleInstallerConfig.xml")); // xml path. throw exception from this
            IClass aa = container.Resolve<IClass>();
            string res = aa.DoSomethings();
            Console.WriteLine(res);
}

Class and interface are as follows:

// It's in the EngineA.dll
namespace EngineA
{
    public class AClass: IClass
    {
        public string DoSomethings()
        {
            return "FromEngineA";
        }

    }
}
It's in Reflection.exe
namespace Reflection
{
    public interface IClass
    {
        string DoSomethings();
    }
}

When I moved Engine.dll to the same folder as Reflection.exe , it can be work and not throw exception.

AndreyPolovodov commented 1 year ago

I can't do dynamic loading via config file even in same directory - #647