Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to resolve assembly 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0" when building Azure Function v3

I have an Azure Function v3.1.

On my machine (macOS + Visual Studio Mac / Jetbrains Rider), it fails to build with the following error:

Error : Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

Here is the complete callstack:

##[error]C:\Users\VssAdministrator\.nuget\packages\microsoft.net.sdk.functions\3.0.9\build\Microsoft.NET.Sdk.Functions.Build.targets(32,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.<ToFunctionJsonBindings>b__1_0(CustomAttribute a)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MakeFunctionJson.ParameterInfoExtensions.ToFunctionJsonBindings(ParameterDefinition parameterInfo)
   at MakeFunctionJson.MethodInfoExtensions.<>c.<ToFunctionJson>b__6_1(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

Here is the content of my csproj (I followed the recommendations regarding AspNetCore 3.1):

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <AzureFunctionsVersion>v3</AzureFunctionsVersion>
        <LangVersion>latest</LangVersion>
        <Nullable>enable</Nullable>
        <RootNamespace>AccountManager</RootNamespace>
        <AssemblyName>AccountManager</AssemblyName>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
      <OutputPath>../bin\Debug\</OutputPath>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
      <OutputPath>../bin\Release\</OutputPath>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.0.1" />
        <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
        <PackageReference Include="Microsoft.Azure.Management.Storage" Version="17.2.0" />
        <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.7" />
        <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.7" />
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />
        <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
        <PackageReference Include="NoSuchCompany.Diagnostics.Guards" Version="1.0.71" />
    </ItemGroup>
    <ItemGroup>
        <None Update="host.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
    </ItemGroup>
    <ItemGroup>
      <ProjectReference Include="..\Core\Core.csproj" />
    </ItemGroup>
    <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
    </ItemGroup>
</Project>

Question

Why is the pipeline unable to build the project?

Update 1

After cleaning the solution output and cleaning the packages folder on my machine, the build fails on my machine as well.

I lied

Update 2

It fails when it is trying to generate the Azure Functions output:

2>Target "_GenerateFunctionsPostBuild" in file "/Users/christophe/.nuget/packages/microsoft.net.sdk.functions/3.0.9/build/Microsoft.NET.Sdk.Functions.Build.targets" from project "AccountManager/src/AccountManager/AccountManager.csproj" (entry point):
       Using "GenerateFunctions" task from assembly "/Users/christophe/.nuget/packages/microsoft.net.sdk.functions/3.0.9/build/../tools/netcoreapp3.1/Microsoft.NET.Sdk.Functions.MSBuild.dll".
       Task "GenerateFunctions"
         Function generator path: '/usr/local/share/dotnet/dotnet'
         Microsoft.NET.Sdk.Functions.Generator.dll "AccountManager/src/bin/Debug/netcoreapp3.1/bin/AccountManager.dll " "AccountManager/src/bin/Debug/netcoreapp3.1/ " "False "
  
2>/Users/christophe/.nuget/packages/microsoft.net.sdk.functions/3.0.9/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' [AccountManager/src/AccountManager/AccountManager.csproj]

If I copy the following file into the bin folder, it works:

/usr/local/share/dotnet/packs/Microsoft.AspNetCore.App.Ref/3.1.8/ref/netcoreapp3.1/Microsoft.AspNetCore.Mvc.Core.dll
like image 344
Kzrystof Avatar asked Oct 03 '20 14:10

Kzrystof


1 Answers

If you added [FromQuery] or any other attribute to your azure function "controller signture" it could happened , at least that what happened to me...

after I removed the [FromQuery] attribute it came back to life..

I have found this answer that nailed it : https://github.com/Azure/azure-functions-vs-build-sdk/issues/435#issuecomment-656854953

like image 74
aris Avatar answered Oct 10 '22 10:10

aris