Search code examples
asp.netvb.netliteralsxmltextwriter

XmlTextWriter not working in my VB .ASP page Literal


I'm getting the error below when I try usign the XmlTextWriter in my VB aspx page

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'XmlTextWriter' is not defined.

The code I'm using is within the .aspx page inside a <% %> literal

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

My page header is also like this

<%@ Page Language="vb" AutoEventWireup="false" Trace="True" EnableViewState="True" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Xml" %>

Can anybody explain why?


Solution

  • As mentioned in the MSDN, the XmlTextWriter class is defined in the System.Xml namespace:

    XmlTextWriter

    So, you should add the

    Imports System.Xml

    directive to the head of the code behind file and also make certain that the System.xml.dll is referenced by your web application.