Mohit Giri
Mohit Giri

Reputation: 1

ModuleInitializeException on Azure Deployment: Missing Dependencies for Microsoft.Identity.Web.Certificate Version 1.25.3

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:

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

Upvotes: -1

Views: 88

Answers (1)

Sirra Sneha
Sirra Sneha

Reputation: 1087

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

Upvotes: 0

Related Questions