Xamarin Android “App not installed”

While getting started on Xamarin Android, I had trouble installing the app on my LG v20 phone. I kept seeing the message “App not installed” and could not figure out why? I knew my phone’s debug settings were correct. I spent some time searching online and then came to the conclusion that I needed to sign the Android application package. This is not a well-discussed problem! If this post has helped you, please leave a comment below! Thanks!

Improving performance with application initialization on Azure App Service (Windows)

Often, performance on a website isn’t what it needs to be. One way you can improve performance is to cache files to the local disk. On Azure App Service Web Apps, an application can access the local disk at D:\local\temp. This location is specific to each instance. Due to the nature of Platform-as-a-service, this location is not easily accessible to the user. However, the application has access to this location pro-grammatically. Moreover, many popular applications and frameworks have file caching as a default feature.

PHP, a popular programming language in the Open Source community, has several MVC Frameworks that include file caching. Frameworks such as Laravel, Symfony, CodeIgniter and many others. In these frameworks, the cache location can be set to the local disk on the VM rather than the storage.

An easy way to clear this cache is to restart the App Service Web App. However, this causes your application to go offline for some time. An alternate way to clear the cache is to utilize the AppInit module within IIS. The IIS AppInit module can execute a script on a W3WP process recycle. These recycles occur on restarts, application settings updates, scaling to new instances, etc. This is not a complete list and more information can be found online.

In this article, you will learn how to execute a script through an application settings update. This is not intended to be a complete solution as your use-case may vary. It is intended to show you how the AppInit module can be used within App Service Windows.

The solution has three components:

  1. Create an initialization page to be executed upon a recycle. This is the clear cache script.
  2. Set the initialization page in the web.config.
  3. Update an application setting to trigger the recycle

Here is a sample initialization page written in PHP:

<?php 
/***** File Location: wwwroot/appInit/maybeCacheClear.php
***** This script runs when the web app is recycled.
**************************************************************
You can lock the cache in two ways so it is not cleared on a recycle:
1) add the application setting 'cacheLock' and set the value to true
2) create a file, cache.lock, within this directory
******************/
if ( file_exists('cache.lock') || ("true" == strtolower(getenv('cacheLock'))) ) 
{
$message = "================================\n" . 'Time Stamp: '. date('m/d/Y H:i:s') ."\n" . "--------------------------------\n" . "Cache is locked. Cannot clear cache.\n" . 'Computer Name: ' .$_SERVER['COMPUTERNAME'] ."\n" . 'Instance ID: ' . $_SERVER['WEBSITE_INSTANCE_ID'] . "\n\n";
}
else {
//!!CLEAR THE CACHE!!
//<INSERT CODE HERE TO CLEAR CACHE>
$message = "================================\n" . 'Time Stamp: '. date('m/d/Y H:i:s') ."\n" . "--------------------------------\n" . "*** CLEARING CACHE***\n" . 'Computer Name: ' .$_SERVER['COMPUTERNAME'] ."\n" . 'Instance ID: ' . $_SERVER['WEBSITE_INSTANCE_ID'] . "\n\n";
}
// Write the contents back to the file file_put_contents('cache.log', $message, FILE_APPEND);

Now that the initialization page has been created, tie this into the web.config so it is executed on a recycle. Here is a sample snippet with the Application Initialization script configuration

<configuration> 
<system.webServer>
<applicationInitialization doAppInitAfterRestart="true" skipManagedModules="true">
<add initializationPage="/appInit/maybeCacheClear.php" hostName="mangeshnew.azurewebsites.net"/>
</applicationInitialization>
</system.webServer>
</configuration>

The last piece of the solution is within Application Settings. Here we will create a key named “cacheLock” with a value of “true”. This setting determines if the cache should be cleared or not. When the value is set to “true”, the cache is locked and will not be cleared. However, when set to “false” the cache is no longer locked and it will erase the cache from the local disk.

Now that web.config, cache clear script and Application Settings are in place, trigger a recycle by updating an Application Setting. If everything went well, you will see a message within cache.log. It should look like this:

That’s it! As simple as that. Once you’ve placed these components in place, you can utilize Application Initialization to clear cache from local instances. I hope this has helped your application design be more performant. Questions or comments? Please leave feedback below!

I moved my Git repo to a new folder and now I’m getting a ton of modified files, help!

I’m running Windows Subsystem for Linux (WSL) on Windows 10. I downloaded a Git repo under the WSL mount. I noticed that whenever I used Windows/Visual Studio Code to save files, the permissions would reset to 000. I spoke with a colleague and his setup was different than mine.

I had the Git repo inside WSL mount.

His Git repo was on the Windows/C-drive mount and he had a soft-link to the repo. He did not face the permission issue.

So after I pushed out my latest changes, I decided to move my repo. This was the easy part. I made a softlink using

ln /directory/ /linkdirectory/

However, after the repo was moved and I modified one file, it was a bit unnerving to find out that ALL the files were listed as modified. I browsed around and saw that this could’ve been due to the line-endings on Linux vs. Windows.

It wasn’t until I updated these two settings that the rotten state in Denmark became a happy state:

git config core.autocrlf true
git config core.filemode false

WordPress Assistant for Azure App Service on Windows

App Service Assistant is a WordPress plugin that provides details on important settings and configuration. This can be helpful to troubleshoot WordPress issues. Information such as current theme, theme path, WP defines, plugins, php_errors.log (if enabled), debug.log (if enabled), user.ini, app settings.

Installing this plugin is a cinch! Just follow the steps below to get it activated and running in your WordPress application.

Installation:

Plugins > Add new

Search for: app service assistant

Click Activate


How to use:

From settings menu, select “App Service Assistant”

Sample screenshot:

Location of Log File – AppAssistant.html is saved in the D:\home\LogFiles directory.

Feedback / Suggestions – Email msangapu@outlook.com