我創建了一個簡單的生成類型提供程序,它在重新組織類型時將程序集的路徑引入程序集,以便將它們置於類型提供程序名稱空間下(如果喜歡,可以使用內部化類型)。在F#類型提供程序中發送生成的類型
鏈接到相關的代碼是在這裏 https://github.com/colinbull/Playground
現在的類型似乎是正確提供,
let[<Literal>]assemblyPath = @"D:\Appdev\Playground\SimpleLib\bin\Debug\SimpleLib.dll"
type T = Inno.InternalisingProvider<assemblyPath>
type C = T.Class1
[<EntryPoint>]
let main argv =
let c = new C()
printfn "Result: %A" c.X
System.Console.ReadLine() |> ignore
0
因爲顯示器VS中沒有任何報告的錯誤。但是,當我編譯這個程序集時,IL看起來會錯誤地發出以下錯誤。在給定的samples pack生成的類型給出
Error 1: A problem occurred writing the binary 'obj\Debug\TypeProviders.Tests.exe': Error in pass3 for type Program, error: Error in GetMethodRefAsMethodDefIdx for mref = ".ctor", error: Exception of type 'Microsoft.FSharp.Compiler.AbstractIL.ILBinaryWriter+MethodDefNotFound' was thrown. FSC 1 1 TypeProviders.Tests
實例似乎不具有任何限定StaticParameters
需要被返回與所提供的類型名稱類型。在這種情況下,我如何在所提供的程序集中發出類型?目前,我做了以下
let provideAssembly (reqType:ProvidedTypeDefinition) assemblyPath =
let name = Path.GetFileName(assemblyPath)
let providedAssembly = ProvidedAssembly.RegisterGenerated(assemblyPath)
for t in providedAssembly.GetExportedTypes() do
let ty = createGeneratedType t
ty.SetAssembly(providedAssembly)
reqType.AddMember(ty)
reqType
在此先感謝
上帝,我很愚蠢的,我試過是第一,但把直接引用生成的類型在我的代碼,所以我當時正在收到編譯錯誤。課程學習 - >正確地閱讀錯誤消息。再次感謝 – 2013-02-26 18:22:00