2
votes

I've been trying out the new Visual Studio 2017 Tools for Azure Functions and I'm running into a problem.

When trying to initialise a class from the Nuget package PowerOfficeGoSDK in an Azure Function, I get a SerializationException:

var authorizationSettings = new AuthorizationSettings
{
    ApplicationKey = applicationKeyGuid,
    ClientKey = clientKeyGuid,
    TokenStore = new BasicTokenStore("my.tokenstore")
};

var goApi = new Go(authorizationSettings);

System.Runtime.Serialization.SerializationException : Unable to find assembly 'GoApi, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null'.

The code uses various other Nuget packages like Microsoft.Azure.KeyVault without any problems. I've checked the bin folder of the function using Kudu, and the GoApi.dll file is there.

Anyone know what might cause the exception?

1
can you enable fusion logs on your machine, then share the logs for func.exe? it'll help show where the assembly was looked for and why it was not found. - ahmelsayed
In addition, if you could share a simple repro (ideally something on GitHub), we can take a closer look at your specific setup. - Fabio Cavalcante
Repo: github.com/SaevarThorisson/azurefunctiontest I can't share any of the API keys for the PowerOfficeGoSDK though. - sth
Also uploaded the Fusion logs to the GitHub repository. - sth

1 Answers

0
votes

I am not familiar with PowerOfficeGoSDK, but based on my test, PowerOfficeGoSDK could be loaded in the Azure function. If it ispossible, please have a try to republish or create a new function App to test it again.

The following is my detail steps:

1.Create new Azure function project with Visual studio 2017

2.According to PowerOfficeGoSDK Dependencies, we need to update newtonsoft.json and Microsoft.Data.Edm to following version

Microsoft.Data.Edm (>= 5.8.2) 
Newtonsoft.Json (>= 10.0.2) 

Note: There is an issue about using Newtonsoft.Json version 10+ in the Azure function

3.Add the timetrigger function and config the storage connection string in the local.settings.json file.

[FunctionName("AzureFunction")]
public static void Run([TimerTrigger("0 */2 * * * *")]TimerInfo myTimer, TraceWriter log)
{
    log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
    try
      {
         var authorizationSettings = new AuthorizationSettings
         {
            ApplicationKey = Guid.NewGuid().ToString(), //I have no application key
            ClientKey = Guid.NewGuid().ToString(), //I have no client key
            TokenStore = new BasicTokenStore("my.tokenstore")
          };
          var goApi = new Go(authorizationSettings);
        }
        catch (Exception e)
        {
           log.Info($"Exception:{e.Message}"); 
        }

        log.Info($"C# Timer trigger function Finished at: {DateTime.Now}");
}

4.Publish it to Azure with Visual Studio and check the result from Azure portal.

Note :I have no application and client key, so I get the exception Invalid ApplicationKey or ClientKey it is as expected.

enter image description here