0
votes

I'm using Azure Functions and want to write code that reads/writes to Dynamics CRM Online. I added the CRM 2015 SDK DLLs (all of them) to a bin folder under where the function.json file resides per Microsoft's documentation.

The function compiles fine.

When running the function I get this error:

Exception while executing function: Functions.CrmTest1. mscorlib: Exception has been thrown by the target of an invocation. Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Here's the function body (just a small test sample):

#r "Microsoft.Xrm.Sdk.dll"  
#r "Microsoft.Xrm.Client.dll"

using System;
using Microsoft.Xrm.Sdk; 
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Client.Services;

public static void Run(string input, TraceWriter log)
{
    var connectionString = "AuthType=Office365;[email protected]; Password=MyPassword;Url=https://contoso.crm.dynamics.com";
    CrmConnection connection = CrmConnection.Parse (connectionString);
    using ( OrganizationService orgService = new OrganizationService(connection))
    { 
        var query = new QueryExpression("account");
        query.ColumnSet.AddColumns("name");
        var ec = orgService.RetrieveMultiple(query);
        log.Verbose(ec[0].GetAttributeValue<string>("name"));
    }
}

There's no indication in the log files what needed assembly can't be found.

What am I missing with getting this to work? How can I find out what DLL is needed but is not found?

1
Tim, what assemblies have you deployed to the bin folder? Can you provide the list? - Fabio Cavalcante
I started with just a few but ended up copying in every DLL that's in the CRM 2015 SDK \bin folder (34 files). I double-checked and they're all in a \bin folder under where my function.json resides. I know that most of the DLLs aren't needed for a simple Xrm app, but the Azure Function logs don't providing any indication about which DLL(s) are missing so I just copied them all up. I'll try using Nuget with the function next, maybe I'll have better luck with that approach. - Tim Dutcher
I've been away for the weekend but I'll run some tests using the CRM 2015 SDK to see what is happening here. There was an issue that would have explained this behavior, but it has been recently addressed.I'll post an update ASAP. - Fabio Cavalcante
Thanks for looking into this Fabio. Getting this to work will be a big win for Dynamics CRM customers. Most CRM Online clients that I work with eventually have the need for one-off and recurring data clean up, scheduled actions, etc. Azure Functions will be perfect for these quick, light-weight system updates that don't require a full WebJob, Worker Role, etc. - Tim Dutcher
I was able to repro this issue today and found a small defect that unfortunately, impacts indirect private dependency resolution. I have a fix for this and will update with an answer once it's deployed. Thanks for reporting it! - Fabio Cavalcante

1 Answers

2
votes

Tim,

The latest deployment that went live today contains the fix to address the issue you ran into. Please try again (you may need to restart your site to pick up the latest version if you had functions running) and let me know if you have any problems.

Thanks again for reporting this! I'm looking forward to seeing what you'll put together with Functions and Dynamics CRM.