-1

I'm using

<PackageReference Include="Microsoft.Identity.Web.Certificate" Version="1.25.3" />

in my project. The application runs successfully on my local machine. However, when deployed to any environment in Azure, I encounter a ModuleInitializeException error. This error message states that "Azure.Identity" cannot be loaded for the module C:\home\site\platform\app_data\modules\TestModule.Web.dll. Application Event Logs -> Error PackageReference

Upon investigation, I found that the following libraries are missing in the Azure environment, causing the issue:

  • Azure.Security.KeyVault.Secrets.dll
  • Microsoft.Identity.Client.Extensions.Msal.dll
  • Azure.Identity.dll

These libraries appear to be related to the Microsoft.Identity.Web.Certificate package. I have tried upgrading and downgrading the package version, but the issue persists.

Any suggestions for resolving this error? Missing Libraries

4
  • Please don't post images of code, errors, logs, or other text; see How to Ask Commented Nov 4, 2024 at 21:13
  • @Mohit Giri Is this a .NET Core or .NET Framework application? Commented Nov 5, 2024 at 7:38
  • Please share your .csproj file Commented Nov 5, 2024 at 9:22
  • Please add <CopyLocalFileAssemblies>true</CopyLocalFileAssemblies> in <PropertyGroup> tag of your csproj file Commented Nov 5, 2024 at 9:42

1 Answer 1

0

The error you’re encountering ModuleInitializeException is related to missing dependencies of the Microsoft.Identity.Web.Certificate package.

  • Sometimes, transitive dependencies are not automatically included. You can do this by explicitly adding the missing packages to your project file.
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.4.0" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="3.0.0" />
<PackageReference Include="Azure.Identity" Version="1.9.0" />
  • If you’re deploying the application via Azure DevOps, GitHub Actions, or any CI/CD pipelines, check the build output and ensure that all relevant DLLs are being published to the output directory.
  • Makesure that your .csproj file is properly configured to copy all necessary files to the output directory.
  • Thanks @Antti K. Koskela for clear explanation I’ve referred this doc and added the below lines to my .csproj file
<PropertyGroup>
 <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

This setting ensures that all DLLs are copied to the output folder when building locally or in CI/CD.

Now after making the above changes I can see the DLLs in my Azure Web App.

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

We tried explicitly adding the missing dependencies and enabled the CopyLocalLockFileAssemblies setting, but the issue still persists.
If you're using free or basic app service plan, try to upgrade it to standard or premium.
We are already using the premium i.e Premium v2 P2V2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.