I’ve been updating our company’s Christmas bake-off site and as part of the update I added the Microsoft.Identity.Web project to help with authentication and accessing the Graph API. This project doesn’t currently have a NuGet package though one is apparently in the works so I included it by taking a local copy and adding it to the solution and then referencing it in the bake-off project.

This worked as expected when running in debug locally but when I published the Web App I received the following error.

An error occurred while starting the application.
.NET Core 4.6.28008.02 X86 v4.0.0.0    |   Microsoft.AspNetCore.Hosting version 2.2.7-servicing-10089    |    Microsoft Windows 10.0.14393    |   Need help?

This wasn’t that informative but it’s possible to enable more descriptive error messages by adding the following application setting in the portal.

ASPNETCORE_DETAILEDERRORS = true

After adding this setting and restarting the Web App I got the slightly more useful error below.

FileNotFoundException: Could not load file or assembly 'Microsoft.Identity.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

From this message and from viewing the Release folder generated on build it appears that Microsoft.Identity.Web.dll is being copied into the folder then building or running locally but is not being created as part of the publish process.

After some investigation and finding this blog post it appears that this is intentional on Microsoft’s part but that if you want to include referenced resources you can specify this in the projects csproj file (not recommended) or better yet the publish file. If using DevOps then this will need to be added as a “Publish Artifact”.

The solution is to add the following property to the “PropertyGroup” section of the csproj or publish profile files.

<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *