Azure function can't read a static file occasionally

Zhengxiao (Edward) Wang 0 Reputation points Microsoft Employee
2024-02-06T08:50:37.25+00:00

I'm using a timer triggered azure function in .NET.

Azure function info:
runtime version: 4.29.1.21919
file system: windows

.NET version: .NET6.0

I have a static json file which is published to the azure function runtime environment. It is placed in the root of the project and I use the following code to get its path:

Path.Combine(context.FunctionAppDirectory, 'myconfig.json')

The weird thing is that the azure function occasionally throws FileNotFound error on this file. Sometimes the azure function can read the file and sometimes it can't, without any code or azure function configuration change. Does anyone have any idea about why this happens?

---Update on 2024-02-26: BTW, I'm using the Azure function hosted in Premium Plan.

I used the same way to read configuration file in other azure functions hosted in Consumption Plan and such error doesn't happen ever.

So I suspect the premium plan is the one to blame. But because my azure function requires ~3GB RAM and the Consumption Plan has 1.5 GB memory limit so I have to choose the Premium Plan.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,539 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Sedat SALMAN 14,155 Reputation points MVP
    2024-02-06T11:03:48.5733333+00:00

  2. Albert Tanure 0 Reputation points Microsoft Employee
    2024-02-07T09:25:29.7966667+00:00

    Hi Zhengxiao, your question is interesting. I would like to understand a bit more your approach to load this file from the root folder. If the case is to maintain configurations, a good approach is to use the Azure App Configuration. It's a good way to manage configurations of your application. Kind Regards, Albert Tanure


  3. MayankBargali-MSFT 70,861 Reputation points
    2024-02-09T11:02:55.7866667+00:00

    @Zhengxiao (Edward) Wang Thanks for reaching out.

    To answer your question on how to read any file you can use the below. I am using the below code to get the file path and it is working as expected and didn't observe any issue. Environment.GetEnvironmentVariable("HOME") + @"\site\wwwroot{director(if any)\youfilename}

    In case if you are still facing the issue then please let me know.

    Please 'Accept Answer' if it helped so that it can help others in the community looking for help on similar topics.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.