question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trying to load configuration from Installer results in duplicate registrations

See original GitHub issue

This is my first time playing with Castle, so maybe I’m doing something idiotic:

I’m creating a new Container that loads an xml file. That xml file loads a custom installer. The custom installer will feed additional xml files. Doing this components fed at the custom installer level are somehow registered twice causing a typeinitializer exception.

Here is some of the code

 internal class CastleContainer
    {
        static CastleContainer()
        {
            var path = System.AppDomain.CurrentDomain.BaseDirectory+"Windsor.config";
            Current = new WindsorContainer(new XmlInterpreter(path));
        }
        public static IWindsorContainer Current { get; internal set; }
    }
    public class DatabaseInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            var source = new InMemoryResource();
            ////XmlInterpreter xi = new XmlInterpreter(source);
            ////xi.ProcessResource(xi.Source, store, container.Kernel);
            //var kernel = container.Kernel;
            //IResourceSubSystem resourceSubSystem = kernel.GetSubSystem(SubSystemConstants.ResourceKey) as IResourceSubSystem;
            //resourceSubSystem.RegisterResourceFactory(new DatabaseResourceFactory());

            container.Install(Configuration.FromXml(source));
        }

        internal class DatabaseResourceFactory : IResourceFactory
        {
            public bool Accept(CustomUri uri)
            {
                return "db".Equals(uri.Scheme);
            }

            public IResource Create(CustomUri uri)
            {
                return this.Create(uri, null);
            }

            public IResource Create(CustomUri uri, string basePath)
            {
                return new InMemoryResource();
            }
        }

        public class InMemoryResource : IResource
        {
            public string FileBasePath
            {
                get
                {
                    throw new NotImplementedException();
                }
            }

            public IResource CreateRelative(string relativePath)
            {
                throw new NotImplementedException();
            }

            public void Dispose()
            {
            }

            public TextReader GetStreamReader()
            {
                var config = @"<configuration>  <components>    <component id=""ConfigRepository"" service=""SimpleService.IMyService,SimpleService"" type=""SimpleService.MyService2,SimpleService"" >      <parameters>        <innerRepositoryKey>ConfigRepository.nh</innerRepositoryKey>      </parameters>    </component>  </components></configuration> ";
                return (new StringReader(config));
            }

            public TextReader GetStreamReader(Encoding encoding)
            {
                return GetStreamReader();
            }
        }
    }

<configuration>
  <installers>
    <install assembly="WindsorSandbox"/>
  </installers>
</configuration>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jonorossicommented, Aug 11, 2015

@richardspence this looks like an unsupported use case. From a quick look at the code it looks like the configuration your installer is “installing” gets loaded into the PartialConfigurationStore of the parent DatabaseInstaller and so gets set up twice.

I probably wouldn’t recommend loading an installer inside another installer. Do you want to describe what you are trying to do, as there is likely a better way.

FYI, no need to make your own InMemoryResource class, there is Castle.Core.Resource.StaticContentResource.

0reactions
ghostcommented, Sep 19, 2017

Please join the discussion on https://github.com/castleproject/Windsor/issues/338 I am proposing we deprecate XML configs. Closing this for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

keras AssertionError: Duplicate registrations for type ' ...
Same problem : I completely uninstalled the libraries (nightly...), and reinstalled the latest stable version (pip3 install tensorflow) I'm ...
Read more >
Known Issue and Workaround: Duplicate Records When ...
This workaround requires scripting and additional configuration steps but it might be appropriate if you must install software as soon as ...
Read more >
Duplicate name registration error in InfoSphere DataStage ...
In order to restore the parallel engine in MPP configuration, using PXEngine/install/copy-orchdist is recommended instead of Copy (cp) command.
Read more >
Service definition duplication by configuration files import
Hi all, I'm trying to import an existing configuration into a new installation of Nagios XI (this is a test environment with a...
Read more >
Error Message: The configuration has not yet loaded. If this ...
Log in to the BIG-IP command line. Attempt to manually load the configuration by entering the following command: tmsh load sys config. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found