This repository was archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 200
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
ConfigurationBinder throws TargetParameterCountException (due to indexer property?) #253
Copy link
Copy link
Closed
Description
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()