开发者

Why is the EntLib Caching Application Block using the wrong configuration file

When I try and use code that makes use of the Enterprise Library Caching Block I get the following error:

The "cachingConfiguration" section is not available in the supplied configuration source.

The section is in my app.config file for that particular assembly though. If I copy the file into the unit test assembly that makes use of the afore mentioned code everything works. Is there any way that I can force it to use the app config that exists in the referenced l开发者_运维百科ibrary so I don't need to duplicate it in every assembly that makes use of it?


Yes.

Select an app.config file to be your master config file (a good choice would be the one in the project of the main application executable).

Now go to your other project (fx. the unit test project). Right-click and select Add Existing Item. Point to the master app.config file and add using the "As link" option:

Add as link http://blog.codevelop.dk/pics/AddAsLink.png

Now you only need to manage one app.config file, and the other projects will 'reference' this file.

Option 2: If you wan't to control what config file the Enterprise Library uses for caching configuration, use:

var fileSource = new FileConfigurationSource(configFilePath);
var factory = new CacheManagerFactory(fileSource);
ICacheManager manager = factory.CreateDefault();


The dll config file that you see in the IDE (if you are using the designer to add settings etc) is largely for convenience. The runtime won't look for it; it wants the file from yourexename.config. Some components provide the facility to specify a separate config file path - I don't know if this is the case for entlib.

Alternatively if you are spawning your own AppDomains you can specify the config file path. And finally some config sections can be referenced in from other files rather than using the file completely (see configSource here) - but in general (and especially for tests) it is easier to just copy the configuration section into the top-level app's config file (or the unit test's config file in this case).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜