{"id":5480,"date":"2014-03-30T22:39:16","date_gmt":"2014-03-30T22:39:16","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-include-another-assembly-in-a-windows-phone-8-xap-collection-of-common-programming-errors\/"},"modified":"2014-03-30T22:39:16","modified_gmt":"2014-03-30T22:39:16","slug":"how-to-include-another-assembly-in-a-windows-phone-8-xap-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-include-another-assembly-in-a-windows-phone-8-xap-collection-of-common-programming-errors\/","title":{"rendered":"How to include another assembly in a Windows Phone 8 XAP-Collection of common programming errors"},"content":{"rendered":"<p>You can add a compiled assembly (.dll file) to your WP8 project and set the file Build Action to &#8216;Content&#8217;. Then you can try to load it as so :<\/p>\n<pre><code>var folder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, \"Plugins\", \"Services\"));\nvar files = await folder.GetFilesAsync();\nvar firstFile = files.FirstOrDefault();\nvar assy = Assembly.LoadFrom(firstFile.Path);\n<\/code><\/pre>\n<p>But Assembly.LoadFrom will fail since it&#8217;s unsupported. You can still use this to load other binary content but not code.<\/p>\n<p>All you can do is reference all &#8216;plugins&#8217; or whatever assemblies you might need and <strong>not<\/strong> directly reference any type from these assemblies. By &#8216;reference the assemblies&#8217; I mean right click on references (in the WP8 project) and &#8220;Add reference&#8230;&#8221;.<\/p>\n<p>You can then do this :<\/p>\n<pre><code>var assy = Assembly.Load(\"MyCompany.MyProject.WhateverAssembly\");\nvar tp = typeof(IService);\nvar x = ass.GetTypes().Where(t =&gt; t.IsClass &amp;&amp; tp.IsAssignableFrom(t)).SingleOrDefault();\nActivator.CreateInstance(x);\n<\/code><\/pre>\n<p>Not very elegant but I could call it a workaround.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can add a compiled assembly (.dll file) to your WP8 project and set the file Build Action to &#8216;Content&#8217;. Then you can try to load it as so : var folder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, &#8220;Plugins&#8221;, &#8220;Services&#8221;)); var files = await folder.GetFilesAsync(); var firstFile = files.FirstOrDefault(); var assy = Assembly.LoadFrom(firstFile.Path); But Assembly.LoadFrom will fail since [&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-5480","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5480","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=5480"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5480\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}