Self healing applications in .NET

The most common cause of failure is an un-handled exception caused by unexpected format of data. When such a thing happens, human intervention is required, which involves restarting the application. What if we can get the application to notify us when this happens and then restart itself?

Notifications when there is an un-handled exception is a common practice. If you are not already doing it, you must be. All it takes is a few lines of code. In the event handler for un-handled exception, log the exception details and send an email out to the dev team (ensure through TDD that there can be no failures in the email sending part!!!). Going on to the next step, if the application restarts itself we can have a self healing application.

Since it is not possible to restart itself, we will use a helper. A second application that wraps around the main application. The helper wraps the main application in an App Domain and monitors for exceptions. All un-handled exceptions from the App Domain are caught, notified, logged and the application restarted. Here we can setup a new App Domain. So the application keeps running even during failures.

There will be situations when the problematic data keeps tripping the application and may keep failing over and again. Having a threshold of the number of consecutive fails helps escalating the issue. It can follow escalation by sending an email on the first fail, email with high priority for the second fail and an SMS for the third failure. At this point the wrapper application can wait for human intervention and not restart the application.

 

Namaste

Nrupal

 

Raspberry Pi and Windows 10 IoT

Being able to run Windows 10 on Raspberry Pi is one of the best news I read a few months back. I was planning on using the Pi to control lights and automate a few things in the house. Being able to program against GPIO in C# is amazing. So I started out with downloading the ISO and setting up the Pi with Windows 10. There are numerous blogs detailing the process.

The website to administer the Pi is amazing. That website should be open sourced and explained how to setup more like that. Since I will be relying on the Pi for lights, heat, other sensors in the house, I would like it to be reliable to say the least. So the first test is to let the Pi run without any other programs on it and check how long it is running without crashing. It turns out that I had to restart several times to access the Pi as it kept dropping from the network. Checked on the router for connected devices before jumping to the conclusion that Pi has crashed. Once the lights and sensors are wired to the Pi, I would want to keep the down time to a minimum and the requirement to restart the system to zero.

Windows 10 IoT on the Pi is not reliable enough to run security systems or for running extended periods. I had to switch to Raspbian and NodeJS to get a reliable system. The NodeJS site has been up and running since a week without any problems.

The actual wiring details and setup along with code to control lights in the house will follow.

 

Namaste

Nrupal

 

Running Silverlight Application in a Console App

Silverlight is officially dead. There was a time, though brief, when Silverlight was the choice to develop new UI apps. Silverlight was the natural choice when UI had to be browser independent, platform agnostic and be able to develop using the goodness of the .NET Framework.

What happens to all the applications when a framework dies?

They are either re-written or still supported by until they have served their purpose. When there is a lot of business logic stuck in the Silverlight Application, how do we re-use this?

I happened to come across a situation where the Silverlight application generates binary data files which can be read or updated by the Silverlight application only. We do not need the UI to come up, we need just the data to be accessible from a console application if possible. Can we use a library built with Silverlight framework in a Console application being built in the full .NET Framework? The answer turns out to be Yes!

App Domains to the rescue.

.NET Framework has an amazing feature of AppDomains, which allow us to set boundaries and sandbox applications. It is possible to build a console app referencing Silverlight libraries and then running it in an AppDomain so that we can switch the framework Dlls at runtime.

If the Silverlight application uses third party libraries, all those need to be dropped into the bin folder and loaded into the App Domain.

There will be warnings during compile time complaining about mismatch of the System.dll and System.Windows.dll versions. Ignore these warnings and switch the Dlls with the ones from Silverlight runtime when starting the AppDomain.

To run the SL app in Console app, we will need two Console Applications. The first one will be run in the normal .NET Framework and is responsible for triggering the AppDomain which will load the required Silverlight libraries for the second console application which contains all the BL required to access the SL app.

The most important thing is to ensure that the correct version of System.dll and System.Windows.dll are loaded into the AppDomain at runtime.

 

Namaste.

Nrupal.