Azure Function: "One or more of the requested types cannot be loaded. Get the LoaderExceptions property for more information."

I have a F # Azure function that doesn’t work, is bizarre, and I don’t know how to approach the fix of the problem. I have created a minimum actual case registry below. The test function is started manually and uses FSharp.Compiler.Service as a dependency, as indicated in project.json below:

 { "frameworks": { "net46":{ "dependencies": { "FSharp.Compiler.Service": "11.0.6" } } } } 

The run.fsx file looks like this:

 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" 

So far so good. The part that illuminates me is that if I add the following function above 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 

Uncommenting section 1 works fine, split section 2 works fine, split section 3 makes hell break. The function compiles, but its launch raises the following exception:

 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. 

... which puzzles me because

  • foo is not even called
  • the signature and the second version use LongIdent , so this type is not the source of the problem.

Any suggestion on how to approach the problem and what the problem may be itself will be very appreciated - I don’t even know where to start, and the same code works fine in the local script.

+6
source share
2 answers

I believe the reason for this is that the Azure Functions SDK is dependent on FSharp.Compiler.Service (FCS) version 9.0.1 . This means that if you try to download another version of FCS, you will get the already downloaded version 9.0.1.

This works as long as the public API of the FCS version you use matches the public API of version 9.0.1, but when there are differences, it will break because your code assumes the open API looks different. I suppose this might cause the problem here, although I am not 100% sure how (maybe LongIdent now another thing than in version 9.0.1?)

The problem itself was used with FAKE , which also bundles FCS and prevents different versions from loading. One option is to rename the assembly to avoid a collision .

+4
source

I also got the same error, I solved it by following the next workaround, please contact if it works for you as well.

  • Right-click the project and select properties.
  • Click the Debug tab and create a profile with a link below a screenshot.

Note Replace UserName with your username.

Project properties

0
source

Source: https://habr.com/ru/post/1015698/


All Articles