Der Typinitialisierer für 'System.Data.Entity.Internal.AppConfig' hat auf einer Unterwebsite eine Ausnahme ausgelöst

Ich habe 2 Websites, eine ist ein Unterverzeichnis einer anderen, aber eine Anwendung, zB: / root & / root / Services

Beide verwenden Entity Framework 6.x, aber die untergeordnete Website wird ausgelöstDer Typinitialisierer für System.Data.Entity.Internal.AppConfig 'hat eine Ausnahme ausgelöst weil es aufgrund der verschachtelten web.config zu viele Einträge für denselben EF-Datenbankanbieter zu sehen scheint

Gibt es eine Möglichkeit, die Anbietersammlung zu löschen, damit ich diesen Fehler nicht erhalte? Ich habe versucht, in das zu setzen, das keine Wirkung hatte.

Wenn ich den Anbieterbereich auskommentiere, funktioniert es

<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>

Aber ich möchte dies nicht tun, da nicht jede Umgebung verschachtelte Websites haben wird. und NuGet neigt legt es wieder in. Kann ich dies programmgesteuert anpassen?

Hier ist die vollständige Ausnahmen- und Stack-Ablaufverfolgung

System.TypeInitializationException was unhandled by user code
HResult=-2146233036
Message=**The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.**
Source=EntityFramework
TypeName=System.Data.Entity.Internal.AppConfig
StackTrace:
     at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
     at System.Data.Entity.Internal.LazyInternalConnection..ctor(String nameOrConnectionString)
     at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
     at co.Repository.Data.coContext..ctor() in coModel.Context.Generated.cs:line 23
     at co.Repository.RepositoryBase`1.SingleOrDefault(Expression`1 predicate) in co.Repository\RepositoryBase.cs:line 13
     at UserFactory.GetOneByUserName(String siteCode, String userName) in UserFactory.cs:line 151
     at UserService.GetOneByUserName(String siteCode, String userName) in UserService.cs:line 59
     at SyncInvokeGetOneByUserName(Object , Object[] , Object[] )
     at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
     at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
InnerException: System.Configuration.ConfigurationErrorsException
     HResult=-2146232062
     Message=An error occurred creating the configuration section handler for entityFramework: **The provider for invariant name 'System.Data.SqlClient' is specified multiple times in the application configuration. The invariant name must be unique for each configured provider.** (web.config line 339)
     Source=System.Configuration
     BareMessage=An error occurred creating the configuration section handler for entityFramework: The provider for invariant name 'System.Data.SqlClient' is specified multiple times in the application configuration. The invariant name must be unique for each configured provider.
     Filename=web.config
     Line=339
     StackTrace:
          at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
          at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
          at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
          at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
          at System.Configuration.ConfigurationManager.GetSection(String sectionName)
          at System.Data.Entity.Internal.AppConfig..ctor()
          at System.Data.Entity.Internal.AppConfig..cctor()
     InnerException: System.InvalidOperationException
          HResult=-2146233079
          Message=The provider for invariant name 'System.Data.SqlClient' is specified multiple times in the application configuration. The invariant name must be unique for each configured provider.
          Source=EntityFramework
          StackTrace:
               at System.Data.Entity.Internal.ConfigFile.ProviderCollection.BaseAdd(ConfigurationElement element)
               at System.Configuration.ConfigurationElementCollection.OnDeserializeUnrecognizedElement(String elementName, XmlReader reader)
               at System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
               at System.Configuration.ConfigurationElement.DeserializeElement(XmlReader reader, Boolean serializeCollectionKey)
               at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
               at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
               at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
               at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
          InnerException: 

Antworten auf die Frage(3)

Ihre Antwort auf die Frage