Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Why does this code cause xsd.exe error, “You must implement a default accessor on System.Configuration.ConfigurationLockCollection”?

$
0
0

Hello MSDN users,

Iam trying to create an XSD from a dll that i created, but when i try to generate the XSD i get the following error message:

You must implement a default accessor on System.Configuration.ConfigurationLockCollection because it inherits from ICollection.

(Also tried different framework version (Did not work))

Command that gets executed:

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools>xsd "J:\ Programming\C#\NightBitsLogger Library\NightBitsLogger\bin\Debug\NightBitsLogger .dll"

Does anyone know what i have to do to have a default accessor for the ConfigurationLockCollection? (Because it seems that this is a bug in the .NET framework)

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Collections;

namespace NightBitsLogger.Configuration
{
    /// <summary>
    /// This class is an abstract class for a Collection of Config Elements
    /// </summary>
    /// <typeparam name="T"></typeparam>
    ///
    [ConfigurationCollection(typeof(ConfigurationItem), AddItemName = "ConfigurationElement" )]
    public abstract class CollectionOfElements<T> : ConfigurationElementCollection
        where T : ConfigurationItem, new()
    {
        /// <summary>
        /// Default Accessor for the collections
        /// </summary>
        [ConfigurationProperty("ConfigurationCollection", IsRequired = true)]
        public CollectionOfElements<ConfigurationItem> ConfigurationCollection
        {
            get
            {
                return base["ConfigurationCollection"] as CollectionOfElements<ConfigurationItem>;
            }
        }

        /// <summary>
        /// Create and return a new Configuration Element
        /// </summary>
        /// <returns></returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new T();
        }

        /// <summary>
        /// Return the element key.
        /// </summary>
        /// <param name="element"></param>
        /// <returns>(ConfigurationElement)key</returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ConfigurationItem)element).Name;
        }

        /// <summary>
        /// Return the element with the given index
        /// Basic accessor for elements
        /// </summary>
        /// <param name="index"></param>
        /// <returns>[Element]byIndex</returns>
        public T this[int index]
        {
            get
            {
                return (T)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        /// <summary>
        /// Add a element to the collection
        /// </summary>
        /// <param name="collectionOfLoggerElement"></param>
        public void Add(T collectionOfLoggerElement)
        {
            BaseAdd(collectionOfLoggerElement);
        }

        /// <summary>
        /// Return the element with the given index
        /// </summary>
        /// <param name="name"></param>
        /// <returns>[Element]byName</returns>
        public new T this[string name]
        {
            get
            {
                return (T)BaseGet(name);
            }
        }
    }

    /// <summary>
    /// The CollectionOfLoggers Collection
    /// </summary>
    [ConfigurationCollection(typeof(CollectionOfLoggersElement), AddItemName = "CollectionOfLoggers", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class CollectionOfLoggers : CollectionOfElements<CollectionOfLoggersElement>
    {
        // Do nothing
    }

    /// <summary>
    /// The FileLogger Collection
    /// </summary>
    [ConfigurationCollection(typeof(FileLoggerElement), AddItemName = "fileLogger", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class FileLoggers : CollectionOfElements<FileLoggerElement>
    {
        // Do nothing
    }

    /// <summary>
    /// The RollingDateFileLogger Collection
    /// </summary>
    [ConfigurationCollection(typeof(RollingDateFileLoggerElement), AddItemName = "rollingDateFileLogger", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class RollingDateFileLoggers : CollectionOfElements<RollingDateFileLoggerElement>
    {
        // Do nothing
    }

    /// <summary>
    /// The RollingSizeFileLogger Collection
    /// </summary>
    [ConfigurationCollection(typeof(RollingSizeFileLoggerElement), AddItemName = "rollingSizeFileLogger", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class RollingSizeFileLoggers : CollectionOfElements<RollingSizeFileLoggerElement>
    {
        // Do nothing
    }

    /// <summary>
    /// The EmailLogger Collection
    /// </summary>
    [ConfigurationCollection(typeof(EmailLoggerElement), AddItemName = "emailLogger", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class EmailLoggers : CollectionOfElements<EmailLoggerElement>
    {
        // Do nothing
    }

    /// <summary>
    /// The SocketLogger Collection
    /// </summary>
    [ConfigurationCollection(typeof(SocketLoggerElement), AddItemName = "socketLogger", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class SocketLoggers : CollectionOfElements<SocketLoggerElement>
    {
        // Do nothing
    }

    /// <summary>
    /// The WindowsEventLogLogger Collection
    /// </summary>
    [ConfigurationCollection(typeof(WindowsEventLogLoggerElement), AddItemName = "WindowsEventLogLogger", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class WindowsEventLogLoggers : CollectionOfElements<WindowsEventLogLoggerElement>
    {
        // Do nothing
    }

    /// <summary>
    /// The ConsoleLogger Collection
    /// </summary>
    [ConfigurationCollection(typeof(ConsoleLoggerElement), AddItemName = "consoleLogger", CollectionType = ConfigurationElementCollectionType.BasicMap)]
    public class ConsoleLoggers : CollectionOfElements<ConsoleLoggerElement>
    {
        // Do nothing
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.ComponentModel;

namespace NightBitsLogger.Configuration
{
    /// <summary>
    /// This is the baseClass that represents a Config Item (Logger)
    /// </summary>
    public class ConfigurationItem : ConfigurationSection
    {
        /// <summary>
        /// Get the configuration
        /// </summary>
        /// <returns></returns>
        public static ConfigurationItem GetConfiguration()
        {
            ConfigurationItem configuration = ConfigurationManager.GetSection("NightBitsLogger.Configuration") as ConfigurationItem;

            if (configuration != null)
            {
                return configuration;
            }

            return new ConfigurationItem();
        }

        /// <summary>
        /// Occurs after the element is deserialized
        /// </summary>
        ///
        protected override void PostDeserialize()
        {
            base.PostDeserialize();
            Validate();
        }

        /// <summary>
        /// Validate the element. Throw a exception if not valid.
        /// </summary>
        protected virtual void Validate()
        {
            if ((IncludeCategories.Trim() != "") && (ExcludeCategories.Trim() != ""))
            {
                throw new ConfigurationErrorsException("logging element can have either includeCategories or excludeCategories, but not both.");
            }
        }

        /// <summary>
        /// Return true if the Logger Element is configured for the current machine; otherwise return false.
        /// </summary>
        /// <returns></returns>
        public bool IsConfiguredForThisMachine()
        {
            var machineNames = Machine.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            return (machineNames.Length == 0) || new List<string>(machineNames).Exists(name => name.Equals(Environment.MachineName, StringComparison.CurrentCultureIgnoreCase));
        }

        /// <summary>
        /// Get the name of the Logger
        /// </summary>
        [ConfigurationProperty("name", DefaultValue = "", IsKey = true, IsRequired = true)]
        [Description("The name of the logger")]
        public string Name
        {
            get
            {
                return (string)this["name"];
            }
        }

        /// <summary>
        /// The machine names (separated by commas) for which the Logger will be created. An empty value creates it on all machines.
        /// </summary>
        [ConfigurationProperty("machine", DefaultValue = "", IsRequired = false)]
        [Description("The machine names (separated by commas) for which this logger will be created. Leaving it empty will create it on all machines")]
        public string Machine
        {
            get
            {
                return (string)this["machine"];
            }
        }

        /// <summary>
        /// Check if the Internal Exception Logging is enabled
        /// </summary>
        [ConfigurationProperty("enableInternalExceptionLogging", DefaultValue = false, IsRequired = false)]
        [Description("true if the internal exceptionLogging is enabled; otherwise false")]
        public bool IsInternalLoggingEnabled
        {
            get
            {
                return (bool)this["isInternalLoggingEnabled"];
            }
        }

        /// <summary>
        /// Check if the Logger is enabled
        /// </summary>
        [ConfigurationProperty("isEnabled", DefaultValue = true, IsRequired = false)]
        [Description("true if the logger is enabled; otherwise false")]
        public bool IsEnabled
        {
            get
            {
                return (bool)this["isEnabled"];
            }
        }

        /// <summary>
        /// The LogLevel of the Logger
        /// </summary>
        [ConfigurationProperty("logLevel", DefaultValue = LogLevel.Debug, IsRequired = false)]
        [Description("The logLevel of the logger")]
        public LogLevel LogLevel
        {
            get
            {
                return (LogLevel)this["logLevel"];
            }
        }

        /// <summary>
        /// Categories to include (leave blank for all)
        /// </summary>
        [ConfigurationProperty("includeCategories", DefaultValue = "", IsRequired = false)]
        [Description("The categories, separated by commas, to include when logging. Leave blank to include everything.")]
        public string IncludeCategories
        {
            get
            {
                return (string)this["includeCategories"];
            }
        }

        /// <summary>
        /// Categories to exclude
        /// </summary>
        [ConfigurationProperty("excludeCategories", DefaultValue = "", IsRequired = false)]
        [Description("The categories, separated by commas, to exclude when logging.")]
        public string ExcludeCategories
        {
            get
            {
                return (string)this["excludeCategories"];
            }
        }

        /// <summary>
        /// If true, wrap the Logger in an KeepLoggingLogger.
        /// </summary>
        [ConfigurationProperty("keepLogging", DefaultValue = false, IsRequired = false)]
        [Description("if true, the logger will be wrapped in a KeepLoggingLogger")]
        public bool keepLogging
        {
            get
            {
                return (bool)this["keepLogging"];
            }
        }

        /// <summary>
        /// If true, wrap the Logger in an AsynchronousLogger.
        /// </summary>
        [ConfigurationProperty("isAsynchronous", DefaultValue = false, IsRequired = false)]
        [Description("if true, the logger will be wrapped in a AsynchronousLogger")]
        public bool IsAsynchronous
        {
            get
            {
                return (bool)this["isAsynchronous"];
            }
        }

        /// <summary>
        /// The FormatString for the Logger
        /// </summary>
        [ConfigurationProperty("formatString", DefaultValue = "", IsRequired = false)]
        [Description("The format string of the logger. If blank, it will use the format string of the enclosing section (the CollectionOfLoggers).")]
        public virtual string FormatString
        {
            get
            {
                return (string)this["formatString"];
            }
        }
    }
}



Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>