fsprojects / FSharp.Data

F# Data: Library for Data Access
https://fsprojects.github.io/FSharp.Data
Other
816 stars 288 forks source link

XmlProvider fails to load documents in mono on OSX #855

Closed rojepp closed 9 years ago

rojepp commented 9 years ago

Running this script in FSI in Xamarin Studio:

#r "System.Data"
#r "System.Xml"
#r "System.Xml.Linq"
#r "../packages/FSharp.Data.2.2.3/lib/net40/FSharp.Data.dll"

open FSharp.Data
open System.IO
type t = XmlProvider<"./paymentsample.xml">

let dir = __SOURCE_DIRECTORY__ + "/files"
let files = Directory.EnumerateFiles dir

for f in files do
  let x = t.Load f
  for pay in x.Body.PaymentBatch.Payments do
    printfn "%A" pay

gives this stacktrace:

System.Xml.XmlException: Document element did not appear. Line 1, position 1. at Mono.Xml2.XmlTextReader.Read () [0x00000] in :0 at System.Xml.XmlTextReader.Read () [0x00000] in :0 at Mono.Xml.XmlFilterReader.Read () [0x00000] in :0 at System.Xml.Linq.XDocument.ReadContent (System.Xml.XmlReader reader, LoadOptions options) [0x00000] in :0 at System.Xml.Linq.XDocument.LoadCore (System.Xml.XmlReader reader, LoadOptions options) [0x00000] in :0 at System.Xml.Linq.XDocument.Load (System.IO.TextReader textReader, LoadOptions options) [0x00000] in :0 at System.Xml.Linq.XDocument.Parse (System.String text, LoadOptions options) [0x00000] in :0 at System.Xml.Linq.XDocument.Parse (System.String text) [0x00000] in :0 at FSharp.Data.Runtime.BaseTypes.XmlElement.Create (System.IO.TextReader reader) [0x00000] in :0 at FSI_0002+results@15.GenerateNext (IEnumerable1& next) [0x00000] in <filename unknown>:0 at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase1[System.Boolean].MoveNextImpl () [0x00000] in :0 at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase1[System.Boolean].System-Collections-IEnumerator-MoveNext () [0x00000] in <filename unknown>:0 at Microsoft.FSharp.Collections.SeqModule.ToList[Boolean] (IEnumerable1 source) [0x00000] in :0 at <StartupCode$FSI_0002>.$FSI_0002.main@ () [0x00000] in :0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0

Note that this code works fine on Windows/.Net.

Sample xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<BizTalk xmlns="urn:schemas-biztalk-org:biztalk/BizTalkv1_0.xml">
  <Route>
    <From />
    <To />
  </Route>
  <Body>
    <PaymentBatch xmlns="urn:schemas-biztalk.org:T4_XMLPaymentSchema.xml">
      <Batch RecordNumber="0.1" BatchNumber="115775415" BatchDate="2015-05-13" />
      <Payment>
        <HEADER RecordNumber="1.1" PaymentDate="2015-02-03" SSN="yyy" TotalPayment="600" CurrencyUnit="SEK" PaymentMethod="2" Quantity="1" PaymentReference="1014/5" ChargeClinic="5415" />
        <PayerDetail RecordNumber="1.2" PayerName="Name Name" Address_2="Nowhere" Town="SomeTown" PostCode="54321" AccountID="1014/5" PayerForename="Name" PayerSurname="Name" AddressType="HA" />
        <InvoiceSet>
          <Invoice RecordNumber="1.3" InvoiceID="1014/5" InvoiceDate="2015-05-12" TotalOnInvoice="600" />
        </InvoiceSet>
        <FOOTER RecordNumber="1.4" />
      </Payment>
      <Payment>
        <HEADER RecordNumber="76.1" PaymentDate="2015-05-12" SSN="xxx" TotalPayment="885" CurrencyUnit="SEK" PaymentMethod="3" Quantity="1" PaymentReference="1014/5" ChargeClinic="5415" />
        <PayerDetail RecordNumber="76.2" PayerName="Some name" Address_2="Some address" Town="Some town" PostCode="12345" AccountID="123/5" PayerForename="Name" PayerSurname="Name" AddressType="HA" />
        <InvoiceSet>
          <Invoice RecordNumber="76.3" InvoiceID="1014/5" InvoiceDate="2015-05-12" TotalOnInvoice="885" />
        </InvoiceSet>
        <FOOTER RecordNumber="76.4" />
      </Payment>
    </PaymentBatch>
  </Body>
</BizTalk>
rojepp commented 9 years ago

My bad, I hope no-one wasted time on this. On the mac, there was an extra file, .DS_Store and I forgot to filter to *.xml. :flushed: