爲什麼使用選項初始化記錄時會收到錯誤?爲什麼使用選項初始化記錄時會收到錯誤?
以下行失敗我的單元測試:
let name = { First=String20("Scott"); Last=String20("Nimrod"); Suffix=None }
測試結果:
結果堆棧跟蹤:在CreateModuleViewModel.Tests.submit模塊() 結果消息:系統。 MissingMethodException:未找到方法: 'Void Name..ctor(String20,String20, Microsoft.FSharp.Core.FSharpOption`1)'。
測試如下:
module CreateModuleViewModel.Tests
open FsUnit
open NUnit.Framework
open UILogic.State
open CreateModule.UILogic
open ManageModule.Entities
[<Test>]
let ``submit module``() =
// Setup
let viewModel = CreationViewModel()
let name = { First=String20("Scott"); Last=String20("Nimrod"); Suffix=None }
let duration = { Hours=1; Minutes=30; Seconds=0 }
let moduleItem = { Author=name; Duration=duration }
// Tets
viewModel.Add(moduleItem)
// Verify
viewModel.Modules.Head = moduleItem |> should equal true
記錄定義如下:
type String20 = String20 of string
type Name = {
First:String20
Last:String20
Suffix:String20 option
}
我爲什麼會收到這個錯誤?
測試和類型定義在不同的程序集中?如果是這樣,你確定在運行時調用了提供類型定義的正確版本的dll嗎?我沒有看到與代碼相關的原因讓您遇到此錯誤。 – TheInnerLight
某些地方的程序集肯定是錯誤的版本。 –
謝謝。我的測試項目設置爲F#3.1並鎖定到該版本,而我的其他所有庫都是F#4.0。 –