在Azure功能上使用Box SDK时出错

时间:2017-03-27 12:04:35

标签: azure box azure-functions

我收到"无法加载文件或程序集' Box.V2,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = ddda8fe64dde1ac3'或其中一个依赖项。系统无法在 Azure功能中找到指定的文件" 错误。关于问题可能是什么的任何想法?

我正在使用package.json文件让Azure Functions引入引用并将它们全部挂起,如文档中所述。

  

上传project.json文件时,运行时获取包并自动添加对包程序集的引用。你不需要添加#r" AssemblyName"指令。只需将所需的using语句添加到run.csx文件中即可使用NuGet包中定义的类型。

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp

我的package.json文件:

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "BouncyCastle": "1.8.1",
        "BouncyCastle-PCL": "1.0.0.6",
        "Box.V2": "2.14.0",
        "Box.V2.JWTAuth": "1.2.0",
        "Microsoft.Bcl": "1.1.10",
        "Microsoft.Bcl.Async": "1.0.168",
        "Microsoft.Bcl.Build": "1.0.14",
        "Microsoft.Net.Http": "2.2.29",
        "Newtonsoft.Json": "6.0.2",
        "Nito.AsyncEx": "2.1.3",
        "System.IdentityModel.Tokens.Jwt": "4.0.2.206221351"
      }
    }
  }
}

run.csx using statement:

using global::Box.V2;
using global::Box.V2.Config;
using global::Box.V2.Exceptions;
using global::Box.V2.JWTAuth;
using global::Box.V2.Models;

完全例外:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.GetTelogisFormInstancePdf ---> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException : Could not load file or assembly 'Box.V2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ddda8fe64dde1ac3' or one of its dependencies. The system cannot find the file specified.

   at Submission#0.Run(HttpRequestMessage req,TraceWriter log) at  : 84 

   End of inner exception

   at System.RuntimeMethodHandle.InvokeMethod(Object target,Object[] arguments,Signature sig,Boolean constructor)

   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object[] parameters,Object[] arguments)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object[] parameters,CultureInfo culture)

   at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.InvokeCore(Object[] parameters,FunctionInvocationContext context)

   at async Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters)

   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.InvokeAsync[TReflected](Object[] arguments)

   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,Object[] invokeParameters,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance)

   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,IReadOnlyDictionary`2 parameters,TraceWriter traceWriter,CancellationTokenSource functionCancellationTokenSource)

   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??…

2 个答案:

答案 0 :(得分:2)

错误显然表明它无法找到程序集:

System.IO.FileNotFoundException : Could not load file or assembly 'Box.V2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ddda8fe64dde1ac3' or one of its dependencies. The system cannot find the file specified.

虽然您在.csx中显示您使用语句来包含命名空间,但是您没有在哪里显示实际reference the external assemblies

如上述链接文档中所述:

If you need to reference a private assembly, you can upload the assembly file into a bin folder relative to your function and reference it by using the file name (e.g. #r "MyAssembly.dll").

确保你的路径正确;我必须确保bin文件夹在我的功能所在的路径中 - 共享组装方法对我没有用。

我还建议,或许比处理csx和引用程序集更简单的方法是将csx放在一起并使用预编译函数,如blog post中所述。然后,您将获得程序集的完整编译时间分辨率以及您不熟悉CSX文件的正确智能感知。

答案 1 :(得分:1)

此错误具有误导性,我不得不最终覆盖BoxJWTAuth以使其正常工作。可以在此处找到此错误的详细信息:https://github.com/box/box-windows-sdk-v2/issues/297