{"id":3048,"date":"2014-03-15T02:04:39","date_gmt":"2014-03-15T02:04:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/15\/problem-when-loading-xap-file-dynamically-in-during-the-runtime-collection-of-common-programming-errors\/"},"modified":"2014-03-15T02:04:39","modified_gmt":"2014-03-15T02:04:39","slug":"problem-when-loading-xap-file-dynamically-in-during-the-runtime-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/15\/problem-when-loading-xap-file-dynamically-in-during-the-runtime-collection-of-common-programming-errors\/","title":{"rendered":"Problem when loading XAP file dynamically in during the runtime.-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn<\/p>\n<p>Hi all,<\/p>\n<p>I am developing an application with multiple XAP files. I have two XAP filesc &#8211; A.xap and B.xap.<\/p>\n<p>I am loading A.xap first and want to load B.xap dynamically. But it results in an exception &#8211; &#8220;Exception has been thrown by the target of an invocation.&#8221; at the line marked as bold and italics.<\/p>\n<p>I pasting below the code I am using and the exception details that I got.<\/p>\n<p>Code<\/p>\n<p>&#8212;&#8212;-<\/p>\n<p>private void btnLogin_Click(object sender, RoutedEventArgs e)<\/p>\n<p>{<\/p>\n<p>CallSharepointSvcClient loginSvc = new CallSharepointSvcClient();loginSvc.IsAuthenticatedCompleted += new EventHandler(loginSvc_IsAuthenticatedCompleted);<\/p>\n<p>loginSvc.IsAuthenticatedAsync(txtUID.Text, txtPwd.Password);<\/p>\n<p>}<\/p>\n<p>void loginSvc_IsAuthenticatedCompleted(object sender, IsAuthenticatedCompletedEventArgs e)<\/p>\n<p>{<\/p>\n<p>if (e.Result == &#8220;Authorized&#8221;)<\/p>\n<p>{<\/p>\n<p>WebClient wb = new WebClient();<\/p>\n<p>wb.OpenReadAsync(<\/p>\n<p>new Uri(&#8220;B.xap&#8221;,UriKind.Relative));<\/p>\n<p>wb.OpenReadCompleted +=<\/p>\n<p>new OpenReadCompletedEventHandler(wb_OpenReadCompleted);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>void wb_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)<\/p>\n<p>{<\/p>\n<p>StreamResourceInfo sri = new StreamResourceInfo(e.Result, null); StreamResourceInfo mainAppSRI = Application.GetResourceStream(sri, new Uri(&#8220;B.dll&#8221;, UriKind.Relative));AssemblyPart loader = new AssemblyPart(); Assembly assembly = loader.Load(mainAppSRI.Stream);this.LayoutRoot.Children.Clear(); <strong><em>this.Content = assembly.CreateInstance(&#8220;B.Page&#8221;) as System.Windows.UIElement;<\/em><\/strong><\/p>\n<p>}<\/p>\n<p>The exception detais &#8211; Stack trace<\/p>\n<p>System.Reflection.TargetInvocationException was unhandled by user code \u00a0 Message=&#8221;Exception has been thrown by the target of an invocation.&#8221; \u00a0 StackTrace: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandle&amp; ctor, Boolean&amp; bNeedSecurityCheck) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.Activator.CreateInstance(Type type, Boolean nonPublic) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.Reflection.Assembly.CreateInstance(String typeName) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at LoginApp.Page.wb_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at System.Net.WebClient.OpenReadOperationCompleted(Object arg) \u00a0 InnerException: System.IO.FileNotFoundException \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Message=&#8221;Could not load file or assembly &#8216;CairngormFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#8217; or one of its dependencies. The system cannot find the file specified.&#8221; \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 StackTrace: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 at VideoLibrary.Page..ctor() \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 InnerException:<\/p>\n<p>Please throw some light into this matter and help me.<\/p>\n<p>Thanks,<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn1<\/p>\n<p>Hi,<\/p>\n<p>I figured out the problem. There was two dependencies for my project. I had to load them\u00a0 manually before creating the instance of the main page. That was the problem.<\/p>\n<p>Thanks,<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn2<\/p>\n<p>Hi,<\/p>\n<p>Thank u for the reply. I tried that as well with the following code&#8230;<\/p>\n<p>string appManifest = new StreamReader(Application.GetResourceStream(new StreamResourceInfo(e.Result, null), new Uri(&#8220;AppManifest.xaml&#8221;, UriKind.Relative)).Stream).ReadToEnd();XElement deploymentRoot = XDocument.Parse(appManifest).Root; List deploymentParts = (from assemblyParts in deploymentRoot.Elements().Elements()select assemblyParts).ToList();UIElement dashShell = null; foreach (XElement xElement in deploymentParts)<\/p>\n<p>{<\/p>\n<p>string source = xElement.Attribute(&#8220;Source&#8221;).Value;StreamResourceInfo streamInfo = Application.GetResourceStream(new StreamResourceInfo(e.Result, &#8220;application\/binary&#8221;), new Uri(source, UriKind.Relative));AssemblyPart asmPart = new AssemblyPart();if (source == &#8220;VideoLibrary.dll&#8221;)<\/p>\n<p>{<\/p>\n<p>Assembly asm = asmPart.Load(streamInfo.Stream);<\/p>\n<p><strong><em>dashShell = asm.CreateInstance(<\/em><\/strong><\/p>\n<p><strong><em>&#8220;VideoLibrary.Page&#8221;) as UIElement<\/em><\/strong><strong><em>;<\/em><\/strong><\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>{<\/p>\n<p>asmPart.Load(streamInfo.Stream);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>this.LayoutRoot.Children.Clear(); this.LayoutRoot.Children.Add(dashShell);<\/p>\n<p>But the line which is marked\u00a0in bold and italics creates the same problem.<\/p>\n<p>If anybody could provide a light into this&#8230;<\/p>\n<p>Thanks<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn3<\/p>\n<p>Hi,<\/p>\n<p>I figured out the problem. There was two dependencies for my project. I had to load them\u00a0 manually before creating the instance of the main page. That was the problem.<\/p>\n<p>Thanks,<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>msdn Hi all, I am developing an application with multiple XAP files. I have two XAP filesc &#8211; A.xap and B.xap. I am loading A.xap first and want to load B.xap dynamically. But it results in an exception &#8211; &#8220;Exception has been thrown by the target of an invocation.&#8221; at the line marked as bold [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3048","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3048","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3048"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3048\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}