c# - 在 Azure 上运行时 F# 中的异常

标签 c# f# azure z3

我们有一个在 Azure 中运行的 C# Web 角色,并且 C# 项目调用我们使用应用程序部署的 F# dll 中的代码。

当我们使用本地 Azure 模拟器在本地运行时,我们的 F# 代码将被调用并运行良好。当它在云中的 Azure 中运行时,我们的 F# 代码在某个时刻失败并出现以下异常:

Failed to parse x's function: var(2).Exception: System.IO.FileNotFoundException: Could not load file or assembly 'FSharp.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'FSharp.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.FSharp.Text.Lexing.LexBuffer1.FromArray(char[] s) at Microsoft.FSharp.Text.Lexing.LexBuffer1.FromString(String s) at [email protected](IEnumerable`1& next)
WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. .Will use default function.

我们发现一些帖子表明这是因为:

Windows Azure runs applications in partial trust, as part of sandboxing their execution. However, the F# core libraries are currently installed into the GAC, but do not have the AllowPartialTrustedCallers attribute. So when building F# applications to be run in Azure, the F# libraries must be statically linked using --standalone. The provided templates take care of this, but you'll notice the following side-affects: • Longer than usual compile times • Large set of references • A dummy reference to "RDManaged.dll"

http://archive.msdn.microsoft.com/fsharpazure

为了尝试解决这个问题,我们遵循以下建议,并将 –standalone 标志放入 F# 库的构建配置中。

http://www.42spikes.com/post/F-and-Azure.aspx

但是,F# 库不使用此标志进行编译。我们收到此构建错误:

Error 3 A problem occurred writing the binary 'obj\Debug\Analyzer.dll': Error in pass2 for type Microsoft.FSharp.Text.StructuredFormat.Joint, error: One of your modules expects the type 'System.Collections.IStructuralEquatable' to be defined within the module being emitted. You may be missing an input file FSC 1 1
Analyzer

此构建错误是否是由于我们的 F# 项目的依赖项造成的?它引用 FSharp.PowerPack.dll 和 Microsoft.Z3.dll,以及我们解决方案中的另一个 C# 库,AnalyzerCommon.dll(它只包含我们的 F# 和 C# 代码实现的通用接口(interface))。

有趣的是,F# 代码被调用并运行良好,直到它到达代码的特定部分 - 使用 FSharp.PowerPack.dll 的公式解析器。

任何提示将不胜感激。

谢谢,山姆

最佳答案

您必须在 WebRole 应用程序中显式引用所有必需的程序集,并将“复制本地”属性设置为“True”。看看这个mine blog post 。我首先提到的是复制本地。

部分代码运行而其他部分不运行的原因是 JIT 编译器。一切都运行良好,直到您遇到需要缺少程序集的代码。一旦您将所有必需的程序集显式添加为引用并将“复制本地”设置为“True”,就不会出现“找不到文件”异常。

如果有帮助请跟进!

编辑

默认情况下,Windows Azure 在完全信任模式下运行。我认为从 SDK 1.3 开始。您可以通过右键单击 Visual Studio 解决方案中云项目中的 Web 角色来更改此设置,选择“属性”,导航“配置”并选择“完全信任”。

关于c# - 在 Azure 上运行时 F# 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8064905/

相关文章:

c# - 如何在mvc.net中设置两个表之间的关系

f# - 简单示例中的 FSCL 错误

使用 F# 进行 Azure.Data.Tables 序列化

wpf - 如何使用 FsXaml 的 CommandDependecy/(ies)

angular - 如何使从 azure 广告收到的 Jwt token 无效

azure - 在没有PrincipalsAllowedToRetrieveManagedPassword的情况下为Azure AD域服务创建gMSA似乎不起作用

java - 如何处理从 Azure IoT 中心接收到的数据

c# - <form>中的Asp.net core设置后台

c# - VirtualKey C# Windows 应用商店应用程序

c# - 简化 if(x == 1 || x == 2)