2

I was put on a C# project that already has an SQL database on azure and asked to implement an automatic code first migration system.

We have a db on azure, but I will have to use a localhost test db for this purpose.

In the Web.config there was already a mechanism to choose between azure's or the local db using:

<add name="MS_TableConnectionString" connectionString="..." .. />

I followed the following tutorial step by step but now when I run the application i get the following error:

No service registered for type 'ITableControllerConfigProvider'. Please Ensure That the dependency resolve Has Been Correctly configured.

Error is triggered by WebApiConfig.cs at line 20:

// Use this class to set WebAPI configuration options
HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));

I found this solution online but it didn't work. I added the dependentAssembly for System.Web.Http but still get the same error.

What is the reason behind this error and what is the best approach to handle it?

UPDATE

Thanks to the feedback given, I was able to fix it. For anyone with the same scenario here is what I was missing:

  • Wrong initializer context and order in Global.asx.cs under Application_Start()

     // This must be first in code
     WebApiConfig.Register();
     // Context: get it from Configuration.cs
     app.Models.MobileServiceContext myDbContext = new app.Models.MobileServiceContext();
     // Configuration() should come from your app
     Database.SetInitializer(new MigrateDatabaseToLatestVersion<app.Models.MobileServiceContext, Configuration>());
     myDbContext.Database.Initialize(false);
    
  • Wrong local connection string:
    Since we had a database the connection string was not pointing to the same version number of the one created by migration.
    In Web.config

    <add name="MS_TableConnectionString" connectionString=".....VERSION_NB";.../>
    

    Version number must point to the one created by migration.

UPDATE 2

I updated my migration mechanism, inspired by the following tutorial.

1
  • 1
    Update 2 tutorial link is dead. Commented Apr 4, 2017 at 14:32

1 Answer 1

1

I cannot be sure why your code is throwing that error. There are only three things that I think might be the cause of the problem.

  1. Your config is not fully initialised. Try

    config.EnsureInitialized()

  2. You are using a dependency inject framework like Ninject, and the dependency resolver has not been set. Try

    config.DependencyResolver = new NinjectResolver(kernel)

Also check the link https://msdn.microsoft.com/en-us/library/microsoft.windowsazure.mobile.service.tables.itablecontrollerconfigprovider.aspx

I think you have to register an implementation of ITableControllerConfigProvider as the config's dependency resolver.

  1. You could be missing an assembly

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot bro, I think number 3 was my case I will post how I fixed it in an update above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.