vb.net做对象xml序列化学习,程序报错
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vb.net做对象xml序列化学习,程序报错相关的知识,希望对你有一定的参考价值。
vb.net做对象xml序列化学习,程序报错
错误如下:
------------------------------------------------------------------------------------------、
发生了 System.InvalidOperationException
HResult=-2146233079
Message=ConsoleApplication1.Module1 因其保护级别而不可访问。只能处理公共类型。
Source=System.Xml
StackTrace:
在 System.Xml.Serialization.TypeDesc.CheckSupported()
在 System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
在 System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference)
在 System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
在 System.Xml.Serialization.ModelScope.GetTypeModel(Type type, Boolean directReference)
在 System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
在 System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
在 ConsoleApplication1.Module1.Main() 位置 e:\ConsoleApplication1\ConsoleApplication1\Module1.vb:行号 10
InnerException:
---------------------------------------------------------------------------------
请问是什么原因
源代码如下:
Imports System.Xml
Imports System.Xml.Serialization
Module Module1
Sub Main()
Dim MYAAA As New AAA
MYAAA.A1 = "BAIGEZY"
MYAAA.A2 = "ASDFASDF"
MYAAA.A3 = "EMC"
Dim serialize As XmlSerializer = New XmlSerializer(GetType(AAA))
serialize.Serialize(Console.Out, MYAAA)
Console.ReadLine()
End Sub
Public Class AAA
Public A1 As String
Public A2 As String
Public A3 As String
Public Sub New()
End Sub
End Class
End Module
Sub Main()
Dim MYAAA As New AAA
MYAAA.A1 = "BAIGEZY"
MYAAA.A2 = "ASDFASDF"
MYAAA.A3 = "EMC"
Dim serialize As XmlSerializer = New XmlSerializer(GetType(AAA))
serialize.Serialize(Console.Out, MYAAA)
Console.ReadLine()
End Sub
End Module
'类不要套在Module中
Public Class AAA
Public A1 As String
Public A2 As String
Public A3 As String
Public Sub New()
End Sub
End Class本回答被提问者采纳
以上是关于vb.net做对象xml序列化学习,程序报错的主要内容,如果未能解决你的问题,请参考以下文章
VB.NET:使用 XDocument 在 XML 文件中添加/编辑/删除 XElement
反序列化然后序列化时保留 Xml Xsd schemaLocation