I've recently updated a project from netcoreapp2.0 to netcoreapp3.1 and v3 function app following the migration guides. Unfortunately, I'm hitting an issue where the metadata generation doesn't work from microsoft.net.sdk.functions.
If I build the project without a reference to the functions package, all the unit tests pass fine but obviously there's no function app enpoints available when loading the runtime.
What's not clear to me is what needs to be done to resolve this issue. I was under the impression that Microsoft.AspNetCore.Mvc.Core is part of the netcore3.1 distribution now (and no longer being published on nuget. I can't explicitly add a reference to AspNetCore.Mvc.Core in the csproj to fix this since the latest published versions are for 2.*. Is there something else I need to do to finish the migration that's missing? Is there a bug here?
[error]C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\microsoft.net.sdk.functions\3.0.7\build\Microsoft.NET.Sdk.Functions.Build.targets(44,5): Error : Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
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)
at MakeFunctionJson.ParameterInfoExtensions.<>c.<IsWebJobSdkTriggerParameter>b__0_0(CustomAttribute a)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at MakeFunctionJson.ParameterInfoExtensions.IsWebJobSdkTriggerParameter(ParameterDefinition parameterInfo)
at MakeFunctionJson.MethodInfoExtensions.<>c.<ToFunctionJson>b__6_0(ParameterDefinition p)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at MakeFunctionJson.MethodInfoExtensions.ToFunctionJson(MethodDefinition method, String assemblyPath)
at MakeFunctionJson.FunctionJsonConverter.GenerateFunctions(IEnumerable`1 types)+MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()
Error generating functions metadata
Relevant sections from the csproj file:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.4.1" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.10.1" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.2" />
<PackageReference Include="Microsoft.Azure.Webjobs.Host.Storage" Version="3.0.14" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
</ItemGroup>
Any update on this? I repro'ed the issue here: https://github.com/rsphife/MetadataGenerationError
I initially ran into this same issue while attempting to upgrade a V2 functions app on 2.2 to V3 on 3.1. The repro linked above though is from a fresh V3 functions app. The issue appears to be related to the Microsoft.AspNetCore.Mvc.NewtonsoftJson package.
The steps for my repro are:
The error I get after adding the [FromBody] attribute is the same as above: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Removing Microsoft.AspNetCore.Mvc.NewtonsoftJson or removing the FromBody attribute and rebuilding resolves the issue.
I haven't found any workarounds for it. We need Microsoft.AspNetCore.Mvc.NewtonsoftJson in our project, so I can't remove it.
I removed the AddMvcCore().AddNewtonsoftJson() call from my code and any references to NewtonsoftJson as a test (not sure if it works at runtime, but unit tests pass at least)
However, a new build issue cropped up:
Extensions/HttpRequestExtensions.cs(338,17): error CS1705: Assembly 'Microsoft.AspNetCore.OData' with identity 'Microsoft.AspNetCore.OData, Version=7.4.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'Microsoft.AspNetCore.Routing, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Routing' with identity 'Microsoft.AspNetCore.Routing, Version=2.2.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Extensions/HttpRequestExtensions.cs(341,36): error CS1705: Assembly 'Microsoft.AspNetCore.OData' with identity 'Microsoft.AspNetCore.OData, Version=7.4.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.Core' with identity 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Extensions/HttpRequestExtensions.cs(357,34): error CS1705: Assembly 'Microsoft.AspNetCore.OData' with identity 'Microsoft.AspNetCore.OData, Version=7.4.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'Microsoft.AspNetCore.Http.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Http.Abstractions' with identity 'Microsoft.AspNetCore.Http.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
I was able to work around this by downgrading Microsoft.AspNetCore.OData to 7.2.3 (before support for NetCore 3.1 was added) and it seems to be happy now.
So is the issue here that these libraries (Microsoft.AspNetCore.Mvc.NewtonsoftJson and Microsoft.AspNetCore.OData ) are referencing versions of libraries that are not available on NuGet? I can see that Microsoft.AspNetCore.Mvc.Core, Microsoft.AspNetCore.Http.Abstractions and Microsoft.AspNetCore.Routing are not available on NuGet as version 3.1.0, but are likely present in the dotnet core SDK runtimes directory.
What's the correct way to work around this? Using the latest OData still causes the "Failed to resolve assembly" error for Mvc.Core 3.1.0.
I have some proprietary libraries for netcoreapp3.1 we're trying to pull in as well and they're also hitting this issue with the Functions SDK. When they are included in my Function app, it builds fine without the Functions SDK and passes unit tests. It's just the metadata generation that's bombing out.
Is there additional information I need in order to get to get this triaged?
I'm having the same error. I'm using the Microsoft.Azure.Functions.Extensions with the Microsoft.NET.Sdk.Functions. Both are updated to the latest versions.
I think I had similar issues. I made a new Timer app using VS2019 and did not change any code. I upgraded to latest non-preview dependencies and received the error "No job functions found. Try making your job classes and methods public". I downgraded Functions sdk to version 3.0.7 and it the timer worked.
My team is still stuck with this issue. As far as I can tell, there's no workaround for us.
@William-Froelich I've just faced a similar issue. Have you tested by removing [FromBody] and use an HttpRequest instead as a workaround?
@ferantivero , we aren't using [FromBody]. Are there other annotations that can cause this?
I looked for similar elements and found we were using [FromRoute]. Removing that seemed to resolve the build, but why would that be the cause?
Are the MVC attributes not supported?
Would really like to use [FromBody]. Unfortunately we are enjoying the utility of [FromBody] . We thought it was working on linux with vscode, but we are now seeing this issue in all our dev environments.
I can see [FromQuery] is causing the same error, and the error message, as shown above, is very unhelpful. Could the builder either support these attributes or explicitly check for them and report them as invalid.
Any updates on this one ? @fabiocav Thx
Just bumped on this too
[FromServices] also seems to cause this.
I got a similar exception, but also received some helpful information prior to the one discussed here. I did what the exception said and it worked. Seems to be caused by some mismatch between trigger attribute parameters and Run() method parameters.
Most helpful comment
Any update on this? I repro'ed the issue here: https://github.com/rsphife/MetadataGenerationError
I initially ran into this same issue while attempting to upgrade a V2 functions app on 2.2 to V3 on 3.1. The repro linked above though is from a fresh V3 functions app. The issue appears to be related to the Microsoft.AspNetCore.Mvc.NewtonsoftJson package.
The steps for my repro are:
The error I get after adding the [FromBody] attribute is the same as above:
Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'Removing Microsoft.AspNetCore.Mvc.NewtonsoftJson or removing the FromBody attribute and rebuilding resolves the issue.