0
votes

I am getting a "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" error in Azure Functions. Any ideas on what the problem might be?

I am using the package.json file to have Azure Functions pull in the references and hook them all up as described in the docs.

When you upload a project.json file, the runtime gets the packages and automatically adds references to the package assemblies. You don't need to add #r "AssemblyName" directives. Just add the required using statements to your run.csx file to use the types defined in the NuGet packages.

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

My package.json file:

{
  "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 statements:

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

Full Exception:

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
Looks like a sign of version mismatch. Can it be that same dependency is referenced twice from different packages with different versions?Mikhail Shilkov

2 Answers

1
votes

This error is misleading and I had to end up overriding BoxJWTAuth in order to make it work. The details of this error can be found here: https://github.com/box/box-windows-sdk-v2/issues/297

2
votes

The error is clearly stating that it can't find the assembly:

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.

And while you show in your .csx that you have using statements to include the namespaces, no where do you show that you actually reference the external assemblies

As described in the above linked documentation:

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").

Make sure you get the path correct; I had to ensure the bin folder was within my path where the function was - the shared assembly approach didn't work for me.

I also suggest that perhaps an easier approach than dealing with csx and referencing assemblies is to ditch csx all together and use pre compiled functions as described in this blog post. Then you get full compile time resolution of assemblies and proper intellisense that you just don't get with the CSX files.