5

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, Func3 handleFailedLookup) at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetServices(Type type, Object key) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext() at System.Linq.Enumerable.ConcatIterator1.MoveNext() at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext() at System.Linq.Enumerable.ConcatIterator1.MoveNext() at System.Linq.Enumerable.<OfTypeIterator>d__321.MoveNext() at System.Collections.Generic.List1.AddEnumerable(IEnumerable1 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.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy1.CreateValue() at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.GetConfiguration() at System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model) at X.Y.ConfigurationModule.ConfigurationContainer..ctor(String nameOrConnectionString)} System.TypeLoadException

1
  • 1
    Are you referencing System.Data.Common.DbProviderFactories? Commented Oct 18, 2017 at 10:54

1 Answer 1

1

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

enter image description here

Version Problem

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

https://www.nuget.org/packages/System.Data.Common/

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the reply. I have not referenced any assembly explicitly. I have tried to get System.Data.Common from Nuget but having tried the different versions in the nuget package has not helped. It seems no matter what I try the error msg remains the same. It refers to version 4.0.0.0 which was never a version being used. Could the error be with System.Data and not System.Data.Common, then 4.0.0.0 would make more sense.
So are you still facing the same problem?
Yes the problem remains the same. The error says: "from assembly System.Data" so maybe there was never anything wrong with System.Data.Common?
Could be as easy as DbProviderFactories class not being available in .NET Standard 2.0, found this: github.com/dotnet/standard/issues/356
I have the same issue, was it resolved or must we wait for core 2.1?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.