Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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'.

Posted
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.
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...