У меня есть раздел пользовательских настроек и я хочу, чтобы создать схему XSD с помощью инструмента XSD, однако я получаю следующее сообщение об ошибке:Получение ошибки при попытке генерации XSD: схемы с использованием xsd.exe
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation. All rights reserved.
Error: There was an error processing 'C:\Development\XXX Application Framewo
rk\XXX.AppFramework\bin\Debug\XXX.AppFramework.dll'.
- There was an error reflecting type 'XXX.AppFramework.Configuration.AppFr
ameworkEnvironmentConfiguration'.
- You must implement a default accessor on System.Configuration.ConfigurationL
ockCollection because it inherits from ICollection.
Однако я не реализовывать ICollection на моей секции, это выглядит следующим образом:
public class AppFrameworkEnvironmentConfiguration : ConfigurationElement
{
[ConfigurationProperty("Name")]
public string Name
{
get { return (string)this["Name"]; }
set { this["Name"] = value; }
}
[ConfigurationProperty("Description")]
public string Description
{
get { return (string)this["Description"]; }
set { this["Description"] = value; }
}
[ConfigurationProperty("ApplicationName")]
public string ApplicationName
{
get { return (string)this["ApplicationName"]; }
set { this["ApplicationName"] = value; }
}
[ConfigurationProperty("DeploymentMode",DefaultValue=DeploymentMode.Local)]
public DeploymentMode DeploymentMode
{
get { return (DeploymentMode)this["DeploymentMode"]; }
set { this["DeploymentMode"] = value; }
}
}
он не смотрит как ConfigurationElement реализует ICollection так им не знаю, почему я получаю эту ошибку?
Имея глубокий взгляд через отражатель, чтобы найти, когда отбрасывается эта ошибка, им еще более озадачены, во-первых мой маленький тест действительно оценить ложь:
bool test = typeof(ICollection).IsAssignableFrom(typeof (XXX.AppFramework.Configuration.AppFrameworkEnvironmentConfiguration));
В отражателе единственное место, где я могу найти это поднять это исключение упаковывается в этом точный тест, я нашел его в System.Xml.Reflection.TypeScope.ImportTypeDesc и выглядит следующим образом:
else if (typeof(ICollection).IsAssignableFrom(type))
{
root = TypeKind.Collection;
elementType = GetCollectionElementType(type, (memberInfo == null) ? null : (memberInfo.DeclaringType.FullName + "." + memberInfo.Name));
none |= GetConstructorFlags(type, ref exception);
}
, а затем
который называет
internal static PropertyInfo GetDefaultIndexer(Type type, string memberInfo)
{
if (typeof(IDictionary).IsAssignableFrom(type))
{
if (memberInfo == null)
{
throw new NotSupportedException(Res.GetString("XmlUnsupportedIDictionary", new object[] { type.FullName }));
}
throw new NotSupportedException(Res.GetString("XmlUnsupportedIDictionaryDetails", new object[] { memberInfo, type.FullName }));
}
MemberInfo[] defaultMembers = type.GetDefaultMembers();
PropertyInfo info = null;
if ((defaultMembers != null) && (defaultMembers.Length > 0))
{
for (Type type2 = type; type2 != null; type2 = type2.BaseType)
{
for (int i = 0; i < defaultMembers.Length; i++)
{
if (defaultMembers[i] is PropertyInfo)
{
PropertyInfo info2 = (PropertyInfo) defaultMembers[i];
if ((info2.DeclaringType == type2) && info2.CanRead)
{
ParameterInfo[] parameters = info2.GetGetMethod().GetParameters();
if ((parameters.Length == 1) && (parameters[0].ParameterType == typeof(int)))
{
info = info2;
break;
}
}
}
}
if (info != null)
{
break;
}
}
}
if (info == null)
{
throw new InvalidOperationException(Res.GetString("XmlNoDefaultAccessors", new object[] { type.FullName })); **< HERE IS THE ERROR**
}
if (type.GetMethod("Add", new Type[] { info.PropertyType }) == null)
{
throw new InvalidOperationException(Res.GetString("XmlNoAddMethod", new object[] { type.FullName, info.PropertyType, "ICollection" }));
}
return info;
}
Я также попытался добавления конструктор без параметров по умолчанию, не отличается ;-( Любые идеи?