I am trying to load a Silverlight project to read every XAML file by creating an instance using reflection, Activator.CreateInstance, of every XAML class for reading its controls.
C# Code:
string strPath = "SilverlightUI.dll";
StreamResourceInfo sri = Application.GetResourceStream(new Uri(strPath, UriKind.RelativeOrAbsolute));
AssemblyPart assemblyPart = new AssemblyPart();
Assembly assembly = assemblyPart.Load(sri.Stream);
Type[] typeArray = assembly.GetExportedTypes();
foreach (Type type in typeArray)
{
object ctl = (object)Activator.CreateInstance(type);
// Following exception is occurring while creating an instance using above line of code
// Exception "Cannot find a Resource with the Name/Key ComboBoxStyle"
}
Perhaps, reflection is not able to recognize Silverlight style ComboBoxStyle. How can i possibly create an instance to read every control in the XAML file dynamically?
I have managed to find the required solution to my problem after struggling with the Google.
App.xamlof the Master/Caller Silverlight project or application, which is using the reflection code to load the Silverlight Controls informationFollowing these steps will eliminate the XAML Parse Exception of missing Style.
Reference: XAML Parser cannot find resource within dynamically loaded XAP when creating form instance