question

ErasmoSolazzo-9187 avatar image
1 Vote"
ErasmoSolazzo-9187 asked ErasmoSolazzo-9187 commented

Azure Function with native dll x64

Hi, I am facing a strange issue.

i need to use in an Azure function some native dll (x64 dll).
Locally function works but when deploy function to Azure I obtain a BadImageFormat exception when native dll are called.

I set 64 bit on Azure portal, compiling with x64 and publishing with Configuration Release x64 and target runtime win-x64.

i use Net Core 3.1 and Azure Function 3.0.9

Am i missing something?

azure-functions
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ErasmoSolazzo-9187 Please let us know if the information provided in this case.

0 Votes 0 ·

1 Answer

JayaC-MSFT avatar image
1 Vote"
JayaC-MSFT answered ErasmoSolazzo-9187 commented

@ErasmoSolazzo-9187 By default apps are actually set to run on 32-bit . But, you have also confirmed to modify the bitness from portal. ( could you share a screenshot)
It may be worth looking into the bin/ of the build and seeing if you see the right runtimes/ folder being generated with native libraries.
Could you also share the entire call stack of the exception?
Also, Please follow these steps:

  • Go to https://resources.azure.com/

  • Find your function app, and go under config/web under it in the tree

  • check the value of use32BitWorkerProcess, whether it is false.

Please let me know if this helps.

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

22207-image.png


22208-image.png



Value of use32BitWorkerProcess is false.
I attached azure portal and visual studio configuration, it is all x64.


I speculated that problem can be visual c++ redistributable lack.
I added needed dll into bin folderwith function dll, but I receive always the same exception: An attempt was made to load a program with an incorrect format.

Have I to put redistributable dll into some other folders?

1 Vote 1 ·
image.png (34.0 KiB)
image.png (19.0 KiB)

You don't have to explicitly load/install it. Azure App Service is a PaaS offering running in a sandbox and the required libraries are already installed.

You may refer to this to check which package is installed for your app service. [ Note : as this document is old you may not see the latest VS example but it would guide you to check the version details of the library]

Also, could you please share the folder structure details where you have put the dll.

Suggestion : You may consider running the application in an Azure VM where you can manage the OS and the installed libraries yourself and see if you are still encountering this problem ( if this option is feasible at all)


0 Votes 0 ·

Ok.

I was working with function for consuption plan feature so a VM is not a feasible solution.
I will evaluate other scalable solution like AKS with KEDA or alternatively other cloud vendor.

Thank you

1 Vote 1 ·

I check with reg query and Redistributable 2013 and 2015-2019 (that my library need) are absent.

I test on a VM without these libraries and I obtain the same exception. Putting redistributable dll in exe folder it works.

I think that azure function runtime folder is not bin folder.
Redistributable dll are in folder D:\home\site\wwwroot\bin where function dll is located.

Can I access to folder where process is running and putting there dll redistributable or update Path enviroment variable to specify folder bin?

0 Votes 0 ·

Azure App Service/Azure Function runs in a secure environment called a sandbox which imposes certain limitation. Limitations like playing around some com components , writing to registry , User32/GDI32 restrictions. The sandbox is described here. ( already mentioned in the previous comment)

I am afraid you won't be able to access the console and install any 3rd party libraries which run via a script, ex: EXE or MSI.

So if you have anything related to any of these Sandbox restriction then going for Azure VM will make more sense. I believe you have already tested with Azure VM and it works fine for you.

If you think this answer helped , please "Accept the answer" and "Up-vote" so that it can help others in the community.

0 Votes 0 ·