.NET Configuration Section Designer - Where is my collection?

会有一股神秘感。 提交于 2019-12-03 20:58:47

Well, I grossly overcomplicated the true issue by specifying the problem down to a specific element, when it turns out not even a simple test attribute on the ConfigurationSection would return an expected value. I also realized that I couldn't access AppSettings, which resulted in a raging clue.

The ultimate cause? The project was compiled as a class library. Config files are only available at the application level. Since I was using NUnit to run the tests, the configuration file from the test project was overriding the development one for the class library. This is probably obvious to any developers who are not stuck in ASP.NET land.

By adding the following configSection to the app.config within the test project:

<section name="customConfigSection" type="ClassLibraryNamespace.SettingsClass, ClassLibraryNamespace"/>

and filling in the corresponding section, the data could be accessed as expected.

Hopefully, this will save someone hours of debugging.

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