What version of F# Data are you using? Have you tried with latest 2.x? If it still doesn't work, please submit an issue on https://github.com/fsharp/FSharp.Data/issues
F# XML Type provider and optional types
-
26-06-2023 - |
Question
Using the XML type provider on these two functionally equivalent XML files gives different results with the XML type provider.
XML File 1:
<?xml version="1.0" encoding="utf-8"?>
<params>
<mode >
<reg >0</reg>
</mode>
<mode >
<reg >1.7976931348623157E+308</reg>
</mode>
<mode></mode>
</params>
XML File 2:
<?xml version="1.0" encoding="utf-8"?>
<params>
<mode>
</mode>
<mode >
<reg >0</reg>
</mode>
<mode >
<reg >1.7976931348623157E+308</reg>
</mode>
</params>
Note that the only difference is that the empty "mode" is at the end of one file and the start of the other.
The test F# code looks like this:
type Test = XmlProvider<""".\test.xml""">
type Test2 = XmlProvider<""".\test2.xml""">
let xml = Test.GetSample()
let list1 = [for mode in xml.Modes -> mode.Reg]
let xml2 = Test2.GetSample()
let list2 = [for mode in xml2.Modes -> mode.Reg]
list1 has type "Option <float> list" as you would expect. But list2 has type "float list", which is incorrect and causes a runtime exception.
Why does this happen and how can do I avoid this issue?
Solution
OTHER TIPS
This is fixed in latest F# Data version
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow