Exceptions in F# when running on Azure
We have a C# web role running in Azure, and the C# project invokes code in an F# dll that we deploy with our app.
When we're running locally using the local Azure emulator, our F# code is invoked and runs fine. When it's running in Azure in the cloud, our F# code fails at a certain point with this exception:
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.LexBuffer 1.FromArray(char[] s) at Microsoft.FSharp.Text.Lexing.LexBuffer
1.FromString(String s) at Marshal.vars@27.GenerateNext(IEnumerable`1& next)
WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLMSoftwareMicrosoftFusion!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 [HKLMSoftwareMicrosoftFusion!EnableLog]. .Will use default function.
We have found some posts that suggest it's because :
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
To try to get round this, we follow the advice below and put the –standalone
flag in the Build config of our F# library.
http://www.42spikes.com/post/F-and-Azure.aspx
However, the F# library doesn't compile with this flag. We get this build error:
Error 3 A problem occurred writing the binary 'objDebugAnalyzer.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
Could this build error be because of the dependencies our F# project has? It references FSharp.PowerPack.dll and Microsoft.Z3.dll, as well as another C# library in our solution, AnalyzerCommon.dll (which just contains a common interface that both our F# and C# code implement).
It's interesting that the F# code is called and runs fine, it's only until it hits a certain part of the code - a formula parser that uses FSharp.PowerPack.dll.
Any tips would be greatly appreciated.
Thanks, Sam
You have to explicitly reference all required assemblies in your WebRole application, and set the " Copy Local " attribute to " True ". Check out this mine blog post. The very first thing I mention is the Copy Local.
The reason that part of your code runs and other not, is the JIT compiler. Everything runs fine, untill you hit a code that requires a missing assembly. Once you have all required assemblies explicitly added as reference and set "Copy Local" to "True", there shall be not "File not found" exception.
Please follow up if that helped!
EDIT
Windows Azure runs in Full Trust by default. Since SDK 1.3 I think. You may change this by right click on your web role in the Cloud project in Visual Studio Solution, choose Properties, navigate "Configuration" and choose "Full trust".
你确实放弃了'standalone'而不是'standalone',不是吗?
链接地址: http://www.djcxy.com/p/86116.html上一篇: 如何创建可以从C#使用的F#Type Provider?
下一篇: F#在Azure上运行时的例外情况