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?
CodePudding user response:
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 thehost.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.
CodePudding user response:
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)