Reputation: 73
I have just added a WPF project to my app and when I try and use my DataAcccess class to interact with Entity DB I get the error:
An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code
Additional information: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded
This error has only started happening since I added this project and I cant figure it out. I copied over my App.Config to the new project, here it is :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
And the error is happening in one of my classes when trying to build a list of objects, in the line
using (var context = new DataAccess())
:
namespace MarketAnalyser.LogicLayer
{
public class Instrument
{
public int ID { get; set; }
public string Name { get; set; }
public string Expiry { get; set; }
public double TickSize { get; set; }
public double TickValue { get; set; }
public double OpenTime { get; set; }
public double CloseTime { get; set; }
public Instrument(string name, string expiry, double tickSize, double tickValue, double openTime, double closeTime)
{
this.Name = name;
this.Expiry = expiry;
this.TickSize = tickSize;
this.TickValue = TickValue;
this.OpenTime = openTime;
this.CloseTime = closeTime;
}
public static List<Instrument> GetAllInstruments()
{
List<Instrument> InstrumentList = new List<Instrument>();
using (var context = new DataAccess())
{
foreach (var instrument in context.Instrument)
{
InstrumentList.Add(instrument);
}
}
return InstrumentList;
}
}
}
Upvotes: 1
Views: 97
Reputation: 336
try with add connectionString
after </configSections>
<connectionStrings>
<add name="Your_EntityName" connectionString="Data Source=your_server_name;Initial Catalog=Your_database_name;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Upvotes: 0
Reputation: 3453
Could you double check that the assembly (EntityFramework.SqlServer) that contains your ADO.NET provider (System.Data.Entity.SqlServer.SqlProviderServices) is deployed to the output folder (bin\debug) It looks like assembly resolution mechanism cannot locate it To view more details on assembly resolution errors you could use Fuslogvw
By default, when you install the latest version of 'EntityFramework 6.1.3' as a NuGet package, you get both assemblies referenced from your project
Double check that you have those references (and that they have copyLocal property set to true), and if not - re-install the package
Upvotes: 2