Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable configSource attribute for Custom Configuration Section in .NET?

following the wealth of information found here how can we get an external .config to work? I've tried the same setup I would use for an external appSettings file, but it is unable to find the file for my custom section.

<configSections> ...     <section name="CustomSettings" type="Fully.Qualified.TypeName.CustomSettings, AssemblyName" /> </configSections> <!-- this works --> <CustomSettings attrib1="val1" attrib2="val2" .../> 

however...

<!--this does not work--> <CustomSettings configSource="someExternalFile.config"/> 

where someExternalFile.config would contain

<CustomSettings attrib1="val1" attrib2="val2" .../> 

any ideas?

like image 495
E Rolnicki Avatar asked Dec 29 '08 20:12

E Rolnicki


1 Answers

The actual file, must be placed relative to the project output folder (by default "\bin\debug" or "bin\Release"

Also, The file in your project tree, look at the properties of the file, and make sure the "Copy to Output Directory" setting is set to "Copy Always" or "Copy if Newer"

EDIT: make sure the separate config file has an xml Element header. The entire file contents should read as follows:

<?xml version="1.0" encoding="utf-8" ?> <CustomSettings attrib1="val1" attrib2="val2" .../> 
like image 140
Charles Bretana Avatar answered Sep 28 '22 04:09

Charles Bretana