0

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?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
William Calleja
  • 4,055
  • 11
  • 41
  • 51

2 Answers2

2

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.

DevExpress Team
  • 11,338
  • 2
  • 24
  • 23
  • Hi DevExpress Team, I'm not using code behind, this is part of a framework that avoids code behind. I'm adding the namespace in the page as `<%@ Import Namespace="System.Xml" %>` and it is still not working, any clue as to why? – William Calleja Feb 07 '11 at 14:39
  • 1
    If the System.xml.dll assembly is referenced, you should be able to use the following code: Dim w As New System.Xml.XmlTextWriter("myxmlfile.xml") – DevExpress Team Feb 07 '11 at 14:41
  • I think you have an alternative class or namespace named "XML" in your project? – digiguru Feb 14 '11 at 14:44
0

XmlTextWriter actually takes two values, try this...

<%@ 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)%>

If that doesn't work, perhaps you have a global XML namespace that is overriting the System.XML class, in which case try

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