"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Does My Unit Test Fail with "The Entity Framework provider type... could not be loaded?"

Why Does My Unit Test Fail with "The Entity Framework provider type... could not be loaded?"

Posted on 2025-02-26
Browse:172

Why Does My Unit Test Fail with

Entity Framework Provider Loading Failure

When attempting to run unit tests on TeamCity, an exception arises: "The Entity Framework provider type
'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' ADO.NET provider could not be loaded..."

Resolution

Despite the absence of direct references to System.Data.Entity in project, the presence of specific configuration settings in the app.config file can cause unexpected behavior:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>

This configuration forces the runtime to attempt loading the Entity Framework provider, even without direct references.

Solution

To resolve this issue, ensure that the EntityFramework.SqlServer NuGet package is installed in all executables involved in the test process. Additionally, remove the entityFramework section from the app.config file, as it is no longer necessary.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3