Mat*_*ias 6 f# azure azure-functions
我有一个F#Azure功能失败,以一种奇怪的方式,并不知道如何解决问题.我在下面创建了一个实际案例的最小重复.手动触发测试功能,并使用FSharp.Compiler.Service作为依赖项,project.json如下所示:
{
"frameworks": {
"net46":{
"dependencies": {
"FSharp.Compiler.Service": "11.0.6"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
该run.fsx文件如下所示:
open System
open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.Ast
open Microsoft.FSharp.Compiler.Interactive.Shell
let Run(input: string, log: TraceWriter) =
// code here that uses FsiEvaluationSession
// and runs just fine
log.Info "I RAN"
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.困扰我的部分是,如果我在上面添加以下功能Run,
// same dependencies as before
open Microsoft.FSharp.Compiler.Interactive.Shell
let foo (longIdent:LongIdent) =
// version 1
// "FOO"
// version 2
// longIdent.ToString ()
// version 3
longIdent |> List.map string
let Run(input: string, log: TraceWriter) =
// same as before
Run Code Online (Sandbox Code Playgroud)
单独取消注释第1部分工作正常,单独的第2部分单独工作正常,取消注释第3部分会导致地狱破裂.该函数编译,但运行它会导致以下异常:
Exception while executing function: Functions.fsc-1. mscorlib: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Run Code Online (Sandbox Code Playgroud)
......这让我感到困惑,因为
foo 在任何地方都没有被称为 LongIdent,所以这种类型似乎不是问题的根源. 任何关于如何处理问题的建议,以及问题本身可能是什么,都将非常感激 - 我甚至不知道从哪里开始,并且相同的代码在本地脚本中运行得非常好.
我认为原因是 Azure Functions SDK 依赖于FSharp.Compiler.Service (FCS) 版本 9.0.1。这意味着当您尝试加载不同版本的 FCS 时,您将获得已加载的版本 9.0.1。
只要您使用的 FCS 版本的公共 API 与版本 9.0.1 的公共 API 匹配,这就可以工作,但是当存在差异时,它会崩溃,因为您的代码假定公共 API 看起来不同。我想这可能会触发这里的问题,尽管我不是 100% 确定如何(可能LongIdent现在与版本 9.0.1 中的情况不同?)
FAKE 也曾经发生过同样的问题,它也捆绑了 FCS 并阻止加载不同版本。选项之一是重命名程序集以避免冲突。
| 归档时间: |
|
| 查看次数: |
1083 次 |
| 最近记录: |