Why do I get this error when I write OPTION STRICT ON? with this code

piscis

Regular
Joined
Jun 30, 2003
Messages
54
Why do I get this error when I write OPTION STRICT ON? with this code

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
XmlSchema11.ReadXml(Application.StartupPath & "\..\Data\GRID.XML", FileMode.Open)
End Sub

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
XmlSchema11.WriteXml(Application.StartupPath & "\..\Data\GRID.XML", FileMode.Open)
End Sub

I get this error:

C:\Documents and Settings\Telemetrika.Com\Desktop\XMLGrid\Form1.vb(111): Overload resolution failed because no accessible 'ReadXml' can be called with these arguments:
'Public Function ReadXml(fileName As String, mode As System.Data.XmlReadMode) As System.Data.XmlReadMode': Option Strict On disallows implicit conversions from 'System.IO.FileMode' to 'System.Data.XmlReadMode'.
'Public Function ReadXml(reader As System.IO.TextReader, mode As System.Data.XmlReadMode) As System.Data.XmlReadMode': Value of type 'String' cannot be converted to 'System.IO.TextReader'.
'Public Function ReadXml(reader As System.IO.TextReader, mode As System.Data.XmlReadMode) As System.Data.XmlReadMode': Option Strict On disallows implicit conversions from 'System.IO.FileMode' to 'System.Data.XmlReadMode'.
'Public Function ReadXml(stream As System.IO.Stream, mode As System.Data.XmlReadMode) As System.Data.XmlReadMode': Value of type 'String' cannot be converted to 'System.IO.Stream'.
'Public Function ReadXml(stream As System.IO.Stream, mode As System.Data.XmlReadMode) As System.Data.XmlReadMode': Option Strict On disallows implicit conversions from 'System.IO.FileMode' to 'System.Data.XmlReadMode'.
'Public Function ReadXml(reader As System.Xml.XmlReader, mode As System.Data.XmlReadMode) As System.Data.XmlReadMode': Value of type 'String' cannot be converted to 'System.Xml.XmlReader'.
'Public Function ReadXml(reader As System.Xml.XmlReader, mode As System.Data.XmlReadMode) As System.Data.XmlReadMode': Option Strict On disallows implicit conversions from 'System.IO.FileMode' to 'System.Data.XmlReadMode'.
 
W/ Option Strict On, an implicit conversion between two types that may result to the truncation of data during the conversion process will flag a compiler error. In your case, instead of using FileMode.Open, use the equivalent value from the System.Data.XmlReadMode enumeration.
 
Change your calls to ReadXml w/c is currently along the lines of:

XmlSchema11.ReadXml(<xml_file>, FileMode.Open)

to

XmlSchema11.ReadXml(<xml_file>, XMLReadMode enumeration member)

where XMLReadMode enumeration member is one of valid members of the XMLReadMode enumeration, e.g., XMLReadMode.Auto, depending on what you're trying to accomplish; refer to http://msdn.microsoft.com/library/d...tml/frlrfsystemdataxmlreadmodeclasstopic.asp.

And let the Option Strict On remain as recommended by mutant for more robust code.
 
Back
Top