3

My azure function is returning error: Azure Functions runtime is unreachable

    System.Reflection.ReflectionTypeLoadException : Unable to load one or more of the requested types.
Method 'LogFunctionStarted' in type 'WebJobs.Host.Storage.Logging.PersistentQueueLogger' from assembly 'Microsoft.Azure.WebJobs.Host.Storage, Version=4.0.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.

  at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)

  at System.Reflection.RuntimeModule.GetTypes()

  at System.Reflection.Assembly.GetTypes()

  at Mapster.TypeAdapterConfig.<>c.b__87_0(Assembly assembly)

  at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()

  at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToList()

  at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

  at Mapster.TypeAdapterConfig.Scan(Assembly[] assemblies)

  at DTSQuickHit.Functions.Startup.Configure(IFunctionsHostBuilder builder) at E:\buildagents\Agent03\_work\37\s\DTSQuickHit.Functions\Startup.cs : 32

my startup:

var environmentName = Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT");
var basePath = IsDevelopmentEnvironment(environmentName)
    ? environmentName
    : $"{Environment.GetEnvironmentVariable("HOME")}\\site\\wwwroot";

var config = new ConfigurationBuilder()
    .SetBasePath(basePath)
    .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
    .AddEnvironmentVariables()
    .Build();

Microsoft.Azure.WebJobs.Host.Storage isnt even in my project files so I dont understand the problem.

My project files:

  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.3.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.1.0" />
  </ItemGroup>

Could you please help me out with solving this?

Krzysztof
  • 152
  • 1
  • 2
  • 15
  • Is `Microsoft.Azure.WebJobs.Host.Storage.dll` building to your `bin` folder? That seems to be the issue. – James Gould May 25 '22 at 12:31
  • Yes it is building to my bin folder, but im not sure what I should do with that – Krzysztof May 25 '22 at 12:48
  • Additionally error indicates that it is related to the Microsoft.Azure.WebJobs.Host.Storage, Version=4.0.4.0 even if I added reference to the – Krzysztof May 25 '22 at 13:13
  • The `does not have an implementation` indicates the SDK is calling a method that isn't being fulfilled by `Host.Storage`. If it's building out that's step 1 - usually it means the DLL its trying to use isn't present. Your `SDK.Functions` version is `3`, is that intentional? The latest is `v4`, try updating that. – James Gould May 25 '22 at 14:01
  • Unfortunately I cannot do that, my app is targeting .net core 3.1 and v4 is targeting .net 6 – Krzysztof May 25 '22 at 16:12
  • Are you using reflection @Krzysztof anywhere in your code? We were using `AppDomain.CurrentDomain.GetAssemblies()` and it looks like Azure have rolled out an update that has stopped this from working – Toby Scamell May 27 '22 at 11:16
  • Is this issue resolved? – kudlatiger Feb 18 '23 at 04:16
  • Yes, solution that worked for me is at a very bottom. – Krzysztof Feb 20 '23 at 07:26

7 Answers7

4

In case any solution related to the storage account setting in the function app is not working following can be the reason.

Your function worker runtime failed to start and now because Azure does some fancy stuff in the background to redeploy resources ASAP, it somehow binds the name of your function to the worker so it'll keep failing even if you redeploy.

The solution to this is to just scale the underlying app service plan to force the function site to start on a new worker. Once the scaling is done the worker runtime will be available again.

I hope this helps :)

2

When I got this issue, my Azure functions runtime is set to 4.x but my Microsoft.NET.Sdk.Functions is at 3.0.13 when it should be at least 4.0.0 as stated on the Microsoft documentation. I just upgraded that package to the latest version and it worked fine.

Raffy
  • 515
  • 1
  • 8
  • 12
1

One more scenario for the similar failure

I had the same similar issue where Azure Function app was complaining about "Azure Functions runtime is unreachable". According to documentation provided by azure nothing has really helped me. But here is the reference it might help you: https://learn.microsoft.com/en-us/azure/azure-functions/functions-recover-storage-account

For me, there was an issue with private endpoint on storage account. If your storage account is behind the private endpoint then add outbound connection in your function app to the same vnet to which storage account's private endpoint is part of.

That didn't work for me as well because I already had those network configurations in place. For me issue was with function implementation and function.json where queueTrigger was using the same storage account which was used to host the functions.

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "msg",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "azcopy",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

I had app config variable "AzureWebJobsStorage" and is used by function app to load the functions from storage account and for that I just need to provision the private endpoint for blob sub-resources. However, as functions were calling the queue I needed the private endpoint for queue sub-resource as well.

here is terraform example to provision private endpoint for storage account with queue sub-resources.

resource "azurerm_private_endpoint" "storage_queue_inbound" {
  name                = "queue-private-endpoint"
  location            = azurerm_resource_group.resourcegroup.location
  resource_group_name = azurerm_resource_group.resourcegroup.name
  subnet_id           = azurerm_subnet.app_service_inbound_subnet.id
  depends_on          = [azurerm_storage_account.storage]
  private_service_connection {
    name                           = "queue-private-endpoint"
    private_connection_resource_id = azurerm_storage_account.storage.id
    subresource_names              = ["queue"]
    is_manual_connection           = false
  }
}
Nitin Singh
  • 231
  • 3
  • 9
0

When you get the error like Azure Functions Runtime is unreachable, then the main reason would be Storage Account connection issue.

Please check the steps given in this thread to fix this issue.

If the above steps not helped to fix, check the below step:

  • Make Sure the local.settings.json file is in the same place as the host.json file located (at the project root).
  • Modify the code of getting env variable like this:
var environmentName = Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT", EnvironmentVariableTarget.Process);
  • And the basic Configuration should be like:
public class Startup : IWebJobsStartup
{
    public void Configure(IWebJobsBuilder builder)
    {
        var config = new ConfigurationBuilder()
            .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
            .SetBasePath(basePath)
            .AddEnvironmentVariables()
            .Build();
    }
}

Also, please refer to this GitHub issue-6239 in Azure Functions which states about setting the AZURE_FUNCTIONS_ENVIRONMENT in startup class having some issues and the given temporary fix.

0

Thanks @HariKrishnaRajoli-MT for your post. Accually I checked thread you mentioned but nothing seemed to fix my issue, what I did instead: I`ve deployed clean function project to Azure which worked and it stared properly and then deployed the proper one which was failing but now it magically worked. I believe that during deployment (because I used many ways of deployment in .yaml file) some of the default might have been overwriten but im not sure)

Krzysztof
  • 152
  • 1
  • 2
  • 15
0

This is tracked on Github, please follow the issue here https://github.com/MicrosoftDocs/azure-docs/issues/92820

  • this should have been comment. – SRIDHARAN May 28 '22 at 08:56
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – SRIDHARAN May 28 '22 at 08:57
0

Please make sure your storage account is accessible by azure function app.

For example if you set deny blob public access or disable public network access on the firewall you may get the error message: "Azure Functions runtime is unreachable".

This is because azure function requires some kind of storage to store triggers, bindings etc.

I am not saying that you should make your blob publicly available. Just make sure that azure function app can talk to storage account.

Roman Pelikh
  • 31
  • 1
  • 8