2010-11-01 4 views
3

J'ai une section de configuration personnalisée et je veux générer un schéma xsd en utilisant l'outil XSD, mais je reçois l'erreur suivante:Obtenir erreur en essayant de générer xsd: schéma à l'aide 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. 

Cependant Je ne mettons pas en œuvre ICollection sur mon article, il ressemble à ceci:

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; } 
    } 


} 

il ne ressemble pas à ConfigurationElement implémente ICollection si je ne suis pas sûr pourquoi je reçois cette erreur?

Ayant eu un regard profond à travers réflecteur pour trouver quand cette erreur est renvoyée, im encore plus perplexes, d'abord mon petit test n'évalue en effet à false:

bool test = typeof(ICollection).IsAssignableFrom(typeof (XXX.AppFramework.Configuration.AppFrameworkEnvironmentConfiguration)); 

Dans réflecteur le seul endroit que je peux trouver il soulever cette exception est enveloppé dans ce test exact, je l'ai trouvé dans System.Xml.Reflection.TypeScope.ImportTypeDesc et ressemble à ceci:

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); 
} 

puis

private static Type GetCollectionElementType(Type type, string memberInfo) 
{ 
return GetDefaultIndexer(type, memberInfo).PropertyType; 
} 

qui appelle

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; 
} 

J'ai aussi essayé d'ajouter un constructeur par défaut sans paramètre, pas différent ;-(Toutes les idées?

Répondre

0

Pouvez-vous essayer d'ajouter un constructeur par défaut, j'ai vu des problèmes similaires comme celui-ci et l'ajout d'un constructeur par défaut vide a résolu cela pour moi dans le passé. Je ne sais pas pourquoi, mais j'ai eu l'intention de faire des recherches à un moment donné.

Questions connexes