Chris
Chris

Reputation: 4083

Azure Functions Not Generating extensions.json

I have an Azure Functions Project with multiple functions, triggered by ServiceBus and BlobStorage.

They have been building and deploying to azure fine for a couple months now.
Something happened recently and they are no longer deploying from my build machine with an error in Azure when you click on the function Error: The binding type(s) 'blobTrigger' are not registered.
It is still deploying fine from my dev machine though. They are using WEBSITE_RUN_FROM_ZIP to deploy the code itself.

I pulled the publish directory from both my dev machine and the build machine and it appears that the file extensions.json is getting generated locally but is not on the build machine, along with empty localization folders that don't exist on the build machine and about 10mb difference in size that I can't account for yet.
The Azure Functions are targeting .Net Standard 2.0. Checking the .Net versions, .Net core is the same version across the build and dev machines.

What causes this file to get generated?

Upvotes: 4

Views: 3947

Answers (3)

jsgoupil
jsgoupil

Reputation: 3997

The best way to find out why it is not working is to turn on the diagnostic logs in Visual Studio then build.

enter image description here

Then, after you build, you can search for the word "extensions.json"

Which will start like this:

2>  Task "GenerateFunctionsExtensionsMetadata"
2>    Task Parameter:SourcePath=F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin
2>    Task Parameter:OutputPath=F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin
2>    Extensions generator working directory: 'C:\Users\jsgou\.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.1.8\tools\net46\..\netstandard2.0\generator'
2>    Extensions generator path: 'dotnet'
2>    Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.Console.dll "F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin" "F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin\extensions.json"

Then, a little further you might find the actual error why it is not working:

2>      HBTI.ServiceTech.AzureFunctions.dll
2>        Resolving assembly: 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
2>        Assembly 'System.Runtime' loaded.
2>        Resolving assembly: 'Microsoft.Azure.Functions.Extensions, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f655f4c90a0eae19'
2>        Assembly 'Microsoft.Azure.Functions.Extensions' loaded from 'F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin\Microsoft.Azure.Functions.Extensions.dll'.
2>        Resolving assembly: 'Microsoft.Azure.WebJobs.Host, Version=3.0.18.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
2>        Assembly 'Microsoft.Azure.WebJobs.Host' loaded from 'F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin\Microsoft.Azure.WebJobs.Host.dll'.
2>        Resolving assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
2>        Resolving assembly: 'Microsoft.AspNetCore.Mvc.Core, Culture=neutral, PublicKeyToken=null'
2>        Cannot load 'Microsoft.AspNetCore.Mvc.Core'. Aborting assembly resolution.
2>        Unable to find fallback for assembly 'Microsoft.AspNetCore.Mvc.Core'. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
2>    File name: 'Microsoft.AspNetCore.Mvc.Core, Culture=neutral, PublicKeyToken=null'
2>       at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
2>       at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
2>       at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, StackCrawlMark& stackMark, IntPtr pPrivHostBinder)
2>       at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, StackCrawlMark& stackMark)
2>       at System.Reflection.Assembly.Load(String assemblyString)
2>       at ExtensionsMetadataGenerator.Console.Program.AssemblyLoader.<>c__DisplayClass1_0.<Initialize>b__0(Object sender, ResolveEventArgs args) in d:\a\1\s\tools\ExtensionsMetadataGenerator\src\ExtensionsMetadataGenerator.Console\Program.cs:line 78
2>
2>
2>        Could not evaluate 'HBTI.ServiceTech.AzureFunctions.dll' for extension metadata. If this assembly contains a Functions extension, ensure that all dependent assemblies exist in 'F:\git\clients\hbti\Portal\hbti-web-master\HBTI.ServiceTech.AzureFunctions\bin\Debug\netcoreapp3.1\bin'. If this assembly does not contain any Functions extensions, this message can be ignored. Exception message: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

My solution in this case, is to simply make my own extensions.json and drop it in the bin foler as such:

enter image description here

Upvotes: 0

Chris
Chris

Reputation: 4083

I have been able to work around the issue by following the advice in this Github comment.

Essentially sometimes you have to include an extra dependency to get msbuild/visual studio to run the post build steps and generate your extensions file.
Add Microsoft.Azure.Webjobs.Script.ExtensionsMetadataGenerator as a dependency to your functions project and it should always (so far) build your publish directory properly.

Per usual, leaving the question open for someone to tell us why this is needed.

Upvotes: 3

Rohit Saigal
Rohit Saigal

Reputation: 9664

One of the possible reasons could be an update to Azure Functions v2.0

That could explain sudden change causing errors for functions that as you mention were working till a couple of months ago.

Take a look at this issue https://github.com/Azure/azure-functions-host/issues/3363#issuecomment-417926456

it's very similar to yours.

One of the changes in v2.0 is that you need to reference the storage extensions when working with storage related triggers

Reference the Storage Extension where appropriate If you have functions that work with Azure Storage (queue/tables/blob) either with triggers, input bindings or output bindings, you'll need to reference the new Microsoft.Azure.WebJobs.Extensions.Storage extension.

Here is a link that documents all the breaking changes - Azure Functions Runtime 2.0.12050-alpha breaking changes notice

Upvotes: 3

Related Questions