0

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
3
  • Please share your GitHub repo if possible?Or else share your folder structure og GitHub. Commented Dec 23, 2023 at 8:01
  • 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/… Commented Dec 23, 2023 at 16:07
  • Can you please share the GitHub repo once again. Iam unable to open the link. Commented Dec 26, 2023 at 8:14

1 Answer 1

0

Do I need to change something in my global.asax or web.config files?

  • Global.asax file has nothing to do related to Package issues.

  • You need to check the Web.config ,packages.config and .csproj files.

  • I can see the System.Web.Http.WebHost under the Project References.

enter image description here

  • Open the .csproj file (can be seen in the root directory of the Application)

enter image description here

OR

  • Right click on the Application =>click on Unload project, .csproj will be opened.

  • I can see the below Reference for System.Web.Http.WebHost in .csproj file.

  <Reference Include="System.Web.Http.WebHost, Version=5.2.9.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    <HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.9\lib\net45\System.Web.Http.WebHost.dll</HintPath>
  </Reference>
  • If you don't have the above configuration, add it in .csproj file (with your required version), save => Reload the project.

  • Remove the bin folder from the deployed Azure App Service.

  • Build and re-deploy the Web App.

  • I am able to deploy the App to Azure App service successfully.

  • Push the below folder to GitHub Repo including Packages folder.

enter image description here

  • There is no change in the yaml file except the run under Publish to folder .
 - name: Publish to folder
   run: msbuild /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="\published\"

Deployment:

enter image description here

Output:

enter image description here

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

Comments

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.