Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Function fails to find file

Tags:

function

c#

azure

I have an azure function that uses the Azure context. When I execute my function from visual studio 2019 on my machine, it executes correctly. However when I publish this to my Azure account, I get an error that the my.azureauth file cannot be found.

Could not find file 'D:\Program Files (x86)\SiteExtensions\Functions\2.0.12950\32bit\my.azureauth'

The code that is used:

var authFilePath = "my.azureauth";
Console.WriteLine($"Authenticating with Azure using credentials in file at {authFilePath}");
azure = Azure.Authenticate(authFilePath).WithDefaultSubscription();
sub = azure.GetCurrentSubscription();

Console.WriteLine($"Authenticated with subscription '{sub.DisplayName}' (ID: {sub.SubscriptionId})");

This is code that I found on one of the Microsoft tutorials. I have set my my.azureauth file to "Copy Always".

Could anyone point my in the right direction?

like image 264
James87262 Avatar asked Oct 20 '25 12:10

James87262


2 Answers

You are get this file path because the Directory.GetCurrentDirectory() would return D:\Program Files (x86)\SiteExtensions\Functions\2.0.12950\32bit instead of D:\home\site\wwwroot\ or D:\home\site\wwwroot\FunctionName.

And if you want to get the wwwroot folder or the function app directory you should use ExecutionContext. Further more information you could refer to this wiki doc.

So the right file path should be context.FunctionDirectory+"\my.azureauth" or context.FunctionAppDirectory+"\my.azureauth", which one to use depends on where your file is stored.

like image 50
George Chen Avatar answered Oct 23 '25 02:10

George Chen


I have found that Kudu is extremely useful in seeing what has been deployed to Azure.

Navigate to your function in the Azure portal. The instructions here will help get to the kudu console.

From there you can browse the files which have been deployed into your function's file system.

If you add " , ExecutionContext context)" at the end of the function's run entry point, you can then get the folder which your function is running from with this line of code,

var path = context.FunctionAppDirectory;

PS apologies for any formatting I am editing this on my phone.

like image 45
Mike Williams Avatar answered Oct 23 '25 03:10

Mike Williams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!