The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception. RRS feed

  • Question

  • Hi all.

    I have a solution that has 3 projects. One of the is the DAL.

    The solution is hosted in team foundation.

    When i try update-database i got the error: "The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception."

    All the console messages are bellow

    update-database -StartUpProjectName ManagerBs.Core -verbose
    Using StartUp project 'ManagerBs.Core'.
    Using NuGet project 'ManagerBs.Core'.
    Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
    System.TypeInitializationException: The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized element. (C:\inetpub\wwwroot\CRM_MVC\ManagerBS\Solution\WebAppManager\ManagerBs.Core\tmp59F8.tmp line 4)
       at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
       at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
       at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
       at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
       --- End of inner exception stack trace ---
       at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
       at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
       at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
       at System.Configuration.ConfigurationManager.get_ConnectionStrings()
       at System.Data.Entity.Internal.AppConfig..ctor()
       at System.Data.Entity.Internal.AppConfig..cctor()
       --- End of inner exception stack trace ---
       at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
       at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
       at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..cctor()
       --- End of inner exception stack trace ---
       at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..ctor()
       at ManagerBs.Core.Migrations.Configuration..ctor() in c:\inetpub\wwwroot\CRM_MVC\ManagerBS\Solution\WebAppManager\ManagerBs.Core\Migrations\Configuration.cs:line 10
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
       at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
       at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
       at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
       at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
       at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
    The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception.

    I couldn't sleep last nights because this problem.

    Somebody have an idea to solve it?

    PS: Sorry my amateur english. ;-)

    Friday, January 24, 2014 12:56 AM


All replies

  • Hello,

    >>When i try update-database i got the error: "The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception."

    Since you are using library, please have a try use command as what the error message shows:

    add-migration -Name First -ProjectName DbSet.Framework -StartUpProjectName CodeFirstConsole

    First: Name of Migration

    Dbset.Framework: Project where dbContext and other classes

    CodeFirstConsole: Start Up project (could be your web, windows or console app)

    And please add the sql connection to the app.config of the DAL dll or it does not work.

    For details, please read this thread:

    If I have misunderstand, please let me know.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 27, 2014 1:42 AM
  • Hi, thanks for answer.

    My problem was solved by disable and enable back migrations.

    Márcio Alves Gonzalez Web programmer

    Sunday, March 9, 2014 3:10 PM
  • Marcio how do you disable and enable migration on visual studio 2013, my program throws the same error

    Saturday, May 17, 2014 6:47 PM
  • Got it
    Saturday, May 17, 2014 6:59 PM
  • Hi. I was wondering, How do you disable migrations cause i know how to enable them?

    Thursday, May 22, 2014 12:05 AM
  • Hi Zulu.

    To disable migrations, enter with: "disable-migrations"

    And to enable "enable-migrations"

    Enter this lines in Package Manager Console

    Márcio Alves Gonzalez

    Márcio Alves Gonzalez Web programmer

    Thursday, May 22, 2014 12:45 PM
  • If you are having multiple projects in your solution, then set your desire project as Startup-Project then try to Enable and Add or Update. :) 

    Saturday, January 5, 2019 10:12 AM