I am trying to get an Azure function running, but am encountering the following error on deployment --
Microsoft.Azure.WebJobs.Script: Error building configuration in an external startup class.
System.Private.CoreLib: Could not load file or assembly '<MyAssembly>, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null'.
But my deployment was successful and I can see the DLL in App Files. I'm running C# / .net 6.0 on Functions v4.0 and using the GitHub Workflow action generated by Deployment Center to deploy.
What can cause the runtime to be unable to see the main function DLL?
Adding image of App Files:
My project package references:
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.15.1" />
<PackageReference Include="Cosmonaut" Version="2.11.3" />
<PackageReference Include="Cosmonaut.ApplicationInsights" Version="2.1.1" />
<PackageReference Include="Cosmonaut.Extensions.Microsoft.DependencyInjection" Version="2.3.0" />
<PackageReference Include="Cosmonaut.NestedQueries" Version="2.11.4" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.6.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SendGrid" Version="3.0.3" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
</ItemGroup>
Deployment GitHub Action from Deployment Center:
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy dotnet core app to Azure Function App - brokentoysapi3
on:
push:
branches:
- master
workflow_dispatch:
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: './api/_new/BrokenToys.Api/' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '6.0.x' # set this to the dotnet version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v2
- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: 'Resolve Project Dependencies Using Dotnet'
shell: pwsh
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet build --configuration Release --output ./output
popd
- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: 'brokentoysapi3'
slot-name: 'Production'
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_E20EFE8EF7D84C4AA5B5C75BE0B66D0F }}
Here's my startup class:
using BrokenToys.Api.Models.Games;
using Cosmonaut;
using Cosmonaut.Extensions.Microsoft.DependencyInjection;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
[assembly: FunctionsStartup(typeof(BrokenToys.Api.Startup))]
namespace BrokenToys.Api
{
public class Startup : FunctionsStartup
{
public static IConfiguration Configuration { set; get; }
public override void Configure(IFunctionsHostBuilder builder)
{
var cosmosSettings =
new CosmosStoreSettings
("BrokenToys", "https://<mycosmosdb>.documents.azure.com:443/", "<mykey>");
builder.Services.AddCosmosStore<Score>(cosmosSettings);
builder.Services.AddCosmosStore<Player>(cosmosSettings);
}
}
}