projectkudu / kudu

Kudu is the engine behind git/hg deployments, WebJobs, and various other features in Azure Web Sites. It can also run outside of Azure.
Apache License 2.0
3.13k stars 652 forks source link

IIS fails silently to load a custom managed module (distributed via a site extension) targeting NET framework webapp(s) #3504

Closed sanikolov closed 7 months ago

sanikolov commented 9 months ago

Repro steps.

My project is built successfully with MSBuild version 17.8.5+b5265ef37 for .NET Framework The resulting artifacts are then packaged as a private nupkg site extension and deployed via kudu endpoints

Project structures.

project structure is not applicable because build, packaging, deployment are separate steps, not necessarily governed by Visual Studio. I am attempting to deploy a private site extension, not a web app.

The log/error given by the failure.

No error is shown. The failure to load our custom managed IIS module is silent.

Debug your Azure website remotely.

Partial subscription ID: 8078 .. 6881 The subscription ID and other IDs shown in gist links below are made up, do not use. I am not convinced that a debugger can attach early enough to catch module loads because the site extension operates externally to the webapp. Module loads are governed by the applicationHost.config not the webapp's own web.config.

Mention any other details that might be useful.

I run the deployment script as follows

powershell -file deploy.ps1

That script uploads a nupkg file to endpoint https://mysitename.scm.azurewebsites.net/api/siteextensions/Foo.SiteExtension via an http PUT method.

Expectations:

  1. the contents of the nupkg file is extracted to the filesystem in D:\home\site\SiteExtensions\Foo.SiteExtension\
  2. install.ps1 runs
  3. managed module Foo.HttpModule.dll specified in applicationHost.xdt (see below) will either get loaded or an error will be printed by w3wp.exe if it failed to load it

Observations:

The new extension is properly registered in the azure portal under Extensions. Good. However

  1. the nupkg contents is NOT extracted to the filesystem. The only file in folder D:\home\site\SiteExtensions\Foo.SiteExtension\ is SiteExtensionStatus.json which shows that ProvisioningState is Succeeded
  2. install.cmd runs ok. Good. install.ps1 which is launched from install.cmd (see below) fails to run properly however
  3. Foo.HttpModule.dll load into IIS fails silently. ProcessExplorer shows an open handle to it but the Modules tab shows that it failed to load (it is missing in the list of modules).

My question is why my observations diverge so significantly from expectations, especially with regard to the load of our custom module.

install.cmd follows

:: cwd=C:\home\site\SiteExtensions
mkdir ..\..\LogFiles\Foo  # created successfully, good
echo "starting installation" > ..\..\LogFiles\Foo\install.log
# upon deployment the echo command works as desired
powershell install.ps1 >> ..\..\LogFiles\Foo\install.log
# the powershell invocation doesn't do anything, output is not visible in the install.log
echo "powershell script exited" >> ..\..\LogFiles\Foo\install.log
# the 2nd echo works too

install.ps1 follows

$now=Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Write-Host "install.ps1 script running at", $now

applicationHost.xdt file generated by extension IIS Manager follows

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location path="" xdt:Locator="Match(path)">
   <system.webServer>
     <modules>
       <add name="FooHttpModule" type="Foo.HttpModule.Module, Foo.HttpModule, Version=1.5.1.0, Culture=neutral, PublicKeyToken=78d1e484ed7e5fac" xdt:Transform="InsertBefore(/configuration/location[(@path='')]/system.webServer/modules/add[(@name='EnvVarSetModule')])" />
     </modules>
   </system.webServer>
 </location>
</configuration>

scmApplicationHost.xdt follows

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
   <runtime xdt:Transform="InsertIfMissing" >
     <environmentVariables xdt:Transform="InsertIfMissing">
     </environmentVariables>
   </runtime>
 </system.webServer>
</configuration>
jvano commented 7 months ago

Hi

If the problem persists and is related to running it on Azure App Service, please open a support incident in Azure: https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request

This way we can better track and assist you on this case

Thanks,

Joaquin Vano Azure App Service

JaroDunajsky commented 5 months ago

Installation of the nuget package follows simple rules. It expands files only from the folder called 'content' of the nuget package. The install.cmd is expected to do the rest of the work. The nuget package is left in the \home\SiteExtensions folder for further customizations. The nuget package used when the original problem was reported also includes 'runtime' folder in the nuget package. Install.cmd would need to take care of custom installation steps and making sure the http module is found. You could consider manual experimentation by setting up the SiteExtensions folder manually and see if it works as expected. Then you modify the install.cmd to match the working layout. Please note that adding custom http modules is a very rarely used experience and it's not optimized for easy consumption.

Jaro Dunajsky Azure App Service