【问题标题】:XmlTextWriter not working in my VB .ASP page LiteralXmlTextWriter 在我的 VB .ASP 页面中不起作用
【发布时间】:2011-01-27 12:19:27
【问题描述】:

当我尝试在我的 VB aspx 页面中使用 XmlTextWriter 时出现以下错误

描述:期间发生错误 所需资源的编译 来服务这个请求。请查阅 以下具体错误详情 并修改您的源代码 适当地。

编译器错误消息:BC30002:类型 'XmlTextWriter' 未定义。

我使用的代码在 文字内的 .aspx 页面内

Dim w As XmlTextWriter = New XmlTextWriter("myxmlfile.xml")

我的页眉也是这样的

谁能解释一下原因?

【问题讨论】:

    标签: asp.net vb.net literals xmltextwriter


    【解决方案1】:

    如 MSDN 中所述,XmlTextWriter 类是在 System.Xml 命名空间中定义的:

    XmlTextWriter

    所以,你应该添加

    导入 System.Xml

    指向代码隐藏文件头部的指令,并确保您的 Web 应用程序引用了 System.xml.dll。

    【讨论】:

    • 您好 DevExpress 团队,我没有使用隐藏代码,这是避免隐藏代码的框架的一部分。我在页面中将命名空间添加为<%@ Import Namespace="System.Xml" %>,但它仍然无法正常工作,有什么线索吗?
    • 如果引用了 System.xml.dll 程序集,您应该可以使用以下代码: Dim w As New System.Xml.XmlTextWriter("myxmlfile.xml")
    • 我认为您的项目中有一个名为“XML”的替代类或命名空间?
    【解决方案2】:

    XmlTextWriter 实际上有两个值,试试这个...

    <%@ Page Language="vb" AutoEventWireup="false" Trace="True" EnableViewState="True" %> 
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Xml" %>
    <% Dim w As New XmlTextWriter("myxmlfile.xml", System.Text.Encoding.ASCII)%>
    

    如果这不起作用,也许你有一个覆盖 System.XML 类的全局 XML 命名空间,在这种情况下尝试

    <%@ Page Language="vb" AutoEventWireup="false" Trace="True" EnableViewState="True" %> 
    <% Dim w As New System.Xml.XmlTextWriter("myxmlfile.xml", System.Text.Encoding.ASCII)%>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-29
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      相关资源
      最近更新 更多