title: Buggy behavior in DbPRoviderFactories.GetFactoryClasses()
body: <p>I am building an mvc app. I have this in web.config in system.data : </p>
  
  <pre><code>&lt;system.data&gt;
      &lt;DbProviderFactories&gt;
          &lt;remove invariant ="System.Data.SqlClient" /&gt;
          &lt;remove invariant="System.Data.Odbc" /&gt;
          &lt;remove invariant="System.Data.Oledb" /&gt;
          &lt;remove invariant="System.Data.OracleClient" /&gt;     
  
          &lt;add name="SqlClient Data Provider" 
               invariant="System.Data.SqlClient" 
               description=".Net Framework Data Provider for SqlServer" 
               type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/&gt;
      &lt;/DbProviderFactories&gt;
  </code></pre>
  
  <p>This provider comes from a reference in the project from nuget and not in GAC. In GAC I have : <img src="https://i.stack.imgur.com/DIKnZ.png" alt="enter image description here"></p>
  
  <p>In DemoController I have : </p>
  
  <pre><code>    DataTable table = DbProviderFactories.GetFactoryClasses();
          DbProviderFactory msSqlDbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");
          var dbProviderFactories = new string[table.Rows.Count+1,table.Columns.Count+1]; //+1 for readability in display
          ushort i = 0, j = 0;
          foreach (DataRow row in table.Rows)
          {
              foreach (DataColumn column in table.Columns)
              {
                  dbProviderFactories[i, j] = row[column].ToString();
                  j++;
              }
              j = 0;
              i++;
          }
  </code></pre>
  
  <p>And as a result you can see on the screenshot.<a href="https://i.stack.imgur.com/NlwC6.png" rel="nofollow noreferrer">Very strange behavior of DbProviderFactories</a></p>
  
  <p>Can anybody tell me why all the providers (ole, oracle, odbc) are still there even though I have removed them in config?
  Can anybody tell me why when there is no such factory as the one for SqlCleint in the array of factories I can call   </p>
  
  <p>DbProviderFactory msSqlDbProviderFactory = DbProviderFactories.GetFactory("System.Data.SqlClient"); </p>
  
  <p>and get the factory anyway? This is a strange behavior I can not explain.</p>
  
  <p>I have come across the problem by doing so : 
   1. Initialized DbContext with default ctor when it has a connection string in web.config like this : </p>
  
  <pre><code>&lt;connectionStrings&gt;
          &lt;add name="MyDbContext"
                connectionString="Data Source=MSSQL-SERVER-INSTANCE;Initial Catalog=MyDb.mdf;Trusted_Connection=False;User ID=u;Password=p"
               providerName="System.Data.SqlClient"/&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <ol start="2">
  <li>Tried to use DbMigrator with DbMigrationConfig like this : </li>
  </ol>
  
  <p>string connectionString = "Data Source=MSSQL-SERVER-INSTANCE;Initial Catalog=MyDb.mdf ;Trusted_Connection=False;User ID=u;Password=p";</p>
  
  <pre><code>    DbMigrationsConfiguration&lt;InitDbContext&gt; cfg = new DbMigrationsConfiguration&lt;InitDbContext&gt;
                      {   
                          AutomaticMigrationsEnabled = true,
                          MigrationsAssembly = Assembly.Load("Migrations"),
                          MigrationsNamespace = "Migrations",
                          TargetDatabase = new DbConnectionInfo(connectionString, "System.Data.SqlClient")
                      };
  
                  DbMigrationsConfiguration cfg = CreateMigrationsConfig(connectionString);
                  new DbMigrator(cfg).Update();
  </code></pre>
  
  <p>And here comes the nasty "Unable to find the requested .Net Framework Data Provider".</p>
  
  <p><a href="http://www.dotnetframework.org/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/fx/src/Data/System/Data/Common/DbProviderFactories@cs/1305376/DbProviderFactories@cs" rel="nofollow noreferrer">The source code of DbProviderFactories</a> </p>