piscis Posted July 30, 2003 Posted July 30, 2003 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'. Quote
JABE Posted July 30, 2003 Posted July 30, 2003 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. Quote
*Experts* mutant Posted July 30, 2003 *Experts* Posted July 30, 2003 You should ALWAYS have Option Strict On. If you just started using it you should in every project. Quote
piscis Posted July 30, 2003 Author Posted July 30, 2003 JABE: How should I re-write the Load Form event then? Quote
JABE Posted July 31, 2003 Posted July 31, 2003 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/default.asp?url=/library/en-us/cpref/html/frlrfsystemdataxmlreadmodeclasstopic.asp. And let the Option Strict On remain as recommended by mutant for more robust code. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.