This repository has been archived by the owner. It is now read-only.

ConfigurationBinder throws TargetParameterCountException (due to indexer property?) #253

Closed
Eilon opened this Issue Jul 23, 2015 · 2 comments

Comments

Projects
None yet
4 participants
@Eilon
Copy link
Member

Eilon commented Jul 23, 2015

Not sure exactly why, but ConfigurationBinder can throw a TargetParameterCountException, perhaps due to the presence of an indexer property (because they have parameters).

I was playing with binding config data into a list of strings and saw this error. I'm not saying the code should necessarily work (though I'm not sure why it shouldn't), but this exception definitely shouldn't appear.

To repro, use this unit test:

        [Fact]
        public void BinderThrowsOnIndexerMaybe()
        {
            var builder = new ConfigurationBuilder();
            var config = builder.Build();
            var options = ConfigurationBinder.Bind<List<string>>(config);
        }

And get this stack trace:

Microsoft.Framework.Configuration.Binder.Test.ConfigurationCollectionBinding.BinderThrowsOnIndexerMaybe [FAIL]
      System.Reflection.TargetParameterCountException : Parameter count mismatch.
      Stack Trace:
            at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
            at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
            at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
            at System.Reflection.PropertyInfo.GetValue(Object obj)
         C:\Users\elipton\Documents\GitHub\Configuration\src\Microsoft.Framework.Configuration.Binder\ConfigurationBinder.cs(49,0): at Microsoft.Framework.Configuration.ConfigurationBinder.BindProperty(PropertyInfo property, Object propertyOwner, IConfiguration configuration)
         C:\Users\elipton\Documents\GitHub\Configuration\src\Microsoft.Framework.Configuration.Binder\ConfigurationBinder.cs(35,0): at Microsoft.Framework.Configuration.ConfigurationBinder.BindObjectProperties(Object obj, IConfiguration configuration)
         C:\Users\elipton\Documents\GitHub\Configuration\src\Microsoft.Framework.Configuration.Binder\ConfigurationBinder.cs(28,0): at Microsoft.Framework.Configuration.ConfigurationBinder.Bind(Object model, IConfiguration configuration)
         C:\Users\elipton\Documents\GitHub\Configuration\src\Microsoft.Framework.Configuration.Binder\ConfigurationBinder.cs(17,0): at Microsoft.Framework.Configuration.ConfigurationBinder.Bind[TModel](IConfiguration configuration)
         ConfigurationCollectionBindingTests.cs(18,0): at Microsoft.Framework.Configuration.Binder.Test.ConfigurationCollectionBinding.BinderThrowsOnIndexerMaybe()
@HaoK

This comment has been minimized.

Copy link
Member

HaoK commented Aug 13, 2015

@HaoK HaoK closed this Aug 13, 2015

@davidfowl

This comment has been minimized.

Copy link
Member

davidfowl commented Aug 13, 2015

@HaoK bug needs labels - bug/enhancement and Done

@HaoK HaoK added bug 3 - Done labels Aug 14, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.