Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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?

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
1  
Nailed it! Thanks! It was referencing System.Web.Mvc.ValueProviderFactory, not System.Web.Http.ValueProviders.ValueProviderFactory which is the correct one. – Lucio Paiva Jul 19 '13 at 20:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.