2

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?

sth
  • 33
  • 4
  • can you [enable fusion logs](https://stackoverflow.com/a/1527249/3234163) 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 Aug 23 '17 at 20:30
  • 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 Aug 23 '17 at 20:33
  • Repo: https://github.com/SaevarThorisson/azurefunctiontest I can't share any of the API keys for the PowerOfficeGoSDK though. – sth Aug 24 '17 at 12:43
  • Also uploaded the Fusion logs to the GitHub repository. – sth Aug 24 '17 at 13:14

1 Answers1

0

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

Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47
  • I tried building it from scratch again now, still getting the same Exception. It happens on the line "var goApi = new Go(authorizationSettings);" Not the line before. – sth Aug 24 '17 at 12:19
  • According to the exception `System.Runtime.Serialization.SerializationException : Unable to find assembly 'GoApi, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null'`. It seems that GoApi can't be loaded on the Azure. But According to my test it seems that it is loaded very well. Execption in my test also happened on the line var `goApi = new Go(authorizationSettings)`. That means want to initialize Go but the authorizationSettings with Invalid ApplicationKey or ClientKey. – Tom Sun - MSFT Aug 25 '17 at 02:16
  • As you can't share your key, my suggestion is that you could create a new function just with my code with your correct key to check whether it is working. – Tom Sun - MSFT Aug 25 '17 at 02:18
  • Did that now and it works on the first run. But on every run after that I get the same Exception. And it doesn't even always work on the first run, just usually. By first run I mean deleting the function from the function app, publishing it again to Azure and the first "Run" click after publishing. – sth Aug 25 '17 at 12:15
  • It is very odd that works for the first time. Please have a try to debug it locally to check it whether it is working. – Tom Sun - MSFT Aug 31 '17 at 01:10