I'm working with MVC 4 and I have this simple dummy ValueProvider:
class DummyValueProviderFactory : ValueProviderFactory
{
public override IValueProvider GetValueProvider(ControllerContext controllerContext)
{
return new DummyValueProvider();
}
private class DummyValueProvider : IValueProvider
{
public DummyValueProvider()
{
}
public bool ContainsPrefix(string prefix)
{
return true;
}
public ValueProviderResult GetValue(string key)
{
return null;
}
}
}
And my problem resides when I try to register it's factory in the Web API:
config.Services.Add(typeof(ValueProviderFactory), new DummyValueProviderFactory());
It compiles OK, but when the server starts, I get an ArgumentException telling me The service type ValueProviderFactory is not supported
.
I've read this tutorial and this other one and both are telling me it should work fine. What am I doing wrong?
Make sure you are referencing the ValueProviderFactory in the ASP.NET Web API namespace, and not the one the MVC namespace. They both have the same class name, but they are in different namespaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With