.NET Framework 4.8 Api displays assembly error in Azure AppService after Deployment

I have an api that uses the .Net framework 4.8 that works on my local. I deployed it to an Auzre App Service. Below is my yml for the deployment. The deployment works, the github action kicks off after check in, the jobs for building and deploying work, the App Service recognizes the successful deployment, and the files are copied to the correct wwwroot folder. The problem is if I try to access an endpoint I get an assembly error. If I navigate to the url for the app service, I get an error page. The api works on my local. It looks like there’s a package mapping error.

How do I fix this so my app service api works? Do I need to change something in my global.asax or web.config files?

My github action yml:

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy ASP app to Azure Web App - MyAppApi

on:
  push:
    branches:
      - my-branch
  workflow_dispatch:

jobs:
  build:
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v4

      - name: Setup MSBuild path
        uses: microsoft/[email protected]

      - name: Setup NuGet
        uses: NuGet/[email protected]

      - name: Restore NuGet packages
        run: nuget restore

      - name: Publish to folder
        run: |
          msbuild "MyProject.Api\My.Api.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder  /p:_PackageTempDir="\published\"
          dir \published
            
      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v3
        with:
          name: ASP-app
          path: '/published/**'
  deploy:
    runs-on: windows-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v3
        with:
          name: ASP-app
      
      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'MyAppApi'
          slot-name: 'Production'
          package: . 
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_--- }}

Here is the error from the App Service’s url that I get when I visit it in the browser.

[FileLoadException: Could not load file or assembly 'System.Web.Http.WebHost, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   CriticalWebApi.Convert.Areas.HelpPage.HelpPageAreaRegistration.RegisterArea(AreaRegistrationContext context) in C:\Work\CriticalPath\CriticalWebApi.Convert\Areas\HelpPage\HelpPageAreaRegistration.cs:24
   System.Web.Mvc.AreaRegistration.CreateContextAndRegister(RouteCollection routes, Object state) +104
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(RouteCollection routes, IBuildManager buildManager, Object state) +190
   System.Web.Mvc.AreaRegistration.RegisterAllAreas(Object state) +35
   System.Web.Mvc.AreaRegistration.RegisterAllAreas() +7
   CriticalPath.Zametek.Api.WebApiApplication.Application_Start() in D:\a\critical-path-api\critical-path-api\CriticalPath.Zametek.Api\Global.asax.cs:16

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http.WebHost, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +475
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +176
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +220
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +303

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http.WebHost, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +659
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +89
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +189

  • Please share your GitHub repo if possible?Or else share your folder structure og GitHub.

    – 

  • The repo is here: github.com/critical-pass/critical-path-api The project is named: CriticalPath.Zametek.Api. I tried to to follow the following post and now I get the same error on my local: stackoverflow.com/questions/20323107/…

    – 




Leave a Comment