Azure and C++ DLL files

K Amen 1 Reputation point
2021-05-05T16:20:00.31+00:00

I have a web app on Azure. It uses .NET Core 3.1. I use two DLL files as dependencies in the app. The first C# DLL depends on or uses the second C++ DLL. When I run the project in Visual Studio locally, there is no issue. When I deploy the app to Azure, it complains only from the second DLL, and it says "unable to load dll or one of its dependencies". As I said the first DLL uses the second DLL in its codes by using " [DllImport(@"..\Folder\Second.dll")] ". What do I need to do or add to the web app? Why it is working locally and not on Azure? Any help would be appreciated.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,306 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,544 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,956 questions
{count} votes

3 answers

Sort by: Most helpful
  1. ajkuma 22,521 Reputation points Microsoft Employee
    2021-05-06T06:38:19.75+00:00

    @K Amen , Thanks for the good question.

    Just to clarify, are you provisioning it on Azure App Service Web App or Azure Cloud Service/or on an Azure VM?

    Just to highlight, since App Service is a fully managed service, it doesn't support installing custom MSIs and custom executables on the underlying workers.
    (cannot install custom DLLs in locations other than the file directory structure of the app).

    The Azure App Service WebApp runs applications in a sandbox as part of the multi-tenant architecture. The App Service sandbox is discussed in this article.

    However, you can try the following to see if you can get your app to successfully find and load the DLL.

    You may try setting the DLL file in your project as ‘Copy always’, change the DllImport command to point to "./bin/mylib.dll" and see if that helps.

    1. Ensure that the native DLL is copied into the /bin subdirectory App
    2. Define the following DllImport, somewhere in your WebApp - (Looks like you have already defined this)
    3. Next, in the startup code path of your WebApp, before you call into your managed wrapper, explicitly include the /bin directory of your WebApp in Windows’ default DLL search path.

    Also, in the Azure Portal, under 'Configuration' Settings’ ('General Settings') of your WebApp, if the native DLL is a 64-bit DLL, ensure to set the ‘Platform’ setting for the app to 64-bit and then check.

    I see that you have also posted this on SO, and have received answers on it, you may also take a look into the suggestions outlined.

    Additional info: App Service -Operating System functionality


  2. K Amen 1 Reputation point
    2021-05-14T21:25:36.22+00:00

    The main project is DotNet Core Web API and ModelView project that is used by the main project. The ModelView project uses a C++ DLL file. When I run the main project in VS and local IIS, it works. When I push the project to remote IIS (Azure), it complains from the DLL file. It says that the file is unable to load or one of its dependencies. The error shows that it cannot find the DLL file in the local path where my VS resides. Is the issue with DLL or the path is not updated when the project is pushed remotely? Why the ModelView project is still pointing to the local path where my VS project is located?

    System.DllNotFoundException: Unable to load DLL 'RateModule_PAMI.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)

    at App.Application.Features.GetHandler.Handle(GetQuery request, CancellationToken cancellationToken) in C:\Users\UserName\Source\Repos\Service\App.Application\Features\Q\Queries\Module\GetHandler.cs:line 55

    Why is still pointing to my local VS project?


  3. ajkuma 22,521 Reputation points Microsoft Employee
    2021-05-31T04:40:58.9+00:00

    Sharing offline discussion/solution: To benefit the community

    The issue was solved by removing the debug mode from the dll, and leaving it only with msvcrt.lib. This was causing trouble though the deployment was selected to release mode, but was defaulting to the debug mod. By removing it manually it solved the issue.

    Thanks @K Amen for your follow-ups and collaboration.