2017-02-03 15 views
1

Heyo、私はユニティゲームのプラグインを作成しています(下のエラー)ので、私はおそらくメインプラグインとランクを読み込みます。私は何がエラーであるかわからないし、私はこれについての投稿を見ていない。あなたが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 **コンストラクタを持っていなければなりません。たとえば、[here](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である必要があり、ゼロパラメータを受け入れる必要があります。

既存のコンストラクタは、XMLシリアル化プロセスがパラメータを受け取るコンストラクタの処理方法を知らないため、このためには機能しません。既存のコンストラクタもそのまま使用できます。パラメータを取らない新しいコンストラクタを追加するだけです。

+0

ありがとう!私はpublic Message(){}を追加しました – Plugin4U

関連する問題