本文介绍了无法将类型为“System .__ ComObject”的COM对象强制转换为类类型“System.Xml.XmlDocument”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个com组件,我已在我的vb.net项目中注册并添加为参考。在尝试访问其方法时,我收到上述错误。需要你的帮助。



以下是代码片段



Dim testResult As Object = Nothing

Dim oxmldom As Object

Dim sXML As String

sXML =

testResult = CreateObject(ComReferenceDLL.iInterface1 )

oxmldom = CreateObject(MSXML2.DOMDocument)

oxmldom = testResult.SampleMethod(sXML)





这里ComReferenceDLL是COM组件。

I have a com component, which i have registered and added as reference in my vb.net project. While trying to access its method I am getting the above error. Need your help.

Below is the code snippet

Dim testResult As Object = Nothing
Dim oxmldom As Object
Dim sXML As String
sXML = ""
testResult = CreateObject("ComReferenceDLL.iInterface1")
oxmldom = CreateObject("MSXML2.DOMDocument")
oxmldom = testResult.SampleMethod(sXML)


Here ComReferenceDLL is the COM component.

推荐答案

  1. 使用 System.Xml.XmlDocument 类。它实现了DOM接口;如果文档的大小不是太大,这种方式是最简单和最好的。
    参见 []。
  2. 使用类 System.Xml.XmlTextReader ;这是最快的阅读方式,特别是你需要跳过一些数据。
    参见 []。
  3. 使用类 System.Xml.Linq.XDocument ;这是类似于 XmlDocument 的最合适的方式,支持LINQ to XML Programming。
    参见 [], []。
  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the class System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].





-SA


这篇关于无法将类型为“System .__ ComObject”的COM对象强制转换为类类型“System.Xml.XmlDocument”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:40