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.