Can a class library have an App.config file?

No, class libraries can hold setting files, but their values will be defined in the application configuration (web.config, app.config…).

That’s because of configuration settings overriding feature.

You’ll need to declare the assemblies’ configuration sections in the app.config or web.config of your application (WPF, SL, ASP.NET…) and define a value for a particular number of settings defined in the proper assembly settings.

EDIT:
Add a setting file to your project and add a setting with application scope, and your assembly would have something like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="Assembly1.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <Assembly1.Settings1>
            <setting name="settingA" serializeAs="String">
                <value>a value</value>
            </setting>
        </Assembly1.Settings1>
    </applicationSettings>
</configuration> 

Now you’d need to go to your application, and you need to copy-paste the section group, and section declarations, and the definition of the values for the settings. That’s all.

Leave a Comment