0
votes

I've been able to get Azure functions written in net core to run. I now have added a reference to "WindowsAzure.Storage" and am now getting loaderexceptions when I use the local test environment ("func host start").

I can not use the default table storage binder as I need to upsert records in different tables.

I use precompiled functions and am developing with VSCode on OSX. I can't find any info if this scenario is supported or not. Is it even possible to get external dependencies working with the 2.0 runtime of Azure functions.

The local SDK/runtime is

  • Azure Functions Core Tools (2.0.1-beta.21)
  • Function Runtime Version: 2.0.11370.0

My csproj file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta3" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.0-beta3" />
    <PackageReference Include="WindowsAzure.Storage" Version="8.6.0" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="SearchTwitter\function.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Part of my function

namespace MyProject.Functions
{
    public class SearchFunction
    {

        public async static Task Run(TimerInfo myTimer, Binder binder, TraceWriter log)
        {

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(System.Environment.GetEnvironmentVariable("StorageConnection", EnvironmentVariableTarget.Process));
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
            CloudTable searchMetaDataTable = tableClient.GetTableReference("SearchMetaData");
            await searchMetaDataTable.CreateIfNotExistsAsync();

        }
 }

Function.json

{
    "bindings": [
        {
            "type": "timerTrigger",
            "direction": "in",
            "schedule": "0 */15 * * * *",
            "runOnStartup": true,
            "name": "myTimer"
        }
    ],
    "scriptFile": "../MyProject.Functions.dll",
    "entryPoint": "MyProject.Functions.SearchFunction.Run"
}
2
What version of the storage SDK are you referencing? The 2.0 runtime is on >8.x. If you can share more details about the error and your setup, it would be helpful, but this scenario should work as expected. - Fabio Cavalcante
Hi I've added more info - BennyM

2 Answers

1
votes

The Azure Storage Namespacee is available by default by the Azure Functions hosting environment. You can find more details here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#referencing-external-assemblies

However, if that’s not what you’re looking for, rest assured that you can consume any external NuGet package by adding it to your Function’s csproj file. For an example on how to do it, check the sample code in this GitHub repo https://github.com/lindydonna/CSharpHttpCore/blob/master/HttpTriggerCore/HttpTriggerCore.csproj

1
votes

For precompiled functions, WindowsAzure.Storage package comes as sub-dependency of Microsoft.NET.Sdk.Functions, so you don't need to reference it separately.

If you still reference it, and the reference is of a wrong version, you will get conflicts all over the place.

Such care should be taken for any sub-dependency of Microsoft.NET.Sdk.Functions. Otherwise, referencing NuGets is perfectly supported.