Added a custom section to web.config

<packaging> <qtytoshow value="8"/> </packaging> 

And for the convenience of obtaining data made configuration class.

 [ConfigurationProperty("qtytoshow", IsRequired = true)] public QuantityConfiguration Quantity { get { return (QuantityConfiguration) base["qtytoshow"]; } set { base["qtytoshow"] = value; } } public class QuantityConfiguration : ConfigurationElement { [ConfigurationProperty("value", IsRequired = true)] public int QtyToShow { get { return (int) base["value"]; } set { base["value"] = value; } } } 

Resharper highlights the following error

 Error 67 Cannot apply indexing with [] to an expression of type 'object' 

And points to sections of code (int) base["value"]; and base["qtytoshow"] . Help me to understand why here it indicates an error, and in the other file the exact same configuration does not exist?

Other configuration file

 [ConfigurationProperty("printer", IsRequired = true)] public PrinterConfiguration Printer { get { return (PrinterConfiguration) base["printer"]; } set { base["printer"] = value; } } public class PrinterConfiguration : ConfigurationElement { [ConfigurationProperty("address", IsRequired = false)] public string Address { get { return (string)base["address"]; } set { base["address"] = value; } } } 

    1 answer 1

    The error was that you need to remember to specify inheritance from the ConfigurationSection class for the root class.