2017-02-03 13 views
1

안녕하세요, 제가 단결 게임 (아래 오류) 용 플러그인을 만들고 있으므로이 플러그인을 메인 플러그인으로 만들고 순위를 읽으려고합니다. 나는 그 오류에 대해 알지 못한다. 나는 이것에 관한 어떤 소식도 보지 못한다. 당신은 Message 클래스에 생성자를 추가 할 필요가잘못된 연산 예외, C# XML 오류

[2/3/2017 7:47:23 PM] [Error] InvalidOperationException: RanksUnlocker.RanksUnlockerConfig+Message cannot be serialized because it does not have a default public constructor - System.Xml.Serialization.ReflectionHelper.CheckSerializableType (System.Type type, Boolean allowPrivateConstructors) 
System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
Rethrow as InvalidOperationException: There was an error reflecting type 'RanksUnlocker.RanksUnlockerConfig+Message'. 
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
System.Xml.Serialization.XmlReflectionImporter.ImportListMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace, System.Xml.Serialization.XmlAttributes atts, Int32 nestingLevel) 
System.Xml.Serialization.XmlReflectionImporter.ImportListMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace, System.Xml.Serialization.XmlAttributes atts, Int32 nestingLevel) 
System.Xml.Serialization.XmlReflectionImporter.CreateMapMember (System.Type declaringType, System.Xml.Serialization.XmlReflectionMember rmember, System.String defaultNamespace) 
System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
Rethrow as InvalidOperationException: There was an error reflecting field 'Messages'. 
System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
Rethrow as InvalidOperationException: There was an error reflecting type 'RanksUnlocker.RanksUnlockerConfig+Rank'. 
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
System.Xml.Serialization.XmlReflectionImporter.ImportListMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace, System.Xml.Serialization.XmlAttributes atts, Int32 nestingLevel) 
System.Xml.Serialization.XmlReflectionImporter.ImportListMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace, System.Xml.Serialization.XmlAttributes atts, Int32 nestingLevel) 
System.Xml.Serialization.XmlReflectionImporter.CreateMapMember (System.Type declaringType, System.Xml.Serialization.XmlReflectionMember rmember, System.String defaultNamespace) 
System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
Rethrow as InvalidOperationException: There was an error reflecting field 'Ranks'. 
System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
Rethrow as InvalidOperationException: There was an error reflecting type 'RanksUnlocker.RanksUnlockerConfig'. 
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.Xml.Serialization.XmlAttributeOverrides overrides, System.Type[] extraTypes, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) 
System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.Type[] extraTypes) 
Rocket.Core.Assets.XMLFileAsset`1[RanksUnlocker.RanksUnlockerConfig]..ctor (System.String file, System.Type[] extraTypes, RanksUnlocker.RanksUnlockerConfig defaultInstance) 
Rocket.Core.Plugins.RocketPlugin`1[RocketPluginConfiguration]..ctor() 
RanksUnlocker.RanksUnlocker..ctor() 
UnityEngine.GameObject:.ctor(String, Type[]) 
Rocket.Core.Plugins.RocketPluginManager:loadPlugins() 
Rocket.Core.Plugins.RocketPluginManager:Start() 
+0

오류 자체는 설명입니다. 중첩 된 타입'RanksUnlocker.RanksUnlockerConfig + Message'는 public ** parameterless ** 생성자를 가져야합니다. 예를 들어 [여기] (http://stackoverflow.com/a/2498243/3744182)를 참조하십시오. – dbc

답변

1

:

[XmlArrayItem(ElementName = "Rank")] 
public List<Rank> Ranks; 
public void LoadDefaults() 
{ 
    Ranks = new List<Rank>() { 
    new Rank() { RankNumber = 0, GroupID = "Default" ,Messages = new List<Message>() { new Message("yo") , new Message("yo")}} 
    }; 
} 
public class Rank 
{ 
    public Rank() { } 

    public int RankNumber; 
    public string GroupID; 
    public List<Message> Messages; 
} 
public class Message 
{ 
    public Message(string Rankmessage) { Rankmessage = RankMessage; } 
    [XmlAttribute("RankMessage")] 
    public string RankMessage; 
} 

오류 :이 내 오류입니다. public이어야하며 0 매개 변수를 받아 들여야합니다.

XML 직렬화 프로세스에서 매개 변수를 사용하는 생성자를 처리하는 방법을 알지 못하기 때문에 이미 가지고있는 기존 생성자가 작동하지 않습니다. 기존 생성자도 유지할 수 있습니다. 매개 변수를 사용하지 않는 새 생성자를 추가하기 만하면됩니다.

+0

감사! 공용 Message() {}를 추가했습니다. – Plugin4U