0

I want to configure per XML a module with a property, which contains a list of class MyObject. My Module and MyObject class are looking like:

public class MyModule : Module
{
    public IList<MyObject> MyObjects { get; set; }

    protected override void Load(ContainerBuilder builder)
    {
        base.Load(builder);

        // Do something with MyObjects.
    }
}

public class MyObject
{
    public string Id { get; set; }
    public bool IsVisable { get; set; }
}

My assumption was to configure it like this in XML:

<modules name="MyModule">
<type>...</type>
<properties>
  <MyObjects>
    <MyObject>
      <Id>1234</Id>
      <IsVisilble>false</IsVisilble>
    </MyObject>
  </MyObjects>
</properties>

But if I run this, I get the following exception:

Unable to convert object of type 'Autofac.Configuration.Util.ConfiguredDictionaryParameter' to type 'System.Collections.Generic.IList`1[MyObject]'

I'm using Autofac 4.5.0 with Autofac.Configuration 4.0.1.

What am I doing wrong? Is there a way to get it working?

der_chirurg
  • 1,475
  • 2
  • 16
  • 26
  • Core Autofac doesn't come with config support, that's a separate package. Include which version of that you're using. Also, [have you read the docs?](http://autofac.readthedocs.io/en/latest/configuration/xml.html) – Travis Illig Nov 09 '17 at 01:04
  • @TravisIllig Yes I read the docs. I'm using autofac.configuration.4.0.1 – der_chirurg Nov 13 '17 at 11:05
  • Any typos in your stuff? `IsVisable` (in code) vs `IsVisilble` (in XML)? Did you [look at the examples in the unit tests](https://github.com/autofac/Autofac.Configuration/blob/develop/test/Autofac.Configuration.Test/Files/ConfigurationExtensions_EnumerableParameters.xml)? Looks like your `name` on the module isn't a number - that's a problem. Looks like you're missing `name` on the elements in your list - that's a problem. Try JSON instead of XML, it's way easier to work with. – Travis Illig Nov 13 '17 at 16:19

0 Answers0