My web.config references an assembly used by a dependent DLL library. Any way around this?

不打扰是莪最后的温柔 提交于 2019-12-08 01:22:43

问题


Here is my concrete example.

I have written a dll which uses EntityFramework to talk to a database and do some work. Originally, the front end was a console application, but there is now an additional requirement for a web front end as well. From what I've read, the 'top-most' application (web app or console app) should store all the configuration, even the configuration which is needed only by the dll itself.

(I will use the web app as my example from now one, but it applies to the console app as well)

To get the web app working, I have moved the connection string and other settings from the dll library's app.config into my web.config.

When I run my web app, I get the following error

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 appears to be due to the fact that in my web.config, the connection string refers to Entity Framework, and there are other EntityFramework references in there too - all of which are required by the DLL library.

One workaround is simply use NuGet to install EntityFramework into my web app. It all works, but seems very wrong - creating an unnecessary dependency.

Is there another way?

Can I untangle the web.config and place the EntityFramework stuff in the dll's app.config, whilst leaving the basic sql server connection string info in the web.config? If so, how - it's resembles spaghetti!

If this is possible, are there any guides out there?

来源:https://stackoverflow.com/questions/26926814/my-web-config-references-an-assembly-used-by-a-dependent-dll-library-any-way-ar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!