【问题标题】:InvalidOperationException while serializing xml in vb.net在 vb.net 中序列化 xml 时出现 InvalidOperationException
【发布时间】:2014-06-02 05:41:35
【问题描述】:

我有以下 vb.net 代码,我试图从 XML 文件中读取内容并将其存储到自定义类列表中。当调试器尝试执行语句时,我的应用程序崩溃了

 Dim serializer As New XmlSerializer(GetType(ItemInfo))

这里的ItemInfo是我用过的一个类。如果我尝试 GetTyp(ItemInfo) 我得到所需的属性,只是 XML 序列化程序没有被初始化

我的完整代码如下:

Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim fi As System.IO.FileInfo = New IO.FileInfo(System.IO.Path.Combine(Application.StartupPath, "items.xml"))
    If fi.Exists Then
        Dim lst As New List(Of ItemInfo)
        Dim serializer As New XmlSerializer(GetType(ItemInfo)) ->Stuck here 
        Dim fs As New IO.FileStream("items.xml", IO.FileMode.Open)
        Dim reader As System.Xml.XmlReader = System.Xml.XmlReader.Create(fs)
        lst = serializer.Deserialize(reader)
        fs.Close()
    End If
End Sub

调试窗口的输出:

'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Users\vparthasarat\Documents\Visual Studio 2013\Projects\temme\temme\bin\Debug\temme.vshost.exe'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    The thread 0x1d3c has exited with code 259 (0x103).
    The thread 0x2164 has exited with code 259 (0x103).
    The thread 0x1c1c has exited with code 259 (0x103).
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Users\vparthasarat\Documents\Visual Studio 2013\Projects\temme\temme\bin\Debug\temme.exe'. Symbols loaded.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'. Symbols loaded.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Users\vparthasarat\Documents\Visual Studio 2013\Projects\temme\temme\bin\Debug\System.Windows.Forms.Calendar.dll'. Symbols loaded.
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'Microsoft.GeneratedCode'. 
    A first chance exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
    'temme.vshost.exe' (CLR v4.0.30319: temme.vshost.exe): Loaded 'C:\Windows\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll'. Module was built without symbols.
    The program '[2408] temme.vshost.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.

有什么建议可以帮助我在这里进步吗?

【问题讨论】:

  • 发布错误信息和堆栈跟踪
  • 这没有帮助。异常的错误消息和堆栈跟踪是什么?您发布的内容看起来像是从 VS 的输出窗口复制的。我正在询问异常的详细信息。没有它,我们无能为力。
  • 我真的没有在屏幕上看到任何异常......应用程序只是终止了,这就是我在输出窗口中得到的全部内容:\
  • 启用这个setting,出现异常会中断。然后你就可以得到详细信息了,更新了链接,请再次查看。
  • 上面写着A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

标签: .net xml vb.net exception-handling


【解决方案1】:

我看了下面的链接,发现出现这个异常是正常的..

XmlSerializer giving FileNotFoundException at constructor

感谢@sriram 指导我完成这个:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 2013-08-30
    • 2014-06-22
    相关资源
    最近更新 更多