Deployment Parts in a Windows Phone App

My apologies in advance as this is a little bit of an obscure scenario but I thought I’d share this information in case others found it useful.

Imagine if you will the following scenario. You have a dll project which can make use of other “provider” libraries. These are optional and the main dll should function regardless of whether the provider is present or not. The issue is this – you need to detect from your library whether this provider dll is present at runtime. In traditional .NET you would use reflection but not all aspects of this are available in the Silverlight model. Instead there is a way to interrogate all the assemblies within the XAP from the Deployment class. The following code snippet shows how to check for a particular assembly:-

bool featurePresent = false;

foreach (System.Windows.AssemblyPart part in System.Windows.Deployment.Current.Parts)
   if (part.Source.ToString().Contains(“FeatureAssemblyName”))
      featurePresent = true;

Published by Peter Freeman Foot

Microsoft Windows Development MVP