question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiling Azure Functions with NuGet package dependencies fails

See original GitHub issue

I have a solution with multiple Azure Function HTTP APIs. They were previously using a shared base class in the same project and were able to build without issue. Now, the shared base class has been moved to a NuGet package. Using the base class from the installed NuGet package (even with symbols) fails to compile with the following message:

Unexpected error: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (0x80131621)  
 at Blueprint.Serverless.ServerlessApiBuilder.Build(ServerlessApi api)   
at Blueprint.Forms.Api.FunctionAppConfiguration.Build(IFunctionHostBuilder builder) 
in [...]\FunctionAppConfiguration.cs:line 33   at FunctionMonkey.Compiler.Core.Compiler.Compile() 
in /Users/jamesrandall/code/functionMonkey/library/Source/FunctionMonkey.Compiler.Core/Compiler.cs:line 91   at FunctionMonkey.Compiler.Program.Main(String[] args) 
in /Users/jamesrandall/code/functionMonkey/library/Source/FunctionMonkey.Compiler/Program.cs:line 56 | Blueprint.Forms.Api | [...].nuget\packages\functionmonkey.compiler\4.0.56-beta.4\build\netstandard1.0\FunctionMonkey.Compiler.targets

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mmeckescommented, May 1, 2020

Not sure if this is related, but I had a similar issue when upgrading to Microsoft.NET.Sdk.Functions 3.0.6 with various nuget packages failing with “Unexpected error: Could not load file or assembly” errors.

I was able to resolve them by adding <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput> as a property in my cproj file.

0reactions
MarkusBernhardtcommented, May 3, 2020

We are using FunctionMonkey built with Azure Pipelines in production. I believe I can remember these problems. The root cause was that parts of the required libraries are loaded from the SDK and in an Azure Pipeline build this works somehow different from a local build.

  1. It is important you install the correct .Net Core SDK on the build machine. Use the task: “Use .NET Core”, choose “SDK” and enter the exact version. We use 3.1.201.

  2. Add to all your .csproj files:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

Our full YAML pipeline file as reference (some things overwritten with xxxxxxxxxxxxxxxx):

pool: name: Azure Pipelines demands:

  • msbuild
  • visualstudio
  • vstest

variables: BuildPlatform: ‘any cpu’ BuildConfiguration: ‘debug’

steps:

  • task: UseDotNet@2 displayName: ‘Use .Net Core sdk 3.1.201’ inputs: version: 3.1.201

  • task: NuGetToolInstaller@0 displayName: ‘Use NuGet 4.x’ inputs: versionSpec: 4.x

  • task: NuGetCommand@2 displayName: ‘NuGet restore’ inputs: restoreSolution: ‘xxxxxxxxxxxxxxxx.sln’ vstsFeed: ‘xxxxxxxxxxxxxxxx’

  • task: VSBuild@1 displayName: ‘Build solution’ inputs: solution: ‘xxxxxxxxxxxxxxxx.sln’ msbuildArgs: ‘/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=“$(build.artifactstagingdirectory)\”’ platform: ‘$(BuildPlatform)’ configuration: ‘$(BuildConfiguration)’

  • task: VSTest@2 displayName: ‘Test assemblies’ inputs: testAssemblyVer2: | *test.dll !*TestAdapter.dll !\obj** !**.Test.Base.dll platform: ‘$(BuildPlatform)’ configuration: ‘$(BuildConfiguration)’ diagnosticsEnabled: True

  • task: PublishSymbols@2 displayName: ‘Publish symbols path’ inputs: PublishSymbols: false

  • task: PublishBuildArtifacts@1 displayName: ‘Publish Artifact: xxxxxxxxxxxxxxxx’ inputs: ArtifactName: xxxxxxxxxxxxxxxx

Hope this helps somehow and good luck, Markus

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure function failing to Load Nuget package
According to the error message: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor ...
Read more >
"Could not load file or assembly" error with Nuget package ...
Workaround: Downgrade Microsoft.NET.Sdk.Functions package to 3.0.3; Restore dependencies. Run function app. Observe no error.
Read more >
Azure Functions v3 and VS2019 - Build fails with Error ...
It seemed the NuGet Package Manager downloaded NuGet packages correct, but Visual Studio failed to recognize them or VS didnt look in the ......
Read more >
Azure Functions quit building with error after upgrading ...
I have one that targets v1 (due to a Framework dependency) and one ... .nuget\packages\microsoft.net.sdk.functions\1.0.38\build\Microsoft.
Read more >
Azure Function Portal C# Script cannot fetch nuget ...
I'm developing a windows Azure Function App in the portal.azure.com. This C# script runs... However, if I remove the first comment, it fails...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found