序列化程序:nullreferenceexception:我在寻找什么?

时间:2019-07-15 19:48:05

标签: c# nullreferenceexception

我尝试序列化ViewModel,但是某些属性似乎为null。但是哪个呢?它可以是ViewModel的道具,也可以是ViewModel中使用的类的道具,不是吗?我如何找出空值在哪里?

我不知道在哪里看。 我是否应该在捕获中编写一些例程来分析MainViewModel对象

错误发生在

XmlSerializer serializer = new XmlSerializer(typeof(MainViewModel));

这是我的StackTrace:

at System.Xml.Serialization.CodeGenerator.GetVariableType(Object var)
at System.Xml.Serialization.SourceInfo.InternalLoad(Type elementType, Boolean asAddress)
at System.Xml.Serialization.XmlSerializationILGen.ILGenLoad(String source, Type type)
at System.Xml.Serialization.XmlSerializationReaderILGen.WriteMemberBegin(Member[] members)
at System.Xml.Serialization.XmlSerializationReaderILGen.WriteArray(String source, String arrayName, ArrayMapping arrayMapping, Boolean readOnly, Boolean isNullable, Int32 fixupIndex, Int32 elementIndex)
at System.Xml.Serialization.XmlSerializationReaderILGen.WriteElement(String source, String arrayName, String choiceSource, ElementAccessor element, ChoiceIdentifierAccessor choice, String checkSpecified, Boolean checkForNull, Boolean readOnly, Int32 fixupIndex, Int32 elementIndex)
at System.Xml.Serialization.XmlSerializationReaderILGen.WriteMemberElementsIf(Member[] members, Member anyElement, String elementElseString)
at System.Xml.Serialization.XmlSerializationReaderILGen.WriteMemberElements(Member[] members, String elementElseString, String elseString, Member anyElement, Member anyText)
at System.Xml.Serialization.XmlSerializationReaderILGen.WriteArray(String source, String arrayName, ArrayMapping arrayMapping, Boolean readOnly, Boolean isNullable, Int32 fixupIndex, Int32 elementIndex)
at System.Xml.Serialization.XmlSerializationReaderILGen.WriteElement(String source, String arrayName, String choiceSource, ElementAccessor element, ChoiceIdentifierAccessor choice, String checkSpecified, Boolean checkForNull, Boolean readOnly, Int32 fixupIndex, Int32 elementIndex)
at System.Xml.Serialization.XmlSerializationReaderILGen.WriteMemberElementsIf(Member[] members, Member anyElement, String elementElseString)
at System.Xml.Serialization.XmlSerializationReaderILGen.WriteMemberElements(Member[] members, String elementElseString, String elseString, Member anyElement, Member anyText)
at System.Xml.Serialization.XmlSerializationReaderILGen.WriteLiteralStructMethod(StructMapping structMapping)
at System.Xml.Serialization.XmlSerializationReaderILGen.GenerateMethod(TypeMapping mapping)
at System.Xml.Serialization.XmlSerializationILGen.GenerateReferencedMethods()
at System.Xml.Serialization.XmlSerializationReaderILGen.GenerateEnd(String[] methods, XmlMapping[] xmlMappings, Type[] types)
at System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at CableCalc.ViewModel.Calculation.CopyClipboard() in E:\Users\erik\Documents\Visual Studio 2017\Projects\CableCalc23\CableCalc\ViewModel\Commands\PasteClipboardCommand.cs:line 36

0 个答案:

没有答案