Reputation: 15420
When using the NuGet.Protocol NuGet Package in Azure Functions, I get the following error: System.Private.CoreLib: Could not load file or assembly
.
[4/18/2020 8:51:43 AM] The 'Function1' function is in error: Unable to load one or more of the requested types.
[4/18/2020 8:51:43 AM] Could not load file or assembly 'NuGet.Protocol, Version=5.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
[4/18/2020 8:51:43 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. System.Private.CoreLib: Could not load file or assembly 'NuGet.Protocol, Version=5.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
I confirmed that the NuGet.Protocol.dll
file exists in the bin
output.
Why can Azure Functions not find NuGet.Protocol.dll
?
Upvotes: 13
Views: 8807
Reputation: 15420
This is a known-problem with Azure Functions, introduced in Microsoft.NET.Sdk.Functions
v3.0.4, and still present today (v3.0.11).
To prevent Azure Functions from removing this library, add the following to your CSPROJ:
<PropertyGroup>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
Here is an example of how I use it in my GitTrends app: https://github.com/brminnick/GitTrends/blob/22d748fc72452dcd39bb3866e30f339827ded3dd/GitTrends.Functions/GitTrends.Functions.csproj#L10
Upvotes: 36