2

構成ファイルからいくつかのカスタム設定をシリアル化しようとしています。以下は私の設定です:

<FavouriteTools>
        <favouriteTool PluginPlaceHolder="FavoriteTool1" PlugInName="Brightness"
          PlugInType="2D" PlugInAssemblyName="Micro.DigiMic.Plugins.AreaBasedOnBrightness.AreaBasedOnBrightnessPlugin"
          GUID="0000c03a-b891-4ebd-87d7-5fbc19073a1a" />
        <favouriteTool PluginPlaceHolder="FavoriteTool2" PlugInName="CircleArea"
          PlugInType="2D" PlugInAssemblyName="Micro.DigiMic.Plugins.CircleAreaPlugin.CircleAreaPlugin"
          GUID="0000c06a-b891-4ebd-87d7-5fbc19073a1a" />
        <favouriteTool PluginPlaceHolder="FavoriteTool3" PlugInName="Contour Area"
          PlugInType="2D" PlugInAssemblyName="Micro.DigiMic.Plugins.ContourAreaPlugin.ContourAreaPlugin"
          GUID="0000c11a-b891-4ebd-87d7-5fbc19073a1a" />         

しかし、シリアル化中にエラーが発生します。これが私のクラスです。

//FavouriteTools - Root Node
[Serializable]
[XmlType("FavoriteTools")]
[ConfigurationCollection(typeof(FavouriteTool), AddItemName = "favouriteTool", CollectionType = ConfigurationElementCollectionType.BasicMap)]
public class FavouriteToolsCollection
: ConfigurationElementCollection    
{
//Few plublic methods here
}

//favouriteTool -  Child node
[Serializable]
[XmlType("favouriteTool")]
public class FavouriteTool : ConfigurationElement
{
    /// <summary>
    /// Gets or sets value of Plugin PlaceHolder.
    /// </summary>
    /// <value>Text Color.</value> 
    [ConfigurationProperty("PluginPlaceHolder", IsRequired = false)]
    public string PlugPlaceHolder
    {
        get { return (string)base["PluginPlaceHolder"]; }
        set { base["PluginPlaceHolder"] = value; }
    }

//Few more properties like above
}

I am trying to serialize below class, but gets exception on below like

XmlSerializer xmlinf = new XmlSerializer(data.GetType());


`data` is `ExportUser`

[Serializable]
public class ExportUser
{

public bool IsMetric { get; set; }

[XmlArray("FavoriteTools")]
    [XmlArrayItem("favouriteTool")]
    public FavouriteToolsCollection FavoriteTools { get; set; }
 }  

私はこのエラーを受け取ります -There was an error reflecting type 'ExportUser'そして内部例外でエラーは言う - There was an error reflecting type 'FavoriteTools'

何か足りないものはありますか?

アップデート:

内部例外を見た後、エラーは

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

There was an error reflecting type 'Zeiss.Micro.DigiMic.Application.FavouriteTool'.

しかし、私はFavouriteToolsCollectionクラスにデフォルトのアクセサーを持っています:

public FavouriteTool this[int index]
    {
        get
        {
            return (FavouriteTool)BaseGet(index);
        }

        set
        {
            if (this.BaseGet(index) != null)
            {
                this.BaseRemoveAt(index);
            }

            this.BaseAdd(index, value);
        }
    }

これ以上何が欠けていますか?

4

1 に答える 1