Search code examples
azure-functionsazure-functions-runtimeazure-functions-core-tools

Function app SDH Upgrade from 3.0.x to 4.0.x


I am trying to upgrade function app sdk from 3.0.x to 4.0.x

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />

I also have a reference to

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.2.1" />

However, after function app sdk upgrade the build is failing with below exception.

Severity    Code    Description Project File    Line    Suppression State
Error       Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.Azure.WebJobs.ServiceBus, Version=4.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
   at Mono.Cecil.TypeReference.Resolve()
   at MakeFunctionJson.AttributeExtensions.IsWebJobsAttribute(CustomAttribute attribute) in /_/src/Microsoft.NET.Sdk.Functions.Generator/AttributeExtensions.cs:line 52
   at MakeFunctionJson.ParameterInfoExtensions.<>c.<IsWebJobSdkTriggerParameter>b__0_0(CustomAttribute a) in /_/src/Microsoft.NET.Sdk.Functions.Generator/ParameterInfoExtensions.cs:line 19
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at MakeFunctionJson.ParameterInfoExtensions.IsWebJobSdkTriggerParameter(ParameterDefinition parameterInfo) in /_/src/Microsoft.NET.Sdk.Functions.Generator/ParameterInfoExtensions.cs:line 17
   at MakeFunctionJson.MethodInfoExtensions.<>c.<HasTriggerAttribute>b__4_0(ParameterDefinition p) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 40
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at MakeFunctionJson.MethodInfoExtensions.HasTriggerAttribute(MethodDefinition method) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 40
   at MakeFunctionJson.MethodInfoExtensions.HasValidWebJobSdkTriggerAttribute(MethodDefinition method) in /_/src/Microsoft.NET.Sdk.Functions.Generator/MethodInfoExtensions.cs:line 24
   at MakeFunctionJson.FunctionJsonConverter.GenerateFunctions(IEnumerable`1 types)+MoveNext() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 134
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 194
   at MakeFunctionJson.FunctionJsonConverter.TryRun() in /_/src/Microsoft.NET.Sdk.Functions.Generator/FunctionJsonConverter.cs:line 87
Error generating functions metadata
    SdBridge.FunctionHost   C:\Users\<<>>\.nuget\packages\microsoft.net.sdk.functions\4.0.1\build\Microsoft.NET.Sdk.Functions.Build.targets 32  

Please help with any pointers to resolve this issue -


Solution

  • One of the workaround could be solve the above issue,

    To upgrade Azure Function 3X to 4X we need to add this following in our .csproj file

    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    

    And update your Nuget package to "Microsoft.NET.Sdk.Functions" Version="4.0.1"

    Make sure that you have installed Azure function core tool version 4x in your local .

    Here is the workaround details that i have tried

    enter image description here

    For more information please refer this MS DOC: Migrating from 3x to 4x