What is self-contained deployment mode, works locally but not after deploying

It happens very often that an application is coded, configured and tested on a local machine and when deployed to an Azure App Service or any other machine, for some reason there are unexpected errors and exceptions.  Let the debugging begin.

I wrote this article “ASP.NET Core 2.1 and HTTP Error 502.5 – Process Failure” some time ago when it was not possible to run an ASP.NET Core application in 64 bit mode, but if the customer wanted or required that, the application would work locally but when deployed, it did not.  This was the solution, I.e. making a self-contained deployment.

But what does self-contained deployment mean and how does it look on an Azure App Service when compared to a ‘non’ self-contained deployment?  Also, after having written these Web App for Container articles, what is the difference between Docker and self-contained?

What is a self-contained deployment, what does it look like?

There is a very nice description of that here “Self-contained deployments (SCD)”.  The benefit is that the version of .NET Core which you have working on your local machine will be the same one it targets when deployed.  The deployment of an self-contained application is larger because it contains all the binaries required to run your application.  An example of a deployed self-contained application is shown in Figure 1. image

Figure 1, my application works locally but not when deployed

Notice that there are 299 displayed modules, I don’t consider this a bad thing, it is just something you get when you deploy a self-contained application.  KUDU/SCM which I have described here, rendered only 300 items and if you need more you need to set the maxVIewItems as stated in the popup within the applications.  Figure 2.

 
ERROR
There are 390 items in this directory, but maxViewItems 
is set to 299. You can increase maxViewItems by setting 
it to a larger value in localStorage.

image

Figure 2, my application works locally but not when deployed, KUDU / SCM maxViewItems

In contrast, see how the ‘non’ self-contained deployment footprint looks like, Figure 3. image

Figure 3, my application works locally but not when deployed

It is smaller, as expected, however if your deployment begins to work using this mechism, then you will know that their is something in the application that is special, or needs some specific configuration which is not supported by default on the platform.  Knowing the configuration details of an application requires serious application knowledge and isn’t ‘usually’ something a platform person would know immediately.  At a minimum, this is a way to isolate the application issue from a platform issue. 

How to create a self-contained deployment

You right-click on the project you wish to publish and selecte the Publish menu item, as seen in Figure 4.

image

Figure 4, my application works locally but not when deployed, how to publish self-contained application

Then when the window shown in Figure 5 is rendered click on the Advanced… link. image

Figure 5, my application works locally but not when deployed, how to publish self-contained application

Next, make the changes similar to those shown in Figure 6.  Selecting those values which are required to run your application. image

Figure 6, my application works locally but not when deployed, how to publish self-contained application

If you have already made a publish, I would recommend that you click “Remove additional files at destination” so that any unnecessary files are removed during this deployment.  Finally, click the Save button and publish in the same way which you would any Azure App Service.  I would then expect the application which is working on your local machine to work on the Azure App Service platorm.  Now, it is up to you to determine what configurations have been made in the application that do not run on the platform.  It is up to the developer/support to determine if you remain in this container or if you root cause and find the custom configuration which does not run as expected on the platform.

How is a self-contained application different from a Docker container or Web App for Containers?

The answer comes down to the inclusion of the operating system in the deployment versus not doing that.  As you may know then you create a Docker image, the image includes the operating system in addition to the applications.  While a self-contained deployment does not contain an operating system, instead only the binaries required to run your application.  A self-contained deployment uses the PaaS operating system.