简体   繁体   English

.net程序集未找到App.config

[英]App.config not located by a .net assembly

I have an ASP.NET application which is adding up .NET assembly in its reference. 我有一个ASP.NET应用程序,它在其参考中添加了.NET程序集。 The assembly is a private assembly and it has a config file with some keys under <AppSettings> . 该程序集是一个私有程序集,它具有一个配置文件,该文件在<AppSettings>下具有一些键。

Now the problem is when I am debugging my ASP.NET application the assembly is not loading the app.config file. 现在的问题是,当我调试ASP.NET应用程序时,程序集未加载app.config文件。

I observed that under the property of referenced assembly I have Copy Local=true . 我观察到在引用程序集的属性下,我具有Copy Local=true

Can anyone please help or point out if i am missing some basics? 任何人都可以帮忙或指出我是否缺少一些基础知识?

You need to collect all pertinent settings into the web.config file of the main ASP.NET application. 您需要将所有相关设置收集到主ASP.NET应用程序的web.config文件中。 Only the config file of the running application (be it web or desktop) is loaded automatically. 系统只会自动加载正在运行的应用程序(网络或桌面)的配置文件。

Look up some articles on how config files work in the .NET environment to learn the basics of what is and isn't loaded, it'll definitely help you avoid headaches like this in the future. 查找有关.NET环境中配置文件如何工作的一些文章,以了解已加载和未加载的基础知识,它肯定会帮助您避免将来遇到此类麻烦。

Alternatively, if you know the name of your assembly's config file you can add a file attribute to your <AppSettings> element, pointing to that file if it's copied to the same directory as the web.config is in. 或者,如果知道程序集的配置文件的名称,则可以将file属性添加到<AppSettings>元素,如果该文件复制到与web.config所在的目录相同的文件,则指向该文件。

<appSettings file="privateassembly.config">

Please note that any appsetting with the same name declared in the web.config will be overridden by the privateassembly.config. 请注意,任何在web.config中声明的具有相同名称的appsetting将被privateassembly.config覆盖。 Also note that any change to privateassembly.config (while the ASP.NET application is running) will not reset the application pool and thus will not be loaded into the AppDomain. 还要注意,对privateassembly.config的任何更改(在ASP.NET应用程序运行时)都不会重置应用程序池,因此不会加载到AppDomain中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM