I have a dll I'm calling from another app. I need to store dll settings in separate xml file. So I'v created App.config file. It is looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="myKey" value="1"/>
</appSettings>
</configuration>
Than I try to get value from config with thic code:
var val=System.Configuration.ConfigurationSettings.AppSettings["myKey"];
But it always return null. Also key count of AppSettings equals zero, so there is no keys in it.
What's wrong with it? How can I store my settings in separate file?
If I'm not mistaken, you're looking for ConfigurationManager.OpenMappedExeConfiguration Method (ExeConfigurationFileMap, ConfigurationUserLevel) .
You need to open that assembly configuration file as an another Configuration
object, and once you've got it, you'll be able to access those AppSettings
.
确保问题中提到的配置在调用应用程序的配置文件中,而不在DLL的App.config中。
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.