2013-08-26 53 views
2

我正在使用VS 2012 TrialFSharp.Data庫對XML進行解析。當我建立了項目中的所有類型的供應商信息變成錯誤 - 這會導致拒絕編譯 - 樣:「類型提供者」在構建項目時未識別

更新 - 輸出試圖建立(框架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 ========== 

末更新

The type 'Transaction' is not defined 

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. 

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

我有open Fharp.Data我上面的模塊和參考System.Xml.Linq

我的解決方案文件: https://dl.dropboxusercontent.com/u/74660436/temp3.zip

我的XML文件: https://dl.dropboxusercontent.com/u/74660436/KMyMoneySampleFile.xml

示例代碼:

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} 
+0

我描述了這個錯誤的一些常見原因在這裏:http://stackoverflow.com/questions/16343876/scripts- dont-recogn-fsharp-data - 它可能是其中之一... –

+0

@TomasPetricek,我終於測試了你的三個想法。不幸的是,他們沒有一個適用於我的情況。我研究了所有這三個問題,對於你指出的問題,我的一切工作都很好。我想我將不得不繼續嘗試尋找解決方案。儘管感謝您的幫助! – Jon49

+0

另一件要嘗試的是創建一個空白腳本文件並使用'#r'從那裏引用庫。然後檢查你是否在'#r'行發現了任何錯誤信息。 –

回答

2

分辨率:此問題已被固定在FSharp。數據1.1.10(nuget)。見下面的評論。


更新:我有同樣的問題,使用下面的代碼:

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) =() 

從本質上講,DomainTypes出現在智能感知,但是編譯器給出了一個Error FS0039: The type 'Ul' is not defined (FS0039)錯誤,同樣的事情「李」。


原來的答覆: 我沒有給你正確的答案,但有趣的是,如果您從XML刪除<TRANSACTIONS></TRANSACTIONS>標籤,它構建的罰款。

也就是說,改變這個:

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

這樣:

<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> 
+0

有趣。我想知道爲什麼導致這個問題。我想它確實表明它在類型提供程序方面有bug。謝謝!你確實得到了它,所以我可以編譯授予我不知道如果項目將工作或如果我拿出交易標記。我會在6天結束時給你100。我會堅持一點,但以防萬一我需要獎勵別人的觀點。不知道如何轉移積分 - 但我相信這是可能的。 – Jon49

+0

我沒有看過XML類型的提供程序來源,看看問題是否存在,但它確實值得一看。我已經設法用一個更簡單的XML例子重新創建了這個,所以我會以明確的狀態將其發佈,然後發佈它,也許有人可以在這個問題上發光。 –

+0

@TroyKershaw如果你有一個簡單的repro,請添加鏈接到GitHub上的bug報告:https://github.com/fsharp/FSharp.Data/issues/189 –

相關問題