2

I'm using VS 2012 Trial and the FSharp.Data library for XML parsing. When I build the project all the type provider information turns into errors - which results in refusal to compile - like:

Update - Output after trying to build (Framework 4.5)

------ Build started: Project: temp3, Configuration: Debug Any CPU ------
C:\Program Files (x86)\Microsoft SDKs\F#\3.0\Framework\v4.0\fsc.exe 
-o:obj\Debug\temp3.dll -g --debug:full --noframework --define:DEBUG 
--define:TRACE --doc:bin\Debug\temp3.XML --optimize- --tailcalls- 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\3.0\Runtime\v4.0\FSharp.Core.dll" 
-r:C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\packages\FSharp.Data.1.1.9\lib\net40\FSharp.Data.DesignTime.dll 
-r:C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\packages\FSharp.Data.1.1.9\lib\net40\FSharp.Data.dll 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Numerics.dll" 
-r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.Linq.dll" 
--target:library --warn:3 --warnaserror:76 --vserrors --validate-type-providers 
--LCID:1033 --utf8output --fullpaths --flaterrors --subsystemversion:6.00 
--highentropyva+ "C:\Users\Laura\AppData\Local\Temp\.NETFramework,Version=v4.5.AssemblyAttributes.fs" Library1.fs 
C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\temp3\Library1.fs(31,122): 
error FS0039: The type 'Transaction' is not defined
C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\temp3\Library1.fs(32,21): 
error FS0072: Lookup on object of indeterminate type based on information 
prior to this program point. 
A type annotation may be needed prior to this program point to constrain 
the type of the object. This may allow the lookup to be resolved.
C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\temp3\Library1.fs(33,85): 
error FS0039: The field, constructor or member 'Postdate' is not defined
C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\temp3\Library1.fs(34,38): 
error FS0752: The operator 'expr.[idx]' has been used on an object of indeterminate 
type based on information prior to this program point. Consider adding 
further type constraints
C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\temp3\Library1.fs(34,74): 
error FS0752: The operator 'expr.[idx]' has been used on an object of indeterminate type 
based on information prior to this program point. Consider adding further type 
constraints
C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\temp3\Library1.fs(34,118): 
error FS0752: The operator 'expr.[idx]' has been used on an object of indeterminate type 
based on information prior to this program point. Consider adding further type 
constraints
C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\temp3\Library1.fs(35,39):     
error FS0752: The operator 'expr.[idx]' has been used on an object of indeterminate type 
based on information prior to this program point. Consider adding further type 
constraints
C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\temp3\Library1.fs(35,68): 
error FS0752: The operator 'expr.[idx]' has been used on an object of indeterminate type 
based on information prior to this program point. Consider adding further type 
constraints
C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\temp3\Library1.fs(35,93): 
error FS0752: The operator 'expr.[idx]' has been used on an object of indeterminate type 
based on information prior to this program point. Consider adding further type 
constraints
C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp3\temp3\Library1.fs(35,125): 
error FS0752: The operator 'expr.[idx]' has been used on an object of indeterminate type 
based on information prior to this program point. Consider adding further type 
constraints
Done building project "temp3.fsproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

End update

The type 'Transaction' is not defined

and

Look up on object of indeterminate type based on information prior to this 
program point. A type annotation may be needed prior to this program point
to constrain the type of the object. This may allow the lookup to be resolved.

and

The field, constructor or member 'Postdate' is not defined

I have open Fharp.Data above my module and reference System.Xml.Linq.

My Solution File: https://dl.dropboxusercontent.com/u/74660436/temp3.zip

My XML File: https://dl.dropboxusercontent.com/u/74660436/KMyMoneySampleFile.xml

Sample code:

namespace KMyMoney
open System.IO
open System.IO.Compression
open FSharp.Data

module Read =

    let decompressFileAndRead sourceFile = (new StreamReader(new GZipStream(File.OpenRead(sourceFile), CompressionMode.Decompress))).ReadToEnd()

    type KMyMoney = XmlProvider<"KMyMoneySampleFile.xml">

    let kMyMoney (sourceData:string) = KMyMoney.Load(sourceData)

    let getAccountNames sourceData = 
        (kMyMoney sourceData).Accounts.GetAccounts()
        |> Array.map (fun acc -> acc.Id, acc.Name)
        |> Map.ofArray

    let getPayeeNames sourceData =
        (kMyMoney sourceData).Payees.GetPayees()
        |> Array.map (fun p -> p.Id, p.Name)
        |> Map.ofArray

    type TransactionNew = {Id:string; Commodity:string; Date:System.DateTime; Account:string option; Amount:float; Payee:string option
                        ; Category:string option; Number:string; Memo:string; Shares:float}

    let amount (value:string) =
        let divideArray (values:float[]) = values.[0]/values.[1]
        value.Split("/".[0]) |> Array.map float |> divideArray

    let splitTransaction (accNames:Map<string,string>) (payeeNames:Map<string,string>) (transaction:KMyMoney.DomainTypes.Transaction) =
        let split = transaction.Splits.GetSplits()
        {Id = transaction.Id; Commodity = transaction.Commodity; Date = transaction.Postdate
        ; Account = accNames.TryFind(split.[0].Account); Amount = amount split.[0].Value; Payee = payeeNames.TryFind(split.[1].Payee)
        ; Category = accNames.TryFind(split.[1].Account); Number = split.[0].Number; Memo = split.[0].Memo; Shares = amount split.[0].Shares}
Jon49
  • 4,444
  • 4
  • 36
  • 73
  • I described some common causes of this error here: http://stackoverflow.com/questions/16343876/scripts-dont-recognize-fsharp-data - it might be one of them... – Tomas Petricek Aug 27 '13 at 00:31
  • @TomasPetricek, I finally tested your three ideas. Unfortunately, none of them applied to my situation. I looked into all three and everything was working fine on my side for the issues you point out. I guess I'll have to keep trying to find a solution. Thanks for your help though! – Jon49 Aug 27 '13 at 20:51
  • Another thing to try is to create a blank script file and use `#r` to reference the library from there. Then check if you get any error message on the `#r` line.. – Tomas Petricek Aug 27 '13 at 23:03
  • Another possible problem could be if the type provider DLL is located on some network share... – Tomas Petricek Aug 27 '13 at 23:03
  • @TomasPetricek, It's just on my single computer. I'll try the #r and see what happens. – Jon49 Aug 27 '13 at 23:13
  • OK, I'm getting the same error: stdin(33,118): error FS0039: The type 'Transaction' is not defined > C:\Users\Laura\BTSync\Dropbox\VisualStudio\Projects\temp\temp\MReadKMyMoney.fs(34,126): error FS0039: The type 'Transaction' is not defined – Jon49 Aug 28 '13 at 00:06
  • I tried this using the latest version of the XML type provider & the sample file you provided and it works fine for me - so there must be some problem with loading the type provider. Are you sure you're calling F# 3.0 compiler? – Tomas Petricek Aug 29 '13 at 19:56
  • I uninstalled FSharp 2.0 hoping this would fix the problem since I read that 2.0 had problems with 1.0. I noticed That I didn't catch the first output which says warnaserror76. So I will post the entire line in my question. Not sure if I should just uninstall all versions of VS and then reinstall VS2012. Seems drastic but I'm not sure what else to do. – Jon49 Aug 31 '13 at 23:30
  • From the o/p I posted it appears I am using F# 3.0 – Jon49 Aug 31 '13 at 23:42
  • @TomasPetricek, Would you be up for testing my test solution file? I've been trying to find a solution for this but haven't been able to find anything yet :-/ https://dl.dropboxusercontent.com/u/74660436/temp3.zip – Jon49 Sep 04 '13 at 22:40
  • Thanks for sharing - I was able to reproduce this, so I suppose it might be some bug in the XML provider. I'll investigate... – Tomas Petricek Sep 05 '13 at 04:10

1 Answers1

2

Resolution: This issue has been fixed in FSharp.Data 1.1.10 (nuget). See comments below.


Update: I have the same issue using the following code:

module XmlTypeProviderIssue

open System
open FSharp.Data

type Html = XmlProvider<"""
<div>
    <span>
        <ul>
            <li/>          
        </ul>
    </span>  
</div>""">

let html = Html.GetSample()

// Div is defined
let divWorks (div:Html.DomainTypes.Div) = ()

// Span is defined
let spanWorks (span:Html.DomainTypes.Span) = ()

// Ul is not
let ulBreaks (ul:Html.DomainTypes.Ul) = ()

// and neither is Li
let liBreaks (li:Html.DomainTypes.Li) = ()

Essentially, DomainTypes appear in intellisense, but the compiler gives an Error FS0039: The type 'Ul' is not defined (FS0039) error, and the same thing for 'Li'.


Original answer: I haven't got a proper answer for you, but interestingly, if you remove the <TRANSACTIONS></TRANSACTIONS> tag from your XML, it builds fine.

That is, change this:

<TRANSACTIONS count="2">
  <TRANSACTION postdate="2005-01-05" commodity="USD" memo="" id="T000000000000001557" entrydate="2013-07-03">
   <SPLITS>
    <SPLIT payee="P000015" reconcileflag="0" shares="-121041/100" reconciledate="" action="Withdrawal" bankid="" account="A000106" number="" value="-121041/100" memo="" id="S0001"/>
    <SPLIT payee="P000015" reconcileflag="0" shares="121041/100" reconciledate="" action="" bankid="" account="A000006" number="" value="121041/100" memo="" id="S0002"/>
   </SPLITS>
  </TRANSACTION>
  <TRANSACTION postdate="2005-01-05" commodity="USD" memo="" id="T000000000000001557" entrydate="2013-07-03">
   <SPLITS>
    <SPLIT payee="P000015" reconcileflag="0" shares="-121041/100" reconciledate="" action="Withdrawal" bankid="" account="A000106" number="" value="-121041/100" memo="" id="S0001"/>
    <SPLIT payee="P000015" reconcileflag="0" shares="121041/100" reconciledate="" action="" bankid="" account="A000006" number="" value="121041/100" memo="" id="S0002"/>
   </SPLITS>
  </TRANSACTION>
</TRANSACTIONS>

to this:

<TRANSACTION postdate="2005-01-05" commodity="USD" memo="" id="T000000000000001557" entrydate="2013-07-03">
   <SPLITS>
    <SPLIT payee="P000015" reconcileflag="0" shares="-121041/100" reconciledate="" action="Withdrawal" bankid="" account="A000106" number="" value="-121041/100" memo="" id="S0001"/>
    <SPLIT payee="P000015" reconcileflag="0" shares="121041/100" reconciledate="" action="" bankid="" account="A000006" number="" value="121041/100" memo="" id="S0002"/>
   </SPLITS>
  </TRANSACTION>
  <TRANSACTION postdate="2005-01-05" commodity="USD" memo="" id="T000000000000001557" entrydate="2013-07-03">
   <SPLITS>
    <SPLIT payee="P000015" reconcileflag="0" shares="-121041/100" reconciledate="" action="Withdrawal" bankid="" account="A000106" number="" value="-121041/100" memo="" id="S0001"/>
    <SPLIT payee="P000015" reconcileflag="0" shares="121041/100" reconciledate="" action="" bankid="" account="A000006" number="" value="121041/100" memo="" id="S0002"/>
   </SPLITS>
</TRANSACTION>
Troy Kershaw
  • 590
  • 3
  • 8
  • Interesting. I wonder why that caused the problem. I guess it does show that it is on the Type Provider side that has the bug. Thanks! You did get it so I could compile granted I don't know if the project will work or not if I take out the Transactions tag. I'll give you the 100 at the end of the 6 days. I'll hold on a little bit though just in case I need to award others points too. Not sure how to transfer points - I'm sure it is possible though. – Jon49 Sep 05 '13 at 19:07
  • I haven't had a look at the XML type provider source to see if the problem's there, but it certainly worth looking. I've managed to recreate this with a simpler XML example, so I'll get it in a clear state, post it up and maybe someone can shine some light on the issue. – Troy Kershaw Sep 05 '13 at 21:48
  • @TroyKershaw If you have a simple repro, please add the link to the bug report on GitHub: https://github.com/fsharp/FSharp.Data/issues/189 – Tomas Petricek Sep 06 '13 at 04:07
  • @TomasPetricek [I've added a Gist](https://gist.github.com/troykershaw/6459750) to the GitHub issue above. – Troy Kershaw Sep 06 '13 at 05:11
  • @TroyKershaw Thanks, I'll have a look! – Tomas Petricek Sep 07 '13 at 04:49
  • 1
    @Jon49 The Github issue above has a fix. I'm not sure when there will be a release on Nuget, so you might have to build from source for now. – Troy Kershaw Sep 12 '13 at 21:35
  • This bugfix has been released in FSharp.Data 1.1.10 http://www.nuget.org/packages/FSharp.Data/1.1.10 – Gustavo Guerra Sep 12 '13 at 22:56
  • Wow, you guys move fast! – Troy Kershaw Sep 12 '13 at 23:08