Yellow Panda
Yellow Panda

Reputation: 141

Azure Functions creating another bin folder inside bin

I am facing an issue with Azure functions seeing another bin folder being created inside bin. So Folder structure is like this bin -> net461 -> bin -> dll's. However any other file(json,xml) in the project gets copied to bin -> net461 . Due to this referencing to the file(json,xml) becomes difficult in the code. I don't need another bin folder.How to fix this?

Upvotes: 6

Views: 3174

Answers (5)

Krishna Nekkala
Krishna Nekkala

Reputation: 301

I found similar issue, and observed another bin folder getting created on building the function app like below enter image description here

This causing below error: System.Private.CoreLib: Could not load file or assembly 'Microsoft.Azure.WebJobs.Extensions.Http, Version=3.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. Microsoft.Azure.WebJobs.Extensions.Http.dll

Its looking for file in folder bin>deubug>net6.0>bin , but file exists in upper bin folder. I know its not a permanant solution as work around I manually copied file into other. It solved the issue and working. If anyone know the resolution instead manual copy will help. Thank you.

Below reference I used for function app <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" /> <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" /> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" /> <PackageReference Include="System.Data.SqlClient" Version="4.6.1" />

Upvotes: 0

Dmytro Arkhypenko
Dmytro Arkhypenko

Reputation: 36

I started to experience this issue when I uprgadded to Microsoft.NET.Sdk.Functions 3.0.11 from 1.0.38. It helped me to downgrade Microsoft.NET.Sdk.Functions to 3.0.1.

Upvotes: 1

Bruce Chen
Bruce Chen

Reputation: 18465

I try to read the file something like this File.ReadAllText(@"FolderName\FileName.json") but when function executes it gives error - Could not find a part of the path 'D:\Windows\system32\FolderName\FileName.json'.

I have checked this issue and found that your code could work on local side correctly but failed after deployed to azure side. You may need to explicitly set the absolute path to read your json file. And you could leverage Microsoft.Azure.WebJobs.ExecutionContext.FunctionDirectory to get the current function directory (e.g. D:\home\site\wwwroot\<FunctionName> for Azure side, C:\Users\xxx\FunctionApps\bin\Debug\net461\<FunctionName> for local side). Details you could follow Retrieving information about the currently running function.

The code for reading the json file would look like this:

File.ReadAllText(Path.Combine(Directory.GetParent(executionContext.FunctionDirectory).FullName,@"helloworld.json"));

Moreover, you could follow this github issue and this tutorial.

Upvotes: 2

wolszakp
wolszakp

Reputation: 1179

Maybe workaround for you will be to embed file into dll.

Embed text file into dll

And then read the content from dll.

Upvotes: 1

Naren
Naren

Reputation: 877

What you are experiencing is the default behavior. Elaborating on the structure of functions project created via Visual Studio.

The following files are part of the functions project. The files in here are actual code files generated by VS or are created by the user.

  • \FunctiaonAppName.sln
  • \FunctiaonAppName\FunctiaonAppName.csproj
  • \host.json
  • \localsetting.json
  • \Function.cs

The following files are generated by the compiling or building the functions project. The files in are here are to be deployed to Azure by following the publish steps.

  • \bin\Debug\net461\Function\function.json
  • \bin\Debug\net461\bin\functionRelatedBinaries.dll
  • host.json

The build step actually fetches all of the necessary binaries that would be required for the function app to run successfully in azure and copies them over to internal bin folder. The inner bin folder also contains all the external binaries reference by Function e.g. Newtonsoft.Json. The contents of the net461 is what needs to be deployed to azure for it to run on cloud.

Can you help me understand how does it become difficult to reference JSON / XML file with this structure. In the above case you can simply assume net461 is the root of the project output and all xml / json files would be present there.

Upvotes: 1

Related Questions