So my solution compiles but when I run it I get an error in the class library that is running .NET 4.6.1.
System.TypeLoadException: 'Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Any suggestions?
EDIT:
Complete error:
$exception {System.TypeLoadException: Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key, Func
3 handleFailedLookup) at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetServices(Type type, Object key) at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key, Func2 valueFactory) at System.Linq.Enumerable.SelectManySingleSelectorIterator
2.MoveNext() at System.Linq.Enumerable.ConcatIterator1.MoveNext() at System.Linq.Enumerable.SelectManySingleSelectorIterator
2.MoveNext() at System.Linq.Enumerable.ConcatIterator1.MoveNext() at System.Linq.Enumerable.<OfTypeIterator>d__32
1.MoveNext() at System.Collections.Generic.List1.AddEnumerable(IEnumerable
1 enumerable) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at System.Data.Entity.Infrastructure.DependencyResolution.InternalConfiguration.Lock() at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.<.ctor>b__1() at System.Lazy
1 source) at System.Data.Entity.Infrastructure.DependencyResolution.InternalConfiguration.Lock() at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.<.ctor>b__1() at System.Lazy
1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy
1.CreateValue() at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.GetConfiguration() at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model) at XYConfigurationModule.ConfigurationContainer..ctor(String nameOrConnectionString)} System.TypeLoadException
You see this type of errors when the assembly your are using is different from the reference assembly.
Example
In this condition you see this error because first one using version 3 and other using 2
Please do these check
1:Open references right click on System.Data.Common.DbProviderFactories assembly and check its version
2:Now open you package config or app config file and check the version of that assembly there.
Solution
If versions conflict please install the library from
Then go to bin folder delete the 'System.Data.Common.DbProviderFactories' dll also delete it from references from your project then click add references go to packages folder because the latest library you downloaded goes in this folder so just add reference. Now right click on this assembly and copy version name and paste that version in your appconfig or packages config file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.